Beispiel #1
0
        public void ExecuteRethrowsNormalException()
        {
            // Arrange
            var cmd = new DelegatingGuardClauseCommand {
                OnExecute = v => { throw new InvalidOperationException(); }
            };
            var sut = new ReflectionExceptionUnwrappingCommand(cmd);
            // Act & Assert
            var dummyValue = new object();

            Assert.Throws <InvalidOperationException>(() =>
                                                      sut.Execute(dummyValue));
        }
        public void ExecuteRethrowsNormalException()
        {
            // Fixture setup
            var cmd = new DelegatingGuardClauseCommand {
                OnExecute = v => { throw new InvalidOperationException(); }
            };
            var sut = new ReflectionExceptionUnwrappingCommand(cmd);
            // Exercise system and verify outcome
            var dummyValue = new object();

            Assert.Throws <InvalidOperationException>(() =>
                                                      sut.Execute(dummyValue));
            // Teardown
        }
Beispiel #3
0
        public void ExecuteUnwrapsAndThrowsInnerExceptionFromTargetInvocationException()
        {
            // Arrange
            var expectedException = new InvalidOperationException();
            var cmd = new DelegatingGuardClauseCommand {
                OnExecute = v => { throw new TargetInvocationException(expectedException); }
            };
            var sut = new ReflectionExceptionUnwrappingCommand(cmd);
            // Act & Assert
            var dummyValue = new object();
            var e          = Assert.Throws <InvalidOperationException>(() =>
                                                                       sut.Execute(dummyValue));

            Assert.Equal(expectedException, e);
        }
Beispiel #4
0
        public void ExecuteExecutesDecoratedCommand()
        {
            // Arrange
            var mockVerified  = false;
            var expectedValue = new object();
            var cmd           = new DelegatingGuardClauseCommand {
                OnExecute = v => mockVerified = expectedValue.Equals(v)
            };
            var sut = new ReflectionExceptionUnwrappingCommand(cmd);

            // Act
            sut.Execute(expectedValue);
            // Assert
            Assert.True(mockVerified, "Mock verified.");
        }
        public void ExecuteUnwrapsAndThrowsInnerExceptionFromTargetInvocationException()
        {
            // Fixture setup
            var expectedException = new InvalidOperationException();
            var cmd = new DelegatingGuardClauseCommand {
                OnExecute = v => { throw new TargetInvocationException(expectedException); }
            };
            var sut = new ReflectionExceptionUnwrappingCommand(cmd);
            // Exercise system and verify outcome
            var dummyValue = new object();
            var e          = Assert.Throws <InvalidOperationException>(() =>
                                                                       sut.Execute(dummyValue));

            Assert.Equal(expectedException, e);
            // Teardown
        }
        public void ExecuteExecutesDecoratedCommand()
        {
            // Fixture setup
            var mockVerified  = false;
            var expectedValue = new object();
            var cmd           = new DelegatingGuardClauseCommand {
                OnExecute = v => mockVerified = expectedValue.Equals(v)
            };
            var sut = new ReflectionExceptionUnwrappingCommand(cmd);

            // Exercise system
            sut.Execute(expectedValue);
            // Verify outcome
            Assert.True(mockVerified, "Mock verified.");
            // Teardown
        }