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

            component.CachedMethod(1, "1")
            .Should().Be.EqualTo(component.CachedMethod(1, "1"));
        }
Exemple #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"));
        }
Exemple #4
0
        public void ShouldCacheMethod()
        {
            var obj1 = factory.Create <ObjectReturningNewGuidsNoInterface>();
            var obj2 = factory.Create <ObjectReturningNewGuidsNoInterface>();

            obj1.CachedMethod().Should().Be.EqualTo(obj2.CachedMethod());
        }
Exemple #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());
        }
Exemple #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());
        }
        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);
        }
Exemple #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);
        }
Exemple #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);
        }
        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());
        }
Exemple #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>();
		}
Exemple #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>();
		}
Exemple #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>();
        }
Exemple #23
0
        public void CanReadProps()
        {
            var obj = factory.Create <IObjectWithCtorParameters>(11, 12);

            Assert.AreEqual(11, obj.Value1);
            Assert.AreEqual(12, obj.Value2);
        }
Exemple #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());
            }
        }
Exemple #25
0
        public void ShouldThrowOriginalException()
        {
            var comp = factory.Create <ObjectThrowingError>();

            Assert.Throws <ArgumentOutOfRangeException>(() => comp.ThrowsArgumentOutOfRangeException());
        }
Exemple #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"));
 }
Exemple #28
0
        public void ShouldNotCacheNonConfiguredType()
        {
            var one = factory.Create <IObjectReturningNewGuids>();

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