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 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 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
 }
Beispiel #6
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);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Verifies that a property has appripriate Guard Clauses in place.
        /// </summary>
        /// <param name="propertyInfo">The property.</param>
        /// <remarks>
        /// <para>
        /// Exactly which Guard Clauses are verified is defined by
        /// <see cref="BehaviorExpectation" />.
        /// </para>
        /// </remarks>
        public override void Verify(PropertyInfo propertyInfo)
        {
            if (propertyInfo == null)
            {
                throw new ArgumentNullException("propertyInfo");
            }

            if (propertyInfo.GetSetMethod() == null)
            {
                return;
            }

            var owner     = this.Builder.CreateAnonymous(propertyInfo.ReflectedType);
            var command   = new PropertySetCommand(propertyInfo, owner);
            var unwrapper = new ReflectionExceptionUnwrappingCommand(command);

            this.BehaviorExpectation.Verify(unwrapper);
        }
Beispiel #8
0
        /// <summary>
        /// Verifies that a property has appropriate Guard Clauses in place.
        /// </summary>
        /// <param name="propertyInfo">The property.</param>
        /// <remarks>
        /// <para>
        /// Exactly which Guard Clauses are verified is defined by
        /// <see cref="BehaviorExpectation" />.
        /// </para>
        /// </remarks>
        public override void Verify(PropertyInfo propertyInfo)
        {
            if (propertyInfo == null)
            {
                throw new ArgumentNullException("propertyInfo");
            }

            if (propertyInfo.GetSetMethod() == null)
            {
                return;
            }

            propertyInfo = this.ResolveUnclosedGenericType(propertyInfo);

            var owner     = this.CreateOwner(propertyInfo);
            var command   = new PropertySetCommand(propertyInfo, owner);
            var unwrapper = new ReflectionExceptionUnwrappingCommand(command);

            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 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 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
 }
        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);
            }
        }
        /// <summary>
        /// Verifies that a property has appripriate Guard Clauses in place.
        /// </summary>
        /// <param name="propertyInfo">The property.</param>
        /// <remarks>
        /// <para>
        /// Exactly which Guard Clauses are verified is defined by
        /// <see cref="BehaviorExpectation" />.
        /// </para>
        /// </remarks>
        public override void Verify(PropertyInfo propertyInfo)
        {
            if (propertyInfo == null)
                throw new ArgumentNullException("propertyInfo");

            if (propertyInfo.GetSetMethod() == null)
                return;

            var owner = this.Builder.CreateAnonymous(propertyInfo.ReflectedType);
            var command = new PropertySetCommand(propertyInfo, owner);
            var unwrapper = new ReflectionExceptionUnwrappingCommand(command);
            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);
            }
        }