Пример #1
0
        public void CombineExplicitPropertyWithAutoProperties()
        {
            // Arrange
            var expectedText = "Fnaah";

            var specifiedCommand = new BindingCommand <DoublePropertyHolder <string, int>, string>(ph => ph.Property1, expectedText);
            var reservedProperty = new InverseRequestSpecification(specifiedCommand);

            var customizedBuilder = new Postprocessor(
                new Postprocessor(
                    new MethodInvoker(new ModestConstructorQuery()),
                    specifiedCommand),
                new AutoPropertiesCommand(reservedProperty),
                new AnyTypeSpecification());

            var builder = new CompositeSpecimenBuilder(
                customizedBuilder,
                Scenario.CreateAutoPropertyBuilder());
            var container = new SpecimenContext(builder);
            // Act
            var result = container.Resolve(typeof(DoublePropertyHolder <string, int>));
            // Assert
            var actual = Assert.IsAssignableFrom <DoublePropertyHolder <string, int> >(result);

            Assert.Equal(expectedText, actual.Property1);
            Assert.Equal(1, actual.Property2);
        }
        public void SutIsRequestSpecification()
        {
            // Arrange
            var dummySpec = new DelegatingRequestSpecification();
            // Act
            var sut = new InverseRequestSpecification(dummySpec);

            // Assert
            Assert.IsAssignableFrom <IRequestSpecification>(sut);
        }
        public void SutIsRequestSpecification()
        {
            // Fixture setup
            var dummySpec = new DelegatingRequestSpecification();
            // Exercise system
            var sut = new InverseRequestSpecification(dummySpec);

            // Verify outcome
            Assert.IsAssignableFrom <IRequestSpecification>(sut);
            // Teardown
        }
        public void SpecificationIsCorrectly()
        {
            // Arrange
            var expectedSpec = new DelegatingRequestSpecification();
            var sut          = new InverseRequestSpecification(expectedSpec);
            // Act
            IRequestSpecification result = sut.Specification;

            // Assert
            Assert.Equal(expectedSpec, result);
        }
        public void SpecificationIsCorrectly()
        {
            // Fixture setup
            var expectedSpec = new DelegatingRequestSpecification();
            var sut          = new InverseRequestSpecification(expectedSpec);
            // Exercise system
            IRequestSpecification result = sut.Specification;

            // Verify outcome
            Assert.Equal(expectedSpec, result);
            // Teardown
        }
        public void IsSatisfiedByReturnsCorrectResult(bool decoratedResult)
        {
            // Arrange
            var spec = new DelegatingRequestSpecification {
                OnIsSatisfiedBy = r => decoratedResult
            };
            var sut = new InverseRequestSpecification(spec);
            // Act
            var dummyRequest = new object();
            var result       = sut.IsSatisfiedBy(dummyRequest);

            // Assert
            Assert.Equal(!decoratedResult, result);
        }
        public void IsSatisfiedByInvokesDecoratedSpecWithCorrectRequest()
        {
            // Arrange
            var expectedRequest = new object();
            var verified        = false;
            var mock            = new DelegatingRequestSpecification {
                OnIsSatisfiedBy = r => verified = expectedRequest == r
            };
            var sut = new InverseRequestSpecification(mock);

            // Act
            sut.IsSatisfiedBy(expectedRequest);
            // Assert
            Assert.True(verified, "Mock verified");
        }
        public void IsSatisfiedByReturnsCorrectResult(bool decoratedResult)
        {
            // Fixture setup
            var spec = new DelegatingRequestSpecification {
                OnIsSatisfiedBy = r => decoratedResult
            };
            var sut = new InverseRequestSpecification(spec);
            // Exercise system
            var dummyRequest = new object();
            var result       = sut.IsSatisfiedBy(dummyRequest);

            // Verify outcome
            Assert.Equal(!decoratedResult, result);
            // Teardown
        }
        public void IsSatisfiedByInvokesDecoratedSpecWithCorrectRequest()
        {
            // Fixture setup
            var expectedRequest = new object();
            var verified        = false;
            var mock            = new DelegatingRequestSpecification {
                OnIsSatisfiedBy = r => verified = expectedRequest == r
            };
            var sut = new InverseRequestSpecification(mock);

            // Exercise system
            sut.IsSatisfiedBy(expectedRequest);
            // Verify outcome
            Assert.True(verified, "Mock verified");
            // Teardown
        }
Пример #10
0
            /// <summary>
            /// Transforms the supplied builder into another.
            /// </summary>
            /// <param name="builder">The builder to transform.</param>
            /// <returns>
            /// A new <see cref="ISpecimenBuilder"/> created from <paramref name="builder"/>.
            /// </returns>
            public ISpecimenBuilder Transform(ISpecimenBuilder builder)
            {
                if (!this.enableAutoProperties)
                {
                    return(builder);
                }

                var defaultSpecIfPostprocessorsIsEmpty = new FalseRequestSpecification();
                var postprocessorSpecs = this.postprocessors.Cast <IRequestSpecification>().Concat(new[] { defaultSpecIfPostprocessorsIsEmpty });
                var reservedProperties = new OrRequestSpecification(postprocessorSpecs);
                var allowedProperties  = new InverseRequestSpecification(reservedProperties);

                return(new Postprocessor <T>(
                           builder,
                           new AutoPropertiesCommand <T>(allowedProperties).Execute,
                           this.inputFilter));
            }
Пример #11
0
        /// <summary>
        /// Adjusts the AutoProperties postprocessor and changes rule to avoid the specified member population.
        /// If AutoProperties node is missing, nothing is done.
        /// </summary>
        private static ISpecimenBuilderNode ExcludeMemberFromAutoProperties(MemberInfo member,
                                                                            ISpecimenBuilderNode graph)
        {
            var autoPropertiesNode = FindAutoPropertiesNode(graph);

            if (autoPropertiesNode == null)
            {
                return(graph);
            }

            var currentSpecification = ((AutoPropertiesCommand)autoPropertiesNode.Command).Specification;
            var newRule = new InverseRequestSpecification(
                new EqualRequestSpecification(
                    member,
                    new MemberInfoEqualityComparer()));

            // Try to make specification list flat if possible
            IRequestSpecification specification;

            if (currentSpecification is TrueRequestSpecification)
            {
                specification = newRule;
            }
            else if (currentSpecification is AndRequestSpecification andSpec)
            {
                specification = new AndRequestSpecification(andSpec.Specifications.Concat(new[] { newRule }));
            }
            else
            {
                specification = new AndRequestSpecification(currentSpecification, newRule);
            }

            return(graph.ReplaceNodes(
                       with: _ => new Postprocessor(
                           autoPropertiesNode.Builder,
                           new AutoPropertiesCommand(typeof(T), specification),
                           autoPropertiesNode.Specification),
                       when: autoPropertiesNode.Equals));
        }