Пример #1
0
        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();
        }
Пример #2
0
        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();
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
        }
Пример #5
0
        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);
        }
Пример #6
0
        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();
        }
Пример #7
0
        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");
        }
Пример #8
0
        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);
        }
Пример #9
0
        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");
        }
Пример #10
0
        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();
        }