Beispiel #1
0
        public void ShouldCache()
        {
            var component = factory.Create <IObjectOfGenericType <string> >();

            component.CachedMethod(1, "1")
            .Should().Be.EqualTo(component.CachedMethod(1, "1"));
        }
Beispiel #2
0
        public void ShouldNotShareCache()
        {
            var one = factory.Create <IObjectReturningNewGuids>();
            var two = factory.Create <IObjectWithCtorParameters>(1, 2);

            one.CachedMethod().Should().Not.Be.EqualTo(two.CachedMethod());
        }
        public void ShouldCache()
        {
            var component = factory.Create <ObjectWithGenericMethodParameters>();

            component.CachedMethod1(1, "1")
            .Should().Be.EqualTo(component.CachedMethod1(1, "1"));
        }
Beispiel #4
0
        public void ShouldCacheMethod()
        {
            var obj1 = factory.Create <ObjectReturningNewGuidsNoInterface>();
            var obj2 = factory.Create <ObjectReturningNewGuidsNoInterface>();

            obj1.CachedMethod().Should().Be.EqualTo(obj2.CachedMethod());
        }
Beispiel #5
0
        public void VerifyCacheIsWorking()
        {
            var obj1 = factory.Create <IReturningRandomNumbers>();
            var obj2 = factory.Create <IReturningRandomNumbers>();

            obj1.CachedNumber().Should().Be.EqualTo(obj2.CachedNumber());
            obj1.CachedNumber2().Should().Be.EqualTo(obj2.CachedNumber2());
        }
Beispiel #6
0
        public void ShouldCacheNullParameterAndReturnValue()
        {
            var component = factory.Create <IObjectReturningNull>();

            component.ReturnNullIfZero(0).Should().Be.Null();
            component.ReturnNullIfZero(0).Should().Be.Null();
            eventListener.CacheHits.Should().Be.EqualTo(1);
        }
        public void DifferentObjectsHasTheirOwnCache()
        {
            var obj  = factory.Create <IObjectReturningNewGuids>();
            var obj2 = factory.Create <IObjectReturningNewGuids>();

            Assert.AreEqual(obj.CachedMethod(), obj.CachedMethod());
            Assert.AreNotEqual(obj.CachedMethod(), obj2.CachedMethod());
        }
        public void VerifyCacheIsWorking()
        {
            var obj1 = factory.Create <IReturningRandomNumbers>();
            var obj2 = factory.Create <IReturningRandomNumbers>();

            Assert.AreEqual(obj1.CachedNumber(), obj2.CachedNumber());
            Assert.AreEqual(obj1.CachedNumber2(), obj2.CachedNumber2());
            Assert.AreNotEqual(obj1.CachedNumber(), obj1.CachedNumber2());
            Assert.AreNotEqual(obj1.NonCachedNumber(), obj2.NonCachedNumber());
        }
Beispiel #9
0
        public void ShouldHaveDifferentCachesPerScope()
        {
            var instance = factory.Create <IReturningRandomNumbers>();

            CacheKeyWithScope.CurrentScope = "1";
            var valueForScope1 = instance.CachedNumber();

            CacheKeyWithScope.CurrentScope = "2";
            instance.CachedNumber()
            .Should().Not.Be.EqualTo(valueForScope1);
        }
Beispiel #10
0
        public void VerifyCacheHits()
        {
            var comp = factory.Create <IObjectReturningNewGuids>();

            comp.CachedMethod();
            Assert.AreEqual(0, eventListener.CacheHits);
            comp.CachedMethod();
            Assert.AreEqual(1, eventListener.CacheHits);
            comp.CachedMethod2();
            Assert.AreEqual(1, eventListener.CacheHits);
        }
Beispiel #11
0
        public void ShouldTurnOffCachingOfMethodAndEvictCache()
        {
            var comp   = factory.Create <IObjectReturningNewGuids>();
            var orgRes = comp.CachedMethod();

            factory.DisableCache <IObjectReturningNewGuids>();
            var newRes = comp.CachedMethod();

            comp.CachedMethod().Should().Not.Be.EqualTo(newRes);
            factory.EnableCache <IObjectReturningNewGuids>();
            comp.CachedMethod().Should().Not.Be.EqualTo(orgRes);
        }
        public void InvalidateSpecificMethodWithSpecificParameter()
        {
            var objWithParam  = factory.Create <IObjectWithParametersOnCachedMethod>();
            var objWithParam2 = factory.Create <IObjectWithParametersOnCachedMethod>();
            var value1        = objWithParam.CachedMethod("roger");
            var value2        = objWithParam2.CachedMethod("roger");

            factory.Invalidate(objWithParam, method => method.CachedMethod("roger"), true);

            value1.Should().Not.Be.EqualTo(objWithParam.CachedMethod("roger"));
            value2.Should().Be.EqualTo(objWithParam2.CachedMethod("roger"));
        }
        public void InvalidateAll()
        {
            var instance = factory.Create <ObjectWithMultipleParameters>();

            CacheKeyWithScope.CurrentScope = "FirstScope";
            var result = instance.Calculate(0, "", 0);

            CacheKeyWithScope.CurrentScope = "SecondScope";
            factory.Invalidate();
            CacheKeyWithScope.CurrentScope = "FirstScope";
            instance.Calculate(0, "", 0)
            .Should().Not.Be.EqualTo(result);
        }
Beispiel #14
0
        public void VerifyInvalidateByType()
        {
            var obj    = factory.Create <IObjectReturningNewGuids>();
            var value1 = obj.CachedMethod();
            var value2 = obj.CachedMethod2();

            Assert.AreEqual(value1, obj.CachedMethod());
            Assert.AreEqual(value2, obj.CachedMethod2());
            Assert.AreNotEqual(value1, value2);
            factory.Invalidate <IObjectReturningNewGuids>();
            Assert.AreNotEqual(value1, obj.CachedMethod());
            Assert.AreNotEqual(value2, obj.CachedMethod2());
        }
        public void ShouldHaveDifferentCachesPerScope()
        {
            var instance = factory.Create <IReturningRandomNumbers>();

            instance.CachedNumber()
            .Should().Be.EqualTo(instance.CachedNumber());
        }
Beispiel #16
0
        public void ShouldGiveLogWarningIfSuspectedParameterIsUsed()
        {
            var comp = factory.Create <IObjectWithParametersOnCachedMethod>();

            comp.CachedMethod(this);

            eventListener.Warnings.Single().Should().Contain(GetType().ToString());
        }
        protected override void TestSetup()
        {
            CacheBuilder
            .For <ObjectReturningNewGuids>()
            .CacheMethod(c => c.CachedMethod())
            .CacheMethod(c => c.CachedMethod2())
            .PerInstance()
            .As <IObjectReturningNewGuids>();

            CacheBuilder
            .For <ObjectWithParametersOnCachedMethod>()
            .CacheMethod(c => c.CachedMethod(null))
            .PerInstance()
            .As <IObjectWithParametersOnCachedMethod>();

            factory = CacheBuilder.BuildFactory();
            obj1    = factory.Create <IObjectReturningNewGuids>();
            obj2    = factory.Create <IObjectReturningNewGuids>();
        }
        protected override void TestSetup()
        {
            CacheBuilder
            .For <ObjectWithMutableList>()
            .CacheMethod(c => c.GetListContents())
            .AsImplemented();

            factory  = CacheBuilder.BuildFactory();
            instance = factory.Create <ObjectWithMutableList>();
        }
		protected override void TestSetup()
		{
			CacheBuilder
				.For<ObjectWithMutableList>()
				.CacheMethod(c => c.GetListContents())
				.AsImplemented();

			factory = CacheBuilder.BuildFactory();
			instance = factory.Create<ObjectWithMutableList>();
		}
		protected override void TestSetup()
		{
			CacheBuilder
				.For<ObjectReturningNewGuids>()
				.CacheMethod(c => c.CachedMethod())
				.CacheMethod(c => c.CachedMethod2())
				.PerInstance()
				.As<IObjectReturningNewGuids>();

			CacheBuilder
				.For<ObjectWithParametersOnCachedMethod>()
				.CacheMethod(c => c.CachedMethod(null))
				.PerInstance()
				.As<IObjectWithParametersOnCachedMethod>();

			factory = CacheBuilder.BuildFactory();
			obj1 = factory.Create<IObjectReturningNewGuids>();
			obj2 = factory.Create<IObjectReturningNewGuids>();
		}
Beispiel #21
0
		protected override void TestSetup()
		{
			eventListener = new StatisticsEventListener();
			CacheBuilder
				.AddEventListener(eventListener)
				.For<ObjectWithParametersOnCachedMethod>()
					.CacheMethod(c => c.CachedMethod(null))
					.As<IObjectWithParametersOnCachedMethod>();

			factory = CacheBuilder.BuildFactory();
			component = factory.Create<IObjectWithParametersOnCachedMethod>();
		}
Beispiel #22
0
        protected override void TestSetup()
        {
            eventListener = new StatisticsEventListener();
            CacheBuilder
            .AddEventListener(eventListener)
            .For <ObjectWithParametersOnCachedMethod>()
            .CacheMethod(c => c.CachedMethod(null))
            .As <IObjectWithParametersOnCachedMethod>();

            factory   = CacheBuilder.BuildFactory();
            component = factory.Create <IObjectWithParametersOnCachedMethod>();
        }
Beispiel #23
0
        public void CanReadProps()
        {
            var obj = factory.Create <IObjectWithCtorParameters>(11, 12);

            Assert.AreEqual(11, obj.Value1);
            Assert.AreEqual(12, obj.Value2);
        }
Beispiel #24
0
        public void ShouldGiveLogWarningIfSuspectedParameterIsUsed()
        {
            var logger = LogManager.GetLogger(typeof(CacheKeyBase));

            if (!logger.IsWarnEnabled)
            {
                Assert.Ignore("log4net logging is not enabled - cannot verify test");
            }
            var comp = factory.Create <IObjectWithParametersOnCachedMethod>();

            using (var log = new LogSpy(logger, Level.Warn))
            {
                comp.CachedMethod(this);
                var logOutput = log.RenderedMessages();
                logOutput.Should().Contain(GetType().ToString());
            }
        }
Beispiel #25
0
        public void ShouldThrowOriginalException()
        {
            var comp = factory.Create <ObjectThrowingError>();

            Assert.Throws <ArgumentOutOfRangeException>(() => comp.ThrowsArgumentOutOfRangeException());
        }
Beispiel #26
0
 public void CanAskFactoryIfComponentIsKnownType()
 {
     Assert.IsTrue(factory.IsKnownInstance(factory.Create <IObjectReturningNewGuids>()));
     Assert.IsFalse(factory.IsKnownInstance(new object()));
 }
 public void VerifySameParameterGivesCacheHit()
 {
     Assert.AreEqual(factory.Create <IObjectWithParametersOnCachedMethod>().CachedMethod("hej"),
                     factory.Create <IObjectWithParametersOnCachedMethod>().CachedMethod("hej"));
 }
Beispiel #28
0
        public void ShouldNotCacheNonConfiguredType()
        {
            var one = factory.Create <IObjectReturningNewGuids>();

            one.CachedMethod().Should().Not.Be.EqualTo(one.CachedMethod());
        }