public void ShouldNotFailOnDoubleDisposeTest() { Mockery mockery; MockProxyFactory factory; IMockObject objectContract; MockProxyFactory.IInvokeDynamicFactory mockInvokeDynamicFactory; IDynamicInvocation mockDynamicInvocation; MethodInfo invokedMethodInfo; mockery = new Mockery(); mockDynamicInvocation = mockery.NewMock <IDynamicInvocation>(); mockInvokeDynamicFactory = mockery.NewMock <MockProxyFactory.IInvokeDynamicFactory>(); invokedMethodInfo = (MethodInfo)MemberInfoProxy <IDisposable> .GetLastMemberInfo(exec => exec.Dispose()); Expect.Once.On(mockInvokeDynamicFactory).Method("GetDynamicInvoker").With("myCacheKey", typeof(IMockObject)).Will(Return.Value(mockDynamicInvocation)); factory = new MockProxyFactory(); Assert.IsNotNull(factory); objectContract = factory.CreateInstance("myCacheKey", mockInvokeDynamicFactory); Assert.IsNotNull(objectContract); factory.Dispose(); factory.Dispose(); mockery.VerifyAllExpectationsHaveBeenMet(); }
public void ShouldCreateInstanceWithCacheKeyAndInvokeDynamicFactoryTest() { Mockery mockery; MockProxyFactory factory; IMockObject objectContract; MockProxyFactory.IInvokeDynamicFactory mockInvokeDynamicFactory; IDynamicInvocation mockDynamicInvocation; MethodInfo invokedMethodInfo; mockery = new Mockery(); mockDynamicInvocation = mockery.NewMock<IDynamicInvocation>(); mockInvokeDynamicFactory = mockery.NewMock<MockProxyFactory.IInvokeDynamicFactory>(); invokedMethodInfo = (MethodInfo)MemberInfoProxy<IDisposable>.GetLastMemberInfo(exec => exec.Dispose()); Expect.Once.On(mockInvokeDynamicFactory).Method("GetDynamicInvoker").With("myCacheKey", typeof(IMockObject)).Will(Return.Value(mockDynamicInvocation)); factory = new MockProxyFactory(); Assert.IsNotNull(factory); objectContract = factory.CreateInstance("myCacheKey", mockInvokeDynamicFactory); Assert.IsNotNull(objectContract); factory.Dispose(); mockery.VerifyAllExpectationsHaveBeenMet(); }
public void ShouldCreateInstanceWithCacheKeyTest() { MockProxyFactory factory; IMockObject objectContract; factory = new MockProxyFactory(); Assert.IsNotNull(factory); Assert.IsFalse(factory.Disposed); objectContract = factory.CreateInstance("myCacheKey"); Assert.IsNotNull(objectContract); factory.Dispose(); Assert.IsTrue(factory.Disposed); }
public void ShouldFailOnDisposedCreateInstanceWithInvokeDynamicTest() { Mockery mockery; MockProxyFactory factory; IDynamicInvocation mockDynamicInvocation; mockery = new Mockery(); mockDynamicInvocation = mockery.NewMock <IDynamicInvocation>(); factory = new MockProxyFactory(); Assert.IsNotNull(factory); factory.Dispose(); factory.CreateInstance(mockDynamicInvocation); }
public void ShouldEnsureCachingTest() { Mockery mockery; MockProxyFactory factory; IMockObject objectContract0, objectContract1, objectContract2, objectContract3; MockProxyFactory.IInvokeDynamicFactory mockInvokeDynamicFactory; IDynamicInvocation mockDynamicInvocation; MethodInfo invokedMethodInfo; mockery = new Mockery(); mockDynamicInvocation = mockery.NewMock <IDynamicInvocation>(); mockInvokeDynamicFactory = mockery.NewMock <MockProxyFactory.IInvokeDynamicFactory>(); invokedMethodInfo = (MethodInfo)MemberInfoProxy <IDisposable> .GetLastMemberInfo(exec => exec.Dispose()); Expect.Exactly(1).On(mockInvokeDynamicFactory).Method("GetDynamicInvoker").With("myCacheKey", typeof(IMockObject)).Will(Return.Value(mockDynamicInvocation)); Expect.Exactly(1).On(mockInvokeDynamicFactory).Method("GetDynamicInvoker").With("myCacheKey_different", typeof(IMockObject)).Will(Return.Value(mockDynamicInvocation)); factory = new MockProxyFactory(); Assert.IsNotNull(factory); objectContract0 = factory.CreateInstance("myCacheKey", mockInvokeDynamicFactory); objectContract1 = factory.CreateInstance("myCacheKey_different", mockInvokeDynamicFactory); objectContract2 = factory.CreateInstance("myCacheKey", mockInvokeDynamicFactory); objectContract3 = factory.CreateInstance(mockDynamicInvocation); Assert.IsNotNull(objectContract0); Assert.IsNotNull(objectContract1); Assert.IsNotNull(objectContract2); Assert.IsNotNull(objectContract3); Assert.AreNotSame(objectContract0, objectContract1); Assert.AreSame(objectContract0, objectContract2); Assert.AreNotSame(objectContract1, objectContract2); Assert.AreNotSame(objectContract0, objectContract3); Assert.AreNotSame(objectContract1, objectContract3); Assert.AreNotSame(objectContract2, objectContract3); factory.Dispose(); mockery.VerifyAllExpectationsHaveBeenMet(); }
public void ShouldFailOnDisposedCreateInstanceWithCacheKeyTest() { Mockery mockery; MockProxyFactory factory; MockProxyFactory.IInvokeDynamicFactory mockInvokeDynamicFactory; mockery = new Mockery(); mockInvokeDynamicFactory = mockery.NewMock <MockProxyFactory.IInvokeDynamicFactory>(); factory = new MockProxyFactory(); Assert.IsNotNull(factory); factory.Dispose(); factory.CreateInstance("test"); }
public void ShouldFailOnDisposedCreateInstanceWithInvokeDynamicTest() { Mockery mockery; MockProxyFactory factory; IDynamicInvocation mockDynamicInvocation; mockery = new Mockery(); mockDynamicInvocation = mockery.NewMock<IDynamicInvocation>(); factory = new MockProxyFactory(); Assert.IsNotNull(factory); factory.Dispose(); factory.CreateInstance(mockDynamicInvocation); }
public void ShouldFailOnDisposedCreateInstanceWithCacheKeyTest() { Mockery mockery; MockProxyFactory factory; MockProxyFactory.IInvokeDynamicFactory mockInvokeDynamicFactory; mockery = new Mockery(); mockInvokeDynamicFactory = mockery.NewMock<MockProxyFactory.IInvokeDynamicFactory>(); factory = new MockProxyFactory(); Assert.IsNotNull(factory); factory.Dispose(); factory.CreateInstance("test"); }
public void ShouldEnsureCachingTest() { Mockery mockery; MockProxyFactory factory; IMockObject objectContract0, objectContract1, objectContract2, objectContract3; MockProxyFactory.IInvokeDynamicFactory mockInvokeDynamicFactory; IDynamicInvocation mockDynamicInvocation; MethodInfo invokedMethodInfo; mockery = new Mockery(); mockDynamicInvocation = mockery.NewMock<IDynamicInvocation>(); mockInvokeDynamicFactory = mockery.NewMock<MockProxyFactory.IInvokeDynamicFactory>(); invokedMethodInfo = (MethodInfo)MemberInfoProxy<IDisposable>.GetLastMemberInfo(exec => exec.Dispose()); Expect.Exactly(1).On(mockInvokeDynamicFactory).Method("GetDynamicInvoker").With("myCacheKey", typeof(IMockObject)).Will(Return.Value(mockDynamicInvocation)); Expect.Exactly(1).On(mockInvokeDynamicFactory).Method("GetDynamicInvoker").With("myCacheKey_different", typeof(IMockObject)).Will(Return.Value(mockDynamicInvocation)); factory = new MockProxyFactory(); Assert.IsNotNull(factory); objectContract0 = factory.CreateInstance("myCacheKey", mockInvokeDynamicFactory); objectContract1 = factory.CreateInstance("myCacheKey_different", mockInvokeDynamicFactory); objectContract2 = factory.CreateInstance("myCacheKey", mockInvokeDynamicFactory); objectContract3 = factory.CreateInstance(mockDynamicInvocation); Assert.IsNotNull(objectContract0); Assert.IsNotNull(objectContract1); Assert.IsNotNull(objectContract2); Assert.IsNotNull(objectContract3); Assert.AreNotSame(objectContract0, objectContract1); Assert.AreSame(objectContract0, objectContract2); Assert.AreNotSame(objectContract1, objectContract2); Assert.AreNotSame(objectContract0, objectContract3); Assert.AreNotSame(objectContract1, objectContract3); Assert.AreNotSame(objectContract2, objectContract3); factory.Dispose(); mockery.VerifyAllExpectationsHaveBeenMet(); }