Example #1
0
        public void CreateExceptionReturnsExceptionWithCorrectMessage()
        {
            // Arrange
            var dummyMethod    = new DelegatingMethod();
            var dummyExpansion = new DelegatingExpansion <object>();
            var parameter      = MethodInvokeCommandTest.CreateAnonymousParameterInfo();
            var sut            = new MethodInvokeCommand(dummyMethod, dummyExpansion, parameter);
            // Act
            var message = Guid.NewGuid().ToString();
            var result  = sut.CreateException(message);
            // Assert
            var e = Assert.IsAssignableFrom <GuardClauseException>(result);

            Assert.Contains(message, e.Message);
        }
Example #2
0
        public void CreateExceptionWithInnerReturnsExceptionWithCorrectInnerException()
        {
            // Fixture setup
            var dummyMethod    = new DelegatingMethod();
            var dummyExpansion = new DelegatingExpansion <object>();
            var parameter      = MethodInvokeCommandTest.CreateAnonymousParameterInfo();
            var sut            = new MethodInvokeCommand(dummyMethod, dummyExpansion, parameter);
            // Exercise system
            var message = Guid.NewGuid().ToString();
            var inner   = new Exception();
            var result  = sut.CreateException(message, inner);
            // Verify outcome
            var e = Assert.IsAssignableFrom <GuardClauseException>(result);

            Assert.Equal(inner, e.InnerException);
            // Teardown
        }
Example #3
0
        public void CreateExceptionWithCustomFailureReasonReturnsExceptionWithCorrectMessageAndInner()
        {
            // Arrange
            var dummyMethod    = new DelegatingMethod();
            var dummyExpansion = new DelegatingExpansion <object>();
            var parameter      = MethodInvokeCommandTest.CreateAnonymousParameterInfo();
            var sut            = new MethodInvokeCommand(dummyMethod, dummyExpansion, parameter);
            var inner          = new Exception();
            // Act
            var dummyValue    = "dummy value";
            var failureReason = "MY_CUSTOM_MESSAGE";
            var result        = sut.CreateException(dummyValue, failureReason, inner);
            // Assert
            var ex = Assert.IsAssignableFrom <GuardClauseException>(result);

            Assert.Contains(", and MY_CUSTOM_MESSAGE", ex.Message);
            Assert.Equal(inner, ex.InnerException);
        }