Exemplo n.º 1
0
        public void ShouldThrowWhenCreatingNotKnownComponent()
        {
            var builder = new CacheBuilder(new ProxyImplThatThrowsNotSupportedEx());
            var factory = builder.BuildFactory();

            Assert.Throws <ArgumentException>(() => factory.Create <object>());
        }
Exemplo n.º 2
0
 protected override void TestSetup()
 {
     CacheBuilder.For <ObjectWithMultipleParameters>()
     .CacheMethod(x => x.Calculate(0, "", 0))
     .AsImplemented();
     component = CacheBuilder.BuildFactory().Create <ObjectWithMultipleParameters>();
 }
Exemplo n.º 3
0
 protected override void TestSetup()
 {
     CacheBuilder.For <ObjectWithParameterReturningFixedValue>("Foo")
     .CacheMethod(x => x.DoIt(0))
     .AsImplemented();
     component = CacheBuilder.BuildFactory().Create <ObjectWithParameterReturningFixedValue>();
 }
Exemplo n.º 4
0
        protected override void TestSetup()
        {
            firstEventListener  = new eventListenerForMultiple();
            secondEventListener = new eventListenerForMultiple();
            thirdEventListener  = new eventListenerForMultiple();
            eventListenerForMultiple.FirstCallOnDelete          = true;
            eventListenerForMultiple.FirstCallOnGetSuccessful   = true;
            eventListenerForMultiple.FirstCallOnPut             = true;
            eventListenerForMultiple.FirstCallOnGetUnsuccessful = true;

            CacheBuilder
            .For <ReturningRandomNumbers>()
            .CacheMethod(c => c.CachedNumber())
            .As <IReturningRandomNumbers>()
            .AddEventListener(firstEventListener)
            .AddEventListener(secondEventListener)
            .AddEventListener(thirdEventListener);

            var factory = CacheBuilder.BuildFactory();
            var comp    = factory.Create <IReturningRandomNumbers>();

            comp.CachedNumber();
            comp.CachedNumber();
            ((ICachingComponent)comp).Invalidate();
        }
Exemplo n.º 5
0
        public void ShouldHandleRecursiveCalls()
        {
            CacheBuilder.For <ObjectRecursive1>()
            .CacheMethod(c => c.Ref(1))
            .AsImplemented();
            CacheBuilder.For <ObjectRecursive2>()
            .CacheMethod(c => c.Foo(1))
            .AsImplemented();

            var factory   = CacheBuilder.BuildFactory();
            var instance2 = factory.Create <ObjectRecursive2>();
            var instance1 = factory.Create <ObjectRecursive1>(instance2);

            var tasks = new List <Task>();

            500.Times(x =>
            {
                tasks.Add(Task.Factory.StartNew(() =>
                {
                    instance1.Ref(x);
                }));
            });

            Task.WaitAll(tasks.ToArray());
        }
Exemplo n.º 6
0
        public void ShouldNotMakeTheSameCallMoreThanOnce()
        {
            CacheBuilder.For <ObjectWithCallCounter>()
            .CacheMethod(c => c.Increment())
            .PerInstance()
            .As <IObjectWithCallCounter>();

            var factory = CacheBuilder.BuildFactory();

            10.Times(() =>
            {
                var instance = factory.Create <IObjectWithCallCounter>();

                var task1 = new Thread(() => instance.Increment());
                var task2 = new Thread(() => instance.Increment());
                var task3 = new Thread(() => instance.Increment());
                task1.Start();
                task2.Start();
                task3.Start();
                task1.Join();
                task2.Join();
                task3.Join();

                instance.Count.Should().Be(1);
            });
        }
Exemplo n.º 7
0
 public void ReturnTypeMustBeDeclared()
 {
     CacheBuilder
     .For <ObjectReturningNewGuids>()
     .CacheMethod(c => c.CachedMethod());
     Assert.Throws <InvalidOperationException>(() => CacheBuilder.BuildFactory());
 }
Exemplo n.º 8
0
 protected override void TestSetup()
 {
     memoryCacheReference = MemoryCache.Default;
     CacheBuilder.For <ObjectWithMultipleParameters>()
     .CacheMethod(x => x.Calculate(0, null, 0))
     .AsImplemented();
     component = CacheBuilder.BuildFactory().Create <ObjectWithMultipleParameters>();
 }
Exemplo n.º 9
0
 protected override void TestSetup()
 {
     CacheBuilder.For <SomeEntity>()
     .CacheMethod(c => c.Run(0, 0))
     .CacheMethod(c => c.Run(null, null))
     .AsImplemented();
     factory = CacheBuilder.BuildFactory();
 }
Exemplo n.º 10
0
 protected override void TestSetup()
 {
     CacheBuilder.For <ObjectWithOverloadedMethod>()
     .CacheMethod(m => m.Something(2))
     .CacheMethod(m => m.Something("d"))
     .AsImplemented();
     component = CacheBuilder.BuildFactory().Create <ObjectWithOverloadedMethod>();
 }
Exemplo n.º 11
0
        public void ShouldThrowArgumentException()
        {
            var builder = new CacheBuilder(new NullProxyFactory());
            var factory = builder.BuildFactory();

            Assert.Throws <ArgumentException>(() =>
                                              factory.Create <object>());
        }
Exemplo n.º 12
0
        protected override void TestSetup()
        {
            CacheBuilder.For <ReturningRandomNumbers>()
            .CacheMethod(c => c.CachedNumber())
            .CacheMethod(c => c.CachedNumber2())
            .As <IReturningRandomNumbers>();

            factory = CacheBuilder.BuildFactory();
        }
Exemplo n.º 13
0
        protected override void TestSetup()
        {
            CacheBuilder
            .For <ObjectThrowingError>()
            .CacheMethod(c => c.ThrowsArgumentOutOfRangeException())
            .AsImplemented();

            factory = CacheBuilder.BuildFactory();
        }
Exemplo n.º 14
0
        protected override void TestSetup()
        {
            CacheBuilder.For <ObjectWithMultipleParameters>()
            .CacheMethod(c => c.Calculate(0, "", 0))
            .PerInstance()
            .AsImplemented();

            factory = CacheBuilder.BuildFactory();
        }
Exemplo n.º 15
0
        protected override void TestSetup()
        {
            CacheBuilder.For <ObjectReturningNewGuidsNoInterface>()
            .CacheMethod(c => c.CachedMethod())
            .CacheMethod(c => c.CachedMethod2())
            .AsImplemented();

            factory = CacheBuilder.BuildFactory();
        }
Exemplo n.º 16
0
        protected override void TestSetup()
        {
            CacheBuilder
            .For <ObjectReturningNewGuids>()
            .CacheMethod(c => c.CachedMethod())
            .As <IObjectReturningNewGuids>();

            factory = CacheBuilder.BuildFactory();
        }
Exemplo n.º 17
0
 protected override void TestSetup()
 {
     CacheBuilder.For <ObjectWithCtorParameters>()
     .CacheMethod(m => m.CachedMethod())
     .As <IObjectWithCtorParameters>();
     CacheBuilder.For <ObjectReturningNewGuids>()
     .As <IObjectReturningNewGuids>();
     factory = CacheBuilder.BuildFactory();
 }
Exemplo n.º 18
0
        protected override void TestSetup()
        {
            CacheBuilder
            .For <ObjectWithCtorParameters>()
            .CacheMethod(c => c.CachedMethod())
            .As <IObjectWithCtorParameters>();

            factory = CacheBuilder.BuildFactory();
        }
Exemplo n.º 19
0
        protected override void TestSetup()
        {
            CacheBuilder.For <ReturningRandomNumbers>()
            .CacheMethod(c => c.CachedNumber())
            .As <IReturningRandomNumbers>();

            var factory = CacheBuilder.BuildFactory();

            instance = factory.Create <IReturningRandomNumbers>();
        }
Exemplo n.º 20
0
 protected override void TestSetup()
 {
     eventListener = new StatisticsEventListener();
     CacheBuilder
     .AddEventListener(eventListener)
     .For <ObjectReturningNull>()
     .CacheMethod(c => c.ReturnNullIfZero(0))
     .As <IObjectReturningNull>();
     factory = CacheBuilder.BuildFactory();
 }
        protected override void TestSetup()
        {
            CacheBuilder
            .For <ObjectWithMutableList>()
            .CacheMethod(c => c.GetListContents())
            .AsImplemented();

            factory  = CacheBuilder.BuildFactory();
            instance = factory.Create <ObjectWithMutableList>();
        }
Exemplo n.º 22
0
        protected override void TestSetup()
        {
            CacheBuilder.For <ObjectTakes100MsToFill>()
            .CacheMethod(c => c.Execute(0))
            .AsImplemented();

            var factory = CacheBuilder.BuildFactory();

            instance = factory.Create <ObjectTakes100MsToFill>();
        }
        public void InvalidateAllByDispose()
        {
            var obj   = factory.Create <IObjectReturningNewGuids>();
            var value = obj.CachedMethod();

            factory.Dispose();
            var newFactory = CacheBuilder.BuildFactory();

            newFactory.Create <IObjectReturningNewGuids>().CachedMethod()
            .Should().Not.Be.EqualTo(value);
        }
Exemplo n.º 24
0
        public void ShouldReturnCorrectTypeForInterface()
        {
            CacheBuilder
            .For <ObjectReturningNewGuids>()
            .CacheMethod(c => c.CachedMethod())
            .As <IObjectReturningNewGuids>();
            var factory = CacheBuilder.BuildFactory();

            factory.ImplementationTypeFor(typeof(IObjectReturningNewGuids))
            .Should().Be.EqualTo(typeof(ObjectReturningNewGuids));
        }
Exemplo n.º 25
0
        protected override void TestSetup()
        {
            eventListener = new StatisticsEventListener();
            CacheBuilder
            .For <ObjectReturningNewGuids>()
            .CacheMethod(c => c.CachedMethod())
            .As <IObjectReturningNewGuids>()
            .AddEventListener(eventListener);

            factory = CacheBuilder.BuildFactory();
        }
Exemplo n.º 26
0
        protected override void TestSetup()
        {
            CacheBuilder.For <ReturningRandomNumbers>()
            .CacheMethod(c => c.CachedNumber())
            .CacheMethod(c => c.CachedNumber2())
            .As <IReturningRandomNumbers>();

            var factoryTemp = CacheBuilder.BuildFactory();

            factory = serializeAndDeserialize(factoryTemp);
        }
Exemplo n.º 27
0
        public void ShouldReturnCorrectTypeForClass()
        {
            CacheBuilder
            .For <ObjectWithNonInterfaceMethod>()
            .CacheMethod(c => c.ReturnsFour())
            .AsImplemented();
            var factory = CacheBuilder.BuildFactory();

            factory.ImplementationTypeFor(typeof(ObjectWithNonInterfaceMethod))
            .Should().Be.EqualTo(typeof(ObjectWithNonInterfaceMethod));
        }
Exemplo n.º 28
0
        public void CreatingProxiesOfSameDeclaredTypeShouldReturnIdenticalTypes()
        {
            CacheBuilder
            .For <ObjectReturningNewGuids>()
            .CacheMethod(c => c.CachedMethod())
            .As <IObjectReturningNewGuids>();

            var factory = CacheBuilder.BuildFactory();

            Assert.AreEqual(factory.Create <IObjectReturningNewGuids>().GetType(), factory.Create <IObjectReturningNewGuids>().GetType());
        }
Exemplo n.º 29
0
        protected override void TestSetup()
        {
            eventListener = new EventListenerForTest();
            CacheBuilder.AddEventListener(eventListener);

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

            factory = CacheBuilder.BuildFactory();
        }
Exemplo n.º 30
0
        public void FactoryReturnsNewInterfaceInstances()
        {
            CacheBuilder
            .For <ObjectWithIdentifier>()
            .As <IObjectWithIdentifier>();
            var factory = CacheBuilder.BuildFactory();
            var obj1    = factory.Create <IObjectWithIdentifier>();
            var obj2    = factory.Create <IObjectWithIdentifier>();

            Assert.AreNotSame(obj1, obj2);
            Assert.AreNotEqual(obj1.Id, obj2.Id);
        }
Exemplo n.º 31
0
		public void ShouldThrowWhenCreatingNotKnownComponent()
		{
			var builder = new CacheBuilder(new ProxyImplThatThrowsNotSupportedEx());
			var factory = builder.BuildFactory();
			Assert.Throws<ArgumentException>(() => factory.Create<object>());
		}