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 VerifySuccedsWhenCommandThrowsCorrectException()
 {
     // Fixture setup
     var cmd = new DelegatingGuardClauseCommand { OnExecute = v => { throw new ArgumentNullException(); } };
     var sut = new NullReferenceBehaviorExpectation();
     // Exercise system and verify outcome
     Assert.DoesNotThrow(() =>
         sut.Verify(cmd));
     // Teardown
 }
 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
 }
 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 SutIsContextualCommand()
        {
            // Fixture setup
            var dummyCommand = new DelegatingGuardClauseCommand();
            // Exercise system
            var sut = new ReflectionExceptionUnwrappingCommand(dummyCommand);

            // Verify outcome
            Assert.IsAssignableFrom <IGuardClauseCommand>(sut);
            // Teardown
        }
        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
        }
 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
 }
        public void VerifySuccedsWhenCommandThrowsCorrectException()
        {
            // Fixture setup
            var cmd = new DelegatingGuardClauseCommand {
                OnExecute = v => { throw new ArgumentNullException(); }
            };
            var sut = new NullReferenceBehaviorExpectation();

            // Exercise system and verify outcome
            Assert.DoesNotThrow(() =>
                                sut.Verify(cmd));
            // Teardown
        }
        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
        }
        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 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 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.DoesNotThrow(() =>
         sut.Verify(cmd));
     // Teardown
 }
        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 VerifyDoesNothingWhenRequestedTypeIsNotGuid(Type type)
        {
            // Fixture setup
            var executeInvoked = false;
            var mockCommand = new DelegatingGuardClauseCommand { OnExecute = v => executeInvoked = true };
            mockCommand.RequestedType = type;

            var sut = new EmptyGuidBehaviorExpectation();
            // Exercise system
            sut.Verify(mockCommand);
            // Verify outcome
            Assert.False(executeInvoked);
            // Teardown
        }
Esempio n. 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.DoesNotThrow(() =>
                                sut.Verify(cmd));
            // 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 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 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 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
        }
Esempio n. 21
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
        }
        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 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
        }
        public void VerifyThrowsWhenCommandThrowsUnexpectedException()
        {
            // Fixture setup
            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();
            // Exercise system and verify outcome
            var result = Assert.Throws <Exception>(() =>
                                                   sut.Verify(cmd));

            Assert.Equal(expected, result);
            // Teardown
        }
Esempio n. 25
0
        public void VerifyDoesNothingWhenRequestedTypeIsNotGuid(Type type)
        {
            // Fixture setup
            var executeInvoked = false;
            var mockCommand    = new DelegatingGuardClauseCommand {
                OnExecute = v => executeInvoked = true
            };

            mockCommand.RequestedType = type;

            var sut = new EmptyGuidBehaviorExpectation();

            // Exercise system
            sut.Verify(mockCommand);
            // Verify outcome
            Assert.False(executeInvoked);
            // Teardown
        }
        public void VerifyCorrectlyInvokesExecuteForNullableContexts(Type type)
        {
            // Fixture setup
            var mockVerified = false;
            var mockCommand = new DelegatingGuardClauseCommand
            {
                OnExecute = v => mockVerified = v == null,
                OnCreateException = v => new InvalidOperationException()
            };
            mockCommand.RequestedType = type;

            var sut = new NullReferenceBehaviorExpectation();
            // Exercise system
            try
            {
                sut.Verify(mockCommand);
            }
            catch (InvalidOperationException) { }
            // Verify outcome
            Assert.True(mockVerified, "Mock verified.");
            // Teardown
        }
        public void VerifyCorrectlyInvokesExecuteWhenRequestedTypeIsGuid()
        {
            // Fixture setup
            var mockVerified = false;
            var mockCommand = new DelegatingGuardClauseCommand
            {
                OnExecute = v => mockVerified = Guid.Empty.Equals(v),
                OnCreateException = v => new InvalidOperationException(),
                RequestedType = typeof(Guid)
            };

            var sut = new EmptyGuidBehaviorExpectation();
            // Exercise system
            try
            {
                sut.Verify(mockCommand);
            }
            catch (InvalidOperationException) { }
            // Verify outcome
            Assert.True(mockVerified);
            // Teardown
        }
Esempio n. 28
0
        public void VerifyCorrectlyInvokesExecuteWhenRequestedTypeIsGuid()
        {
            // Fixture setup
            var mockVerified = false;
            var mockCommand  = new DelegatingGuardClauseCommand
            {
                OnExecute         = v => mockVerified = Guid.Empty.Equals(v),
                OnCreateException = v => new InvalidOperationException(),
                RequestedType     = typeof(Guid)
            };

            var sut = new EmptyGuidBehaviorExpectation();

            // Exercise system
            try
            {
                sut.Verify(mockCommand);
            }
            catch (InvalidOperationException) { }
            // Verify outcome
            Assert.True(mockVerified);
            // Teardown
        }
        public void VerifyCorrectlyInvokesExecuteForNullableContexts(Type type)
        {
            // Fixture setup
            var mockVerified = false;
            var mockCommand  = new DelegatingGuardClauseCommand
            {
                OnExecute         = v => mockVerified = v == null,
                OnCreateException = v => new InvalidOperationException()
            };

            mockCommand.RequestedType = type;

            var sut = new NullReferenceBehaviorExpectation();

            // Exercise system
            try
            {
                sut.Verify(mockCommand);
            }
            catch (InvalidOperationException) { }
            // Verify outcome
            Assert.True(mockVerified, "Mock verified.");
            // 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 VerifyThrowsWhenCommandThrowsUnexpectedException()
 {
     // Fixture setup
     var expectedInner = new Exception();
     var expected = new Exception();
     var cmd = new DelegatingGuardClauseCommand
     {
         OnExecute = v => { throw expectedInner; },
         OnCreateExceptionWithInner = (v, e) => v == "\"Guid.Empty\"" && expectedInner.Equals(e) ? 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 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 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 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
 }