public bool ContainsParameters(IGuardClauseCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            var expectedCommand = command as ReflectionExceptionUnwrappingCommand;
            MethodInvokeCommand methodCommand = null;

            if (expectedCommand == null)
            {
                methodCommand = command as MethodInvokeCommand;
            }
            else
            {
                methodCommand = expectedCommand.Command as MethodInvokeCommand;
            }

            if (methodCommand != null)
            {
                return(ParameterNames.Any(p => p == methodCommand.ParameterInfo.Name));
            }
            return(false);
        }
 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
 }
 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
 }
Exemple #4
0
        private void Verify(IMethod method)
        {
            var parameters = (from pi in method.Parameters
                              select this.Builder.CreateAnonymous(GuardClauseAssertion.GetParameterType(pi))).ToList();

            var i = 0;

            foreach (var pi in method.Parameters)
            {
                var expansion = new IndexedReplacement <object>(i++, parameters);

                var command   = new MethodInvokeCommand(method, expansion, pi);
                var unwrapper = new ReflectionExceptionUnwrappingCommand(command);
                this.BehaviorExpectation.Verify(unwrapper);
            }
        }
        public void ExecuteCorrectlyInvokesMethod()
        {
            // Fixture setup
            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);
            // Exercise system
            sut.Execute(value);
            // Verify outcome
            Assert.True(mockVerified);
            // Teardown
        }
        private void Verify(IMethod method, bool isReturnValueIterator)
        {
            var parameters = this.GetParameters(method);

            var i = 0;

            foreach (var pi in method.Parameters)
            {
                var expansion = new IndexedReplacement <object>(i++, parameters);

                var command   = new MethodInvokeCommand(method, expansion, pi);
                var unwrapper = new ReflectionExceptionUnwrappingCommand(command);
                if (isReturnValueIterator)
                {
                    var iteratorDecorator = new IteratorMethodInvokeCommand(unwrapper);
                    this.behaviorExpectation.Verify(iteratorDecorator);
                }
                else
                {
                    this.BehaviorExpectation.Verify(unwrapper);
                }
            }
        }
        private void Verify(IMethod method, bool isReturnValueIterator)
        {
            var parameters = (from pi in method.Parameters
                              select this.Builder.CreateAnonymous(GuardClauseAssertion.GetParameterType(pi))).ToList();

            var i = 0;
            foreach (var pi in method.Parameters)
            {
                var expansion = new IndexedReplacement<object>(i++, parameters);

                var command = new MethodInvokeCommand(method, expansion, pi);
                var unwrapper = new ReflectionExceptionUnwrappingCommand(command);
                if (isReturnValueIterator)
                {
                    var iteratorDecorator = new IteratorMethodInvokeCommand(unwrapper);
                    this.behaviorExpectation.Verify(iteratorDecorator);
                }
                else
                    this.BehaviorExpectation.Verify(unwrapper);
            }
        }
        private void Verify(IMethod method, bool isReturnValueIterator)
        {
            var parameters = this.GetParameters(method);

            var i = 0;
            foreach (var pi in method.Parameters)
            {
                var expansion = new IndexedReplacement<object>(i++, parameters);

                var command = new MethodInvokeCommand(method, expansion, pi);
                var unwrapper = new ReflectionExceptionUnwrappingCommand(command);
                if (isReturnValueIterator)
                {
                    var iteratorDecorator = new IteratorMethodInvokeCommand(unwrapper);
                    this.behaviorExpectation.Verify(iteratorDecorator);
                }
                else
                    this.BehaviorExpectation.Verify(unwrapper);
            }
        }
 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
 }