public void ShouldThrowWhenCreatingNotKnownComponent() { var builder = new CacheBuilder(new ProxyImplThatThrowsNotSupportedEx()); var factory = builder.BuildFactory(); Assert.Throws <ArgumentException>(() => factory.Create <object>()); }
protected override void TestSetup() { CacheBuilder.For <ObjectWithMultipleParameters>() .CacheMethod(x => x.Calculate(0, "", 0)) .AsImplemented(); component = CacheBuilder.BuildFactory().Create <ObjectWithMultipleParameters>(); }
protected override void TestSetup() { CacheBuilder.For <ObjectWithParameterReturningFixedValue>("Foo") .CacheMethod(x => x.DoIt(0)) .AsImplemented(); component = CacheBuilder.BuildFactory().Create <ObjectWithParameterReturningFixedValue>(); }
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(); }
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()); }
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); }); }
public void ReturnTypeMustBeDeclared() { CacheBuilder .For <ObjectReturningNewGuids>() .CacheMethod(c => c.CachedMethod()); Assert.Throws <InvalidOperationException>(() => CacheBuilder.BuildFactory()); }
protected override void TestSetup() { memoryCacheReference = MemoryCache.Default; CacheBuilder.For <ObjectWithMultipleParameters>() .CacheMethod(x => x.Calculate(0, null, 0)) .AsImplemented(); component = CacheBuilder.BuildFactory().Create <ObjectWithMultipleParameters>(); }
protected override void TestSetup() { CacheBuilder.For <SomeEntity>() .CacheMethod(c => c.Run(0, 0)) .CacheMethod(c => c.Run(null, null)) .AsImplemented(); factory = CacheBuilder.BuildFactory(); }
protected override void TestSetup() { CacheBuilder.For <ObjectWithOverloadedMethod>() .CacheMethod(m => m.Something(2)) .CacheMethod(m => m.Something("d")) .AsImplemented(); component = CacheBuilder.BuildFactory().Create <ObjectWithOverloadedMethod>(); }
public void ShouldThrowArgumentException() { var builder = new CacheBuilder(new NullProxyFactory()); var factory = builder.BuildFactory(); Assert.Throws <ArgumentException>(() => factory.Create <object>()); }
protected override void TestSetup() { CacheBuilder.For <ReturningRandomNumbers>() .CacheMethod(c => c.CachedNumber()) .CacheMethod(c => c.CachedNumber2()) .As <IReturningRandomNumbers>(); factory = CacheBuilder.BuildFactory(); }
protected override void TestSetup() { CacheBuilder .For <ObjectThrowingError>() .CacheMethod(c => c.ThrowsArgumentOutOfRangeException()) .AsImplemented(); factory = CacheBuilder.BuildFactory(); }
protected override void TestSetup() { CacheBuilder.For <ObjectWithMultipleParameters>() .CacheMethod(c => c.Calculate(0, "", 0)) .PerInstance() .AsImplemented(); factory = CacheBuilder.BuildFactory(); }
protected override void TestSetup() { CacheBuilder.For <ObjectReturningNewGuidsNoInterface>() .CacheMethod(c => c.CachedMethod()) .CacheMethod(c => c.CachedMethod2()) .AsImplemented(); factory = CacheBuilder.BuildFactory(); }
protected override void TestSetup() { CacheBuilder .For <ObjectReturningNewGuids>() .CacheMethod(c => c.CachedMethod()) .As <IObjectReturningNewGuids>(); factory = CacheBuilder.BuildFactory(); }
protected override void TestSetup() { CacheBuilder.For <ObjectWithCtorParameters>() .CacheMethod(m => m.CachedMethod()) .As <IObjectWithCtorParameters>(); CacheBuilder.For <ObjectReturningNewGuids>() .As <IObjectReturningNewGuids>(); factory = CacheBuilder.BuildFactory(); }
protected override void TestSetup() { CacheBuilder .For <ObjectWithCtorParameters>() .CacheMethod(c => c.CachedMethod()) .As <IObjectWithCtorParameters>(); factory = CacheBuilder.BuildFactory(); }
protected override void TestSetup() { CacheBuilder.For <ReturningRandomNumbers>() .CacheMethod(c => c.CachedNumber()) .As <IReturningRandomNumbers>(); var factory = CacheBuilder.BuildFactory(); instance = factory.Create <IReturningRandomNumbers>(); }
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>(); }
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); }
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)); }
protected override void TestSetup() { eventListener = new StatisticsEventListener(); CacheBuilder .For <ObjectReturningNewGuids>() .CacheMethod(c => c.CachedMethod()) .As <IObjectReturningNewGuids>() .AddEventListener(eventListener); factory = CacheBuilder.BuildFactory(); }
protected override void TestSetup() { CacheBuilder.For <ReturningRandomNumbers>() .CacheMethod(c => c.CachedNumber()) .CacheMethod(c => c.CachedNumber2()) .As <IReturningRandomNumbers>(); var factoryTemp = CacheBuilder.BuildFactory(); factory = serializeAndDeserialize(factoryTemp); }
public void ShouldReturnCorrectTypeForClass() { CacheBuilder .For <ObjectWithNonInterfaceMethod>() .CacheMethod(c => c.ReturnsFour()) .AsImplemented(); var factory = CacheBuilder.BuildFactory(); factory.ImplementationTypeFor(typeof(ObjectWithNonInterfaceMethod)) .Should().Be.EqualTo(typeof(ObjectWithNonInterfaceMethod)); }
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()); }
protected override void TestSetup() { eventListener = new EventListenerForTest(); CacheBuilder.AddEventListener(eventListener); CacheBuilder .For <ObjectWithParametersOnCachedMethod>() .CacheMethod(c => c.CachedMethod(null)) .As <IObjectWithParametersOnCachedMethod>(); factory = CacheBuilder.BuildFactory(); }
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); }
public void ShouldThrowWhenCreatingNotKnownComponent() { var builder = new CacheBuilder(new ProxyImplThatThrowsNotSupportedEx()); var factory = builder.BuildFactory(); Assert.Throws<ArgumentException>(() => factory.Create<object>()); }