Ejemplo n.º 1
0
        public void RequestedParameterNameIsCorrect()
        {
            var dummyMethod    = new DelegatingMethod();
            var dummyExpansion = new DelegatingExpansion <object>();
            var parameter      = MethodInvokeCommandTest.CreateAnonymousParameterInfo();
            var sut            = new MethodInvokeCommand(dummyMethod, dummyExpansion, parameter);

            var actual = sut.RequestedParameterName;

            Assert.Equal(parameter.Name, actual);
        }
Ejemplo n.º 2
0
        public void SutIsGuardClauseCommand()
        {
            // Arrange
            var dummyMethod    = new DelegatingMethod();
            var dummyExpansion = new DelegatingExpansion <object>();
            var dummyParameter = MethodInvokeCommandTest.CreateAnonymousParameterInfo();
            // Act
            var sut = new MethodInvokeCommand(dummyMethod, dummyExpansion, dummyParameter);

            // Assert
            Assert.IsAssignableFrom <IGuardClauseCommand>(sut);
        }
Ejemplo n.º 3
0
        public void SutIsGuardClauseCommand()
        {
            // Fixture setup
            var dummyMethod    = new DelegatingMethod();
            var dummyExpansion = new DelegatingExpansion <object>();
            var dummyParameter = MethodInvokeCommandTest.CreateAnonymousParameterInfo();
            // Exercise system
            var sut = new MethodInvokeCommand(dummyMethod, dummyExpansion, dummyParameter);

            // Verify outcome
            Assert.IsAssignableFrom <IGuardClauseCommand>(sut);
            // Teardown
        }
Ejemplo n.º 4
0
        public void RequestedTypeIsCorrect()
        {
            // Arrange
            var dummyMethod    = new DelegatingMethod();
            var dummyExpansion = new DelegatingExpansion <object>();
            var parameter      = MethodInvokeCommandTest.CreateAnonymousParameterInfo();
            var sut            = new MethodInvokeCommand(dummyMethod, dummyExpansion, parameter);
            // Act
            var result = sut.RequestedType;

            // Assert
            Assert.Equal(parameter.ParameterType, result);
        }
Ejemplo n.º 5
0
        public void ExpansionIsCorrect()
        {
            // Arrange
            var dummyMethod    = new DelegatingMethod();
            var expansion      = new DelegatingExpansion <object>();
            var dummyParameter = MethodInvokeCommandTest.CreateAnonymousParameterInfo();
            var sut            = new MethodInvokeCommand(dummyMethod, expansion, dummyParameter);
            // Act
            IExpansion <object> result = sut.Expansion;

            // Assert
            Assert.Equal(expansion, result);
        }
Ejemplo n.º 6
0
        public void ParameterInfoIsCorrect()
        {
            // Fixture setup
            var dummyMethod    = new DelegatingMethod();
            var dummyExpansion = new DelegatingExpansion <object>();
            var parameter      = MethodInvokeCommandTest.CreateAnonymousParameterInfo();
            var sut            = new MethodInvokeCommand(dummyMethod, dummyExpansion, parameter);
            // Exercise system
            ParameterInfo result = sut.ParameterInfo;

            // Verify outcome
            Assert.Equal(parameter, result);
            // Teardown
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
        public void ExecuteCorrectlyInvokesMethod()
        {
            // Arrange
            var value     = new object();
            var arguments = new[] { new object(), new object(), new object() };
            var expansion = new DelegatingExpansion <object> {
                OnExpand = v => v == value ? arguments : new object[0]
            };
            var dummyParameter = MethodInvokeCommandTest.CreateAnonymousParameterInfo();

            var mockVerified = false;
            var method       = new DelegatingMethod {
                OnInvoke = a => mockVerified = a == arguments
            };

            var sut = new MethodInvokeCommand(method, expansion, dummyParameter);

            // Act
            sut.Execute(value);
            // Assert
            Assert.True(mockVerified);
        }