Пример #1
0
        public void WhenCallingServiceThrowingExceptionThenInterceptorIsCalled()
        {
            // Assign
            SimpleService       service = new SimpleService();
            DefaultProxyBuilder builder = this.CreateTestableBuilder();

            this.interceptor.Setup(i => i.OnExecuting());
            this.interceptor.Setup(i => i.OnExecuted());
            this.interceptor.Setup(i => i.OnException(It.IsAny <Exception>()));
            var  proxy           = builder.Build(service, this.interceptor.Object);
            bool exceptionRaised = false;

            // Act
            try
            {
                proxy.ThrowsException();
            }
            catch (Exception)
            {
                exceptionRaised = true;
            }

            // Assert
            this.interceptor.Verify(i => i.OnExecuting(), Times.Once());
            this.interceptor.Verify(i => i.OnExecuted(), Times.Never());
            this.interceptor.Verify(i => i.OnException(It.IsAny <Exception>()), Times.Once());
            Assert.True(exceptionRaised);
        }
Пример #2
0
        public void WhenBuildingProxyThenReturnsProxyOfSameType()
        {
            // Assign
            SimpleService       service = new SimpleService();
            DefaultProxyBuilder builder = this.CreateTestableBuilder();

            // Act
            var proxy = builder.Build(service, this.interceptor.Object);

            // Assert
            Assert.NotNull(proxy);
            Assert.IsAssignableFrom(typeof(SimpleService), proxy);
        }
Пример #3
0
        public void WhenBuildingProxyThenReturnsProxyOfSameType()
        {
            // Assign
            SimpleService service = new SimpleService();
            DefaultProxyBuilder builder = this.CreateTestableBuilder();

            // Act
            var proxy = builder.Build(service, this.interceptor.Object);

            // Assert
            Assert.NotNull(proxy);
            Assert.IsAssignableFrom(typeof(SimpleService), proxy);
        }
Пример #4
0
        public void WhenBuildingProxyMultipleTimesThenUseCache()
        {
            // Assign
            SimpleService       service = new SimpleService();
            DefaultProxyBuilder builder = this.CreateTestableBuilder();

            // Act
            builder.Build(service, this.interceptor.Object);
            var proxy = builder.Build(service, this.interceptor.Object);

            // Assert
            // TODO : How to validate the cache hit? Using a external object?
            Assert.NotNull(proxy);
            Assert.IsAssignableFrom(typeof(SimpleService), proxy);
        }
Пример #5
0
        public void WhenBuildingProxyMultipleTimesThenUseCache()
        {
            // Assign
            SimpleService service = new SimpleService();
            DefaultProxyBuilder builder = this.CreateTestableBuilder();

            // Act
            builder.Build(service, this.interceptor.Object);
            var proxy = builder.Build(service, this.interceptor.Object);

            // Assert
            // TODO : How to validate the cache hit? Using a external object?
            Assert.NotNull(proxy);
            Assert.IsAssignableFrom(typeof(SimpleService), proxy);
        }
Пример #6
0
        public void WhenCallingNonVirtualServiceThenInterceptorIsNotCalled()
        {
            // Assign
            SimpleService       service = new SimpleService();
            DefaultProxyBuilder builder = this.CreateTestableBuilder();

            this.interceptor.Setup(i => i.OnExecuting());
            this.interceptor.Setup(i => i.OnExecuted());
            this.interceptor.Setup(i => i.OnException(It.IsAny <Exception>()));
            var proxy = builder.Build(service, this.interceptor.Object);

            // Act
            proxy.NonVirtual();

            // Assert
            this.interceptor.Verify(i => i.OnExecuting(), Times.Never());
            this.interceptor.Verify(i => i.OnExecuted(), Times.Never());
            this.interceptor.Verify(i => i.OnException(It.IsAny <Exception>()), Times.Never());
        }
Пример #7
0
        public void WhenCallingNonVirtualServiceThenInterceptorIsNotCalled()
        {
            // Assign
            SimpleService service = new SimpleService();
            DefaultProxyBuilder builder = this.CreateTestableBuilder();

            this.interceptor.Setup(i => i.OnExecuting());
            this.interceptor.Setup(i => i.OnExecuted());
            this.interceptor.Setup(i => i.OnException(It.IsAny<Exception>()));
            var proxy = builder.Build(service, this.interceptor.Object);

            // Act
            proxy.NonVirtual();

            // Assert
            this.interceptor.Verify(i => i.OnExecuting(), Times.Never());
            this.interceptor.Verify(i => i.OnExecuted(), Times.Never());
            this.interceptor.Verify(i => i.OnException(It.IsAny<Exception>()), Times.Never());
        }
Пример #8
0
        public void WhenCallingWithEnumParameterThenInterceptorIsCalled()
        {
            // Assign
            SimpleService       service = new SimpleService();
            DefaultProxyBuilder builder = this.CreateTestableBuilder();

            this.interceptor.Setup(i => i.OnExecuting());
            this.interceptor.Setup(i => i.OnExecuted());
            this.interceptor.Setup(i => i.OnException(It.IsAny <Exception>()));
            var proxy = builder.Build(service, this.interceptor.Object);
            var value = StringSplitOptions.None;

            // Act
            proxy.EnumTypeParameter(value);

            // Assert
            this.interceptor.Verify(i => i.OnExecuting(), Times.Once());
            this.interceptor.Verify(i => i.OnExecuted(), Times.Once());
            this.interceptor.Verify(i => i.OnException(It.IsAny <Exception>()), Times.Never());
        }
Пример #9
0
        public void WhenCallingServiceReturningEnumTypeThenInterceptorIsCalled()
        {
            // Assign
            SimpleService       service = new SimpleService();
            DefaultProxyBuilder builder = this.CreateTestableBuilder();

            this.interceptor.Setup(i => i.OnExecuting());
            this.interceptor.Setup(i => i.OnExecuted());
            this.interceptor.Setup(i => i.OnException(It.IsAny <Exception>()));
            var proxy = builder.Build(service, this.interceptor.Object);

            // Act
            var value4 = proxy.ReturnsEnum();

            // Assert
            this.interceptor.Verify(i => i.OnExecuting(), Times.Once());
            this.interceptor.Verify(i => i.OnExecuted(), Times.Once());
            this.interceptor.Verify(i => i.OnException(It.IsAny <Exception>()), Times.Never());

            Assert.Equal(service.EnumValue, value4);
        }
Пример #10
0
        public void WhenCallingWithValueTypeParameterThenInterceptorIsCalled()
        {
            // Assign
            SimpleService service = new SimpleService();
            DefaultProxyBuilder builder = this.CreateTestableBuilder();

            this.interceptor.Setup(i => i.OnExecuting());
            this.interceptor.Setup(i => i.OnExecuted());
            this.interceptor.Setup(i => i.OnException(It.IsAny<Exception>()));
            var proxy = builder.Build(service, this.interceptor.Object);
            var value = 123;

            // Act 
            proxy.ValueTypeParameter(value);

            // Assert
            this.interceptor.Verify(i => i.OnExecuting(), Times.Once());
            this.interceptor.Verify(i => i.OnExecuted(), Times.Once());
            this.interceptor.Verify(i => i.OnException(It.IsAny<Exception>()), Times.Never());

            Assert.Equal(value, proxy.ValueTypeValue);
        }
Пример #11
0
        public void WhenCallingServiceThrowingExceptionThenInterceptorIsCalled()
        {
            // Assign
            SimpleService service = new SimpleService();
            DefaultProxyBuilder builder = this.CreateTestableBuilder();

            this.interceptor.Setup(i => i.OnExecuting());
            this.interceptor.Setup(i => i.OnExecuted());
            this.interceptor.Setup(i => i.OnException(It.IsAny<Exception>()));
            var proxy = builder.Build(service, this.interceptor.Object);
            bool exceptionRaised = false;

            // Act
            try
            {
                proxy.ThrowsException();
            }
            catch (Exception)
            {
                exceptionRaised = true;
            }

            // Assert
            this.interceptor.Verify(i => i.OnExecuting(), Times.Once());
            this.interceptor.Verify(i => i.OnExecuted(), Times.Never());
            this.interceptor.Verify(i => i.OnException(It.IsAny<Exception>()), Times.Once());
            Assert.True(exceptionRaised);
        }
Пример #12
0
        public void WhenCallingServiceReturningEnumTypeThenInterceptorIsCalled()
        {
            // Assign
            SimpleService service = new SimpleService();
            DefaultProxyBuilder builder = this.CreateTestableBuilder();

            this.interceptor.Setup(i => i.OnExecuting());
            this.interceptor.Setup(i => i.OnExecuted());
            this.interceptor.Setup(i => i.OnException(It.IsAny<Exception>()));
            var proxy = builder.Build(service, this.interceptor.Object);
            
            // Act
            var value4 = proxy.ReturnsEnum();

            // Assert
            this.interceptor.Verify(i => i.OnExecuting(), Times.Once());
            this.interceptor.Verify(i => i.OnExecuted(), Times.Once());
            this.interceptor.Verify(i => i.OnException(It.IsAny<Exception>()), Times.Never());

            Assert.Equal(service.EnumValue, value4);
        }