コード例 #1
0
        public void SutIsContextualCommand()
        {
            // Arrange
            var dummyCommand = new DelegatingGuardClauseCommand();
            // Act
            var sut = new ReflectionExceptionUnwrappingCommand(dummyCommand);

            // Assert
            Assert.IsAssignableFrom <IGuardClauseCommand>(sut);
        }
コード例 #2
0
        public void CommandIsCorrect()
        {
            // Arrange
            var expectedCommand = new DelegatingGuardClauseCommand();
            var sut             = new ReflectionExceptionUnwrappingCommand(expectedCommand);
            // Act
            IGuardClauseCommand result = sut.Command;

            // Assert
            Assert.Equal(expectedCommand, result);
        }
コード例 #3
0
        public void SutIsContextualCommand()
        {
            // Fixture setup
            var dummyCommand = new DelegatingGuardClauseCommand();
            // Exercise system
            var sut = new ReflectionExceptionUnwrappingCommand(dummyCommand);

            // Verify outcome
            Assert.IsAssignableFrom <IGuardClauseCommand>(sut);
            // Teardown
        }
コード例 #4
0
        public void VerifyThrowsWhenCommandThrowsArgumentNullExceptionWithInvalidParamName(string invalidParamName)
        {
            var cmd = new DelegatingGuardClauseCommand
            {
                OnExecute = v => { throw new ArgumentNullException(invalidParamName); }
            };
            var sut = new NullReferenceBehaviorExpectation();

            Assert.Throws <Exception>(() =>
                                      sut.Verify(cmd));
        }
コード例 #5
0
        public void CommandIsCorrect()
        {
            // Fixture setup
            var expectedCommand = new DelegatingGuardClauseCommand();
            var sut             = new ReflectionExceptionUnwrappingCommand(expectedCommand);
            // Exercise system
            IGuardClauseCommand result = sut.Command;

            // Verify outcome
            Assert.Equal(expectedCommand, result);
            // Teardown
        }
コード例 #6
0
        public void RequestedParamNameIsCorrect()
        {
            const string expected    = "foo";
            var          commandStub = new DelegatingGuardClauseCommand {
                RequestedParameterName = expected
            };
            var sut = new ReflectionExceptionUnwrappingCommand(commandStub);

            var actual = sut.RequestedParameterName;

            Assert.Equal(expected, actual);
        }
コード例 #7
0
        public void VerifySucceedsWhenCommandThrowsCorrectException()
        {
            // Arrange
            var cmd = new DelegatingGuardClauseCommand {
                OnExecute = v => { throw new ArgumentNullException(); }
            };
            var sut = new NullReferenceBehaviorExpectation();

            // Act & Assert
            Assert.Null(Record.Exception(() =>
                                         sut.Verify(cmd)));
        }
コード例 #8
0
        public void ContextTypeIsCorrect(Type type)
        {
            // Arrange
            var cmd = new DelegatingGuardClauseCommand {
                RequestedType = type
            };
            var sut = new ReflectionExceptionUnwrappingCommand(cmd);
            // Act
            var result = sut.RequestedType;

            // Assert
            Assert.Equal(type, result);
        }
コード例 #9
0
        public void VerifySucceedsWhenCommandThrowsCorrectException()
        {
            // Fixture setup
            var cmd = new DelegatingGuardClauseCommand {
                OnExecute = v => { throw new ArgumentNullException(); }
            };
            var sut = new NullReferenceBehaviorExpectation();

            // Exercise system and verify outcome
            Assert.Null(Record.Exception(() =>
                                         sut.Verify(cmd)));
            // Teardown
        }
コード例 #10
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));
        }
コード例 #11
0
        public void ContextTypeIsCorrect(Type type)
        {
            // Fixture setup
            var cmd = new DelegatingGuardClauseCommand {
                RequestedType = type
            };
            var sut = new ReflectionExceptionUnwrappingCommand(cmd);
            // Exercise system
            var result = sut.RequestedType;

            // Verify outcome
            Assert.Equal(type, result);
            // Teardown
        }
コード例 #12
0
        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
        }
コード例 #13
0
        public void VerifySuccedsWhenCommandThrowsCorrectException()
        {
            // Arrange
            var cmd = new DelegatingGuardClauseCommand
            {
                OnExecute     = v => { throw new ArgumentException(); },
                RequestedType = typeof(Guid)
            };
            var sut = new EmptyGuidBehaviorExpectation();

            // Act & Assert
            Assert.Null(Record.Exception(() =>
                                         sut.Verify(cmd)));
        }
コード例 #14
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);
        }
コード例 #15
0
        public void CreateExceptionReturnsCorrectResult()
        {
            // Arrange
            var value    = Guid.NewGuid().ToString();
            var expected = new Exception();
            var cmd      = new DelegatingGuardClauseCommand {
                OnCreateException = v => value == v ? expected : new Exception()
            };
            var sut = new ReflectionExceptionUnwrappingCommand(cmd);
            // Act
            var result = sut.CreateException(value);

            // Assert
            Assert.Equal(expected, result);
        }
コード例 #16
0
        public void VerifySuccedsWhenCommandThrowsCorrectException()
        {
            // Fixture setup
            var cmd = new DelegatingGuardClauseCommand
            {
                OnExecute     = v => { throw new ArgumentException(); },
                RequestedType = typeof(Guid)
            };
            var sut = new EmptyGuidBehaviorExpectation();

            // Exercise system and verify outcome
            Assert.Null(Record.Exception(() =>
                                         sut.Verify(cmd)));
            // Teardown
        }
コード例 #17
0
        public void VerifyThrowsWhenCommandDoesNotThrow()
        {
            // Arrange
            var expected = new Exception();
            var cmd      = new DelegatingGuardClauseCommand
            {
                OnCreateException = v => v == "null" ? expected : new Exception()
            };
            var sut = new NullReferenceBehaviorExpectation();
            // Act & Assert
            var result = Assert.Throws <Exception>(() =>
                                                   sut.Verify(cmd));

            Assert.Equal(expected, result);
        }
コード例 #18
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.");
        }
コード例 #19
0
        public void VerifyVerifiesAllBehaviorExpectations()
        {
            // Arrange
            var observedCommands = new List <IGuardClauseCommand>();
            var expectations     = Enumerable.Repeat(new DelegatingBehaviorExpectation {
                OnVerify = observedCommands.Add
            }, 3).ToArray();
            var sut = new CompositeBehaviorExpectation(expectations);

            var cmd = new DelegatingGuardClauseCommand();

            // Act
            sut.Verify(cmd);
            // Assert
            Assert.Equal(expectations.Length, observedCommands.Count(c => cmd.Equals(c)));
        }
コード例 #20
0
        public void CreateExceptionReturnsCorrectResult()
        {
            // Fixture setup
            var value    = Guid.NewGuid().ToString();
            var expected = new Exception();
            var cmd      = new DelegatingGuardClauseCommand {
                OnCreateException = v => value == v ? expected : new Exception()
            };
            var sut = new ReflectionExceptionUnwrappingCommand(cmd);
            // Exercise system
            var result = sut.CreateException(value);

            // Verify outcome
            Assert.Equal(expected, result);
            // Teardown
        }
コード例 #21
0
        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
        }
コード例 #22
0
        public void VerifyThrowsWhenCommandDoesNotThrow()
        {
            // Arrange
            var expected = new Exception();
            var cmd      = new DelegatingGuardClauseCommand
            {
                OnCreateException = v => v == "\"Guid.Empty\"" ? expected : new Exception(),
                RequestedType     = typeof(Guid)
            };
            var sut = new EmptyGuidBehaviorExpectation();
            // Act & Assert
            var result = Assert.Throws <Exception>(() =>
                                                   sut.Verify(cmd));

            Assert.Equal(expected, result);
        }
コード例 #23
0
        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
        }
コード例 #24
0
        public void VerifyThrowsWhenCommandDoesNotThrow()
        {
            // Fixture setup
            var expected = new Exception();
            var cmd      = new DelegatingGuardClauseCommand
            {
                OnCreateException = v => v == "null" ? expected : new Exception()
            };
            var sut = new NullReferenceBehaviorExpectation();
            // Exercise system and verify outcome
            var result = Assert.Throws <Exception>(() =>
                                                   sut.Verify(cmd));

            Assert.Equal(expected, result);
            // Teardown
        }
コード例 #25
0
        public void VerifyThrowsWhenCommandThrowsUnexpectedException()
        {
            // Arrange
            var expectedInner = new Exception();
            var expected      = new Exception();
            var cmd           = new DelegatingGuardClauseCommand
            {
                OnExecute = v => { throw expectedInner; },
                OnCreateExceptionWithInner = (v, e) => v == "null" && expectedInner.Equals(e) ? expected : new Exception()
            };
            var sut = new NullReferenceBehaviorExpectation();
            // Act & Assert
            var result = Assert.Throws <Exception>(() =>
                                                   sut.Verify(cmd));

            Assert.Equal(expected, result);
        }
コード例 #26
0
        public void VerifyDoesNothingWhenContextTypeIsNotInterfaceOrReference(Type type)
        {
            // Arrange
            var verifyInvoked = false;
            var mockCommand   = new DelegatingGuardClauseCommand {
                OnExecute = v => verifyInvoked = true
            };

            mockCommand.RequestedType = type;

            var sut = new NullReferenceBehaviorExpectation();

            // Act
            sut.Verify(mockCommand);
            // Assert
            Assert.False(verifyInvoked, "Mock verified.");
        }
コード例 #27
0
        public void VerifyVerifiesAllBehaviorExpectations()
        {
            // Fixture setup
            var observedCommands = new List <IGuardClauseCommand>();
            var expectations     = Enumerable.Repeat(new DelegatingBehaviorExpectation {
                OnVerify = observedCommands.Add
            }, 3).ToArray();
            var sut = new CompositeBehaviorExpectation(expectations);

            var cmd = new DelegatingGuardClauseCommand();

            // Exercise system
            sut.Verify(cmd);
            // Verify outcome
            Assert.Equal(expectations.Length, observedCommands.Count(c => cmd.Equals(c)));
            // Teardown
        }
コード例 #28
0
        public void VerifyThrowsWhenCommandDoesNotThrow()
        {
            // Fixture setup
            var expected = new Exception();
            var cmd      = new DelegatingGuardClauseCommand
            {
                OnCreateException = v => v == "\"Guid.Empty\"" ? expected : new Exception(),
                RequestedType     = typeof(Guid)
            };
            var sut = new EmptyGuidBehaviorExpectation();
            // Exercise system and verify outcome
            var result = Assert.Throws <Exception>(() =>
                                                   sut.Verify(cmd));

            Assert.Equal(expected, result);
            // Teardown
        }
コード例 #29
0
        public void VerifyDoesNothingWhenRequestedTypeIsNotGuid(Type type)
        {
            // Arrange
            var executeInvoked = false;
            var mockCommand    = new DelegatingGuardClauseCommand {
                OnExecute = v => executeInvoked = true
            };

            mockCommand.RequestedType = type;

            var sut = new EmptyGuidBehaviorExpectation();

            // Act
            sut.Verify(mockCommand);
            // Assert
            Assert.False(executeInvoked);
        }
コード例 #30
0
        public void VerifyDoesNothingWhenContextTypeIsNotInterfaceOrReference(Type type)
        {
            // Fixture setup
            var verifyInvoked = false;
            var mockCommand   = new DelegatingGuardClauseCommand {
                OnExecute = v => verifyInvoked = true
            };

            mockCommand.RequestedType = type;

            var sut = new NullReferenceBehaviorExpectation();

            // Exercise system
            sut.Verify(mockCommand);
            // Verify outcome
            Assert.False(verifyInvoked, "Mock verified.");
            // Teardown
        }