Exemplo n.º 1
0
        public void SutIsContextualCommand()
        {
            // Arrange
            var dummyCommand = new DelegatingGuardClauseCommand();
            // Act
            var sut = new ReflectionExceptionUnwrappingCommand(dummyCommand);

            // Assert
            Assert.IsAssignableFrom <IGuardClauseCommand>(sut);
        }
Exemplo n.º 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);
        }
        public void SutIsContextualCommand()
        {
            // Fixture setup
            var dummyCommand = new DelegatingGuardClauseCommand();
            // Exercise system
            var sut = new ReflectionExceptionUnwrappingCommand(dummyCommand);

            // Verify outcome
            Assert.IsAssignableFrom <IGuardClauseCommand>(sut);
            // Teardown
        }
        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));
        }
        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
        }
Exemplo n.º 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);
        }
Exemplo n.º 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)));
        }
Exemplo n.º 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);
        }
        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
        }
Exemplo n.º 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));
        }
        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
        }
        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
        }
        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)));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
        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
        }
Exemplo n.º 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);
        }
Exemplo n.º 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.");
        }
        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)));
        }
        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
        }
        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
        }
        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);
        }
        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 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
        }
        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);
        }
Exemplo n.º 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.");
        }
Exemplo n.º 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
        }
        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
        }
        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);
        }
        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
        }