public void VerifyConstructorInvokesBehaviorExpectationWithCorrectParameterInfo(Type type, int constructorIndex)
        {
            // Fixture setup
            var ctor       = type.GetConstructors().ElementAt(constructorIndex);
            var parameters = ctor.GetParameters();

            var observedParameters = new List <ParameterInfo>();
            var expectation        = new DelegatingBehaviorExpectation
            {
                OnVerify = c =>
                {
                    var unwrapper = Assert.IsAssignableFrom <ReflectionExceptionUnwrappingCommand>(c);
                    var methodCmd = Assert.IsAssignableFrom <MethodInvokeCommand>(unwrapper.Command);

                    observedParameters.Add(methodCmd.ParameterInfo);
                }
            };

            var sut = new GuardClauseAssertion(new Fixture(), expectation);

            // Exercise system
            sut.Verify(ctor);
            // Verify outcome
            Assert.True(parameters.SequenceEqual(observedParameters));
            // Teardown
        }
        public void VerifyConstructorInvokesBehaviorExpectationWithCorrectParametersForReplacement(Type type, int constructorIndex)
        {
            // Fixture setup
            var ctor       = type.GetConstructors().ElementAt(constructorIndex);
            var parameters = ctor.GetParameters();

            var expectation = new DelegatingBehaviorExpectation
            {
                OnVerify = c =>
                {
                    var unwrapper = Assert.IsAssignableFrom <ReflectionExceptionUnwrappingCommand>(c);
                    var methodCmd = Assert.IsAssignableFrom <MethodInvokeCommand>(unwrapper.Command);

                    var replacement = Assert.IsAssignableFrom <IndexedReplacement <object> >(methodCmd.Expansion);
                    Assert.True(replacement.Source.Select(x => x.GetType()).SequenceEqual(parameters.Select(p => p.ParameterType)));
                }
            };

            var sut = new GuardClauseAssertion(new Fixture(), expectation);

            // Exercise system
            sut.Verify(ctor);
            // Verify outcome (done by mock)
            // Teardown
        }
        public void VerifyConstructorInvokesBehaviorExpectationWithCorrectReplacementIndices(Type type, int constructorIndex)
        {
            // Fixture setup
            var ctor       = type.GetConstructors().ElementAt(constructorIndex);
            var parameters = ctor.GetParameters();

            var observedIndices = new List <int>();
            var expectation     = new DelegatingBehaviorExpectation
            {
                OnVerify = c =>
                {
                    var unwrapper = Assert.IsAssignableFrom <ReflectionExceptionUnwrappingCommand>(c);
                    var methodCmd = Assert.IsAssignableFrom <MethodInvokeCommand>(unwrapper.Command);

                    var replacement = Assert.IsAssignableFrom <IndexedReplacement <object> >(methodCmd.Expansion);
                    observedIndices.Add(replacement.ReplacementIndex);
                }
            };

            var sut = new GuardClauseAssertion(new Fixture(), expectation);

            // Exercise system
            sut.Verify(ctor);
            // Verify outcome
            var expectedIndices = Enumerable.Range(0, parameters.Length);

            Assert.True(expectedIndices.SequenceEqual(observedIndices));
            // Teardown
        }
        public void VerifyMethodInvokesBehaviorExpectationWithCorrectMethod(Type ownerType, int methodIndex)
        {
            // Fixture setup
            var method     = ownerType.GetMethods().ElementAt(methodIndex);
            var parameters = method.GetParameters();

            var expectation = new DelegatingBehaviorExpectation
            {
                OnVerify = c =>
                {
                    var unwrapper = Assert.IsAssignableFrom <ReflectionExceptionUnwrappingCommand>(c);
                    var methodCmd = Assert.IsAssignableFrom <MethodInvokeCommand>(unwrapper.Command);

                    var instanceMethod = Assert.IsAssignableFrom <InstanceMethod>(methodCmd.Method);
                    Assert.Equal(method, instanceMethod.Method);
                    Assert.IsAssignableFrom(ownerType, instanceMethod.Owner);
                    Assert.True(parameters.SequenceEqual(instanceMethod.Parameters));
                }
            };

            var sut = new GuardClauseAssertion(new Fixture(), expectation);

            // Exercise system
            sut.Verify(method);
            // Verify outcome (done by mock)
            // Teardown
        }
        public void VerifyPropertyCorrectlyInvokesBehaviorExpectation()
        {
            // Fixture setup
            var fixture = new Fixture();
            var owner   = fixture.Freeze <PropertyHolder <Version> >(c => c.OmitAutoProperties());
            var value   = fixture.Freeze <Version>();

            var property = owner.GetType().GetProperty("Property");

            var mockVerified = false;
            var expectation  = new DelegatingBehaviorExpectation
            {
                OnVerify = c =>
                {
                    var unwrapper = Assert.IsAssignableFrom <ReflectionExceptionUnwrappingCommand>(c);
                    var setterCmd = Assert.IsAssignableFrom <PropertySetCommand>(unwrapper.Command);
                    mockVerified = setterCmd.PropertyInfo.Equals(property) &&
                                   setterCmd.Owner.Equals(owner);
                }
            };
            var sut = new GuardClauseAssertion(fixture, expectation);

            // Exercise system
            sut.Verify(property);
            // Verify outcome
            Assert.True(mockVerified, "Mock verified.");
            // Teardown
        }
        public void BehaviorExpectationIsCorrectFromGreedyConstructor()
        {
            // Fixture setup
            var dummyComposer             = new Fixture();
            IBehaviorExpectation expected = new DelegatingBehaviorExpectation();
            var sut = new GuardClauseAssertion(dummyComposer, expected);
            // Exercise system
            IBehaviorExpectation result = sut.BehaviorExpectation;

            // Verify outcome
            Assert.Equal(expected, result);
            // Teardown
        }
        public void ComposerIsCorrectFromGreedyConstructor()
        {
            // Fixture setup
            ISpecimenBuilder expectedBuilder = new Fixture();
            var dummyExpectation             = new DelegatingBehaviorExpectation();
            var sut = new GuardClauseAssertion(expectedBuilder, dummyExpectation);
            // Exercise system
            ISpecimenBuilder result = sut.Builder;

            // Verify outcome
            Assert.Equal(expectedBuilder, result);
            // Teardown
        }
        public void VerifyMethodIgnoresEquals(Type type, Type argumentType)
        {
            // Fixture setup
            var method = type.GetMethod("Equals", new[] { argumentType });

            var invoked     = false;
            var expectation = new DelegatingBehaviorExpectation {
                OnVerify = c => invoked = true
            };

            var sut = new GuardClauseAssertion(new Fixture(), expectation);

            // Exercise system
            sut.Verify(method);
            // Verify outcome
            Assert.False(invoked);
            // Teardown
        }