Esempio n. 1
0
        public void ComposeWithValueReturnsCorrectResult()
        {
            // Arrange
            var expectedValue = 9;
            var customBuilder = SpecimenBuilderNodeFactory.CreateComposer <PropertyHolder <int> >()
                                .With(x => x.Property, expectedValue);
            var builder = new CompositeSpecimenBuilder(
                customBuilder,
                Scenario.CreateCoreBuilder());
            // Act
            var result = new SpecimenContext(builder).Create <PropertyHolder <int> >();

            // Assert
            Assert.Equal(expectedValue, result.Property);
        }
Esempio n. 2
0
        public void CustomizeFromFactoryCorrectlyResolvesSpecimen()
        {
            // Arrange
            var instance = new PropertyHolder <float> {
                Property = 89
            };
            var builder = new CompositeSpecimenBuilder(
                SpecimenBuilderNodeFactory.CreateComposer <PropertyHolder <float> >().FromFactory(() => instance).OmitAutoProperties(),
                Scenario.CreateCoreBuilder());
            // Act
            var result = new SpecimenContext(builder).Create <PropertyHolder <float> >();

            // Assert
            Assert.Equal(instance, result);
            Assert.Equal(89, result.Property);
        }
        public void FromQuadrupleArgFuncReturnsCorrectResult()
        {
            // Arrange
            var sut = SpecimenBuilderNodeFactory.CreateComposer <Version>();
            Func <int, int, int, int, Version> f = (mj, mn, b, r) => new Version(mj, mn, b, r);
            // Act
            var actual = sut.FromFactory(f);
            // Assert
            var factory  = new SpecimenFactory <int, int, int, int, Version>(f);
            var expected = new NodeComposer <Version>(
                SpecimenBuilderNodeFactory.CreateTypedNode(typeof(Version), factory));

            var n = Assert.IsAssignableFrom <ISpecimenBuilderNode>(actual);

            Assert.True(expected.GraphEquals(n, new NodeComparer()));
        }
        public void FromTripleArgFuncReturnsCorrectResult()
        {
            // Arrange
            var sut = SpecimenBuilderNodeFactory.CreateComposer <decimal>();
            Func <int, Guid, Version, decimal> f = (i, g, v) => i;
            // Act
            var actual = sut.FromFactory(f);
            // Assert
            var factory  = new SpecimenFactory <int, Guid, Version, decimal>(f);
            var expected = new NodeComposer <decimal>(
                SpecimenBuilderNodeFactory.CreateTypedNode(typeof(decimal), factory));

            var n = Assert.IsAssignableFrom <ISpecimenBuilderNode>(actual);

            Assert.True(expected.GraphEquals(n, new NodeComparer()));
        }
Esempio n. 5
0
        public void FromSpecimenBuilderFactoryReturnsCorrectResult()
        {
            // Fixture setup
            var sut     = SpecimenBuilderNodeFactory.CreateComposer <Guid>();
            var builder = new DelegatingSpecimenBuilder();
            // Exercise system
            var actual = sut.FromFactory(builder);
            // Verify outcome
            var expected = new NodeComposer <Guid>(
                SpecimenBuilderNodeFactory.CreateTypedNode(typeof(Guid), builder));

            var n = Assert.IsAssignableFrom <ISpecimenBuilderNode>(actual);

            Assert.True(expected.GraphEquals(n, new NodeComparer()));
            // Teardown
        }
Esempio n. 6
0
        public void CustomizeAndComposeComplexType()
        {
            // Fixture setup
            // Exercise system
            var result = new CompositeNodeComposer <DoublePropertyHolder <int, decimal> >(
                new CompositeSpecimenBuilder(
                    SpecimenBuilderNodeFactory.CreateComposer <DoublePropertyHolder <int, decimal> >(),
                    Scenario.CreateAutoPropertyBuilder()
                    )
                ).With(x => x.Property2, 8m).WithAutoProperties().Create();

            // Verify outcome
            Assert.Equal(1, result.Property1);
            Assert.Equal(8, result.Property2);
            // Teardown
        }
Esempio n. 7
0
        public void ComposeWithAutoProperties()
        {
            // Fixture setup
            var customBuilder = SpecimenBuilderNodeFactory.CreateComposer <DoublePropertyHolder <int, int> >()
                                .WithAutoProperties();
            var builder = new CompositeSpecimenBuilder(
                customBuilder,
                Scenario.CreateCoreBuilder());
            // Exercise system
            var result = new SpecimenContext(builder).Create <DoublePropertyHolder <int, int> >();

            // Verify outcome
            Assert.Equal(1, result.Property1);
            Assert.Equal(2, result.Property2);
            // Teardown
        }
Esempio n. 8
0
        public void ComposeWithAutoPropertiesAndExplicitProperty()
        {
            // Arrange
            var customBuilder = SpecimenBuilderNodeFactory.CreateComposer <DoublePropertyHolder <int, int> >()
                                .WithAutoProperties()
                                .With(x => x.Property1, 8);
            var builder = new CompositeSpecimenBuilder(
                customBuilder,
                Scenario.CreateCoreBuilder());
            // Act
            var result = new SpecimenContext(builder).Create <DoublePropertyHolder <int, int> >();

            // Assert
            Assert.Equal(8, result.Property1);
            Assert.Equal(1, result.Property2);
        }
        public void CreateComposerReturnsCorrectResult()
        {
            // Fixture setup
            // Exercise system
            NodeComposer <int> actual =
                SpecimenBuilderNodeFactory.CreateComposer <int>();
            // Verify outcome
            var expected = new NodeComposer <int>(
                SpecimenBuilderNodeFactory.CreateTypedNode(
                    typeof(int),
                    new MethodInvoker(
                        new ModestConstructorQuery())));

            Assert.True(expected.GraphEquals(actual, new NodeComparer()));
            // Teardown
        }
Esempio n. 10
0
        public void ComposeWithValueReturnsCorrectResult()
        {
            // Fixture setup
            var expectedValue = 9;
            var customBuilder = SpecimenBuilderNodeFactory.CreateComposer <PropertyHolder <int> >()
                                .With(x => x.Property, expectedValue);
            var builder = new CompositeSpecimenBuilder(
                customBuilder,
                Scenario.CreateCoreBuilder());
            // Exercise system
            var result = new SpecimenContext(builder).Create <PropertyHolder <int> >();

            // Verify outcome
            Assert.Equal(expectedValue, result.Property);
            // Teardown
        }
        public void FromSingleArgFuncReturnsCorrectResult()
        {
            // Arrange
            var sut             = SpecimenBuilderNodeFactory.CreateComposer <float>();
            Func <int, float> f = i => i;
            // Act
            var actual = sut.FromFactory(f);
            // Assert
            var factory  = new SpecimenFactory <int, float>(f);
            var expected = new NodeComposer <float>(
                SpecimenBuilderNodeFactory.CreateTypedNode(typeof(float), factory));

            var n = Assert.IsAssignableFrom <ISpecimenBuilderNode>(actual);

            Assert.True(expected.GraphEquals(n, new NodeComparer()));
        }
        public void FromSeedReturnsCorrectResult()
        {
            // Arrange
            var sut = SpecimenBuilderNodeFactory.CreateComposer <decimal>();
            Func <decimal, decimal> f = d => d;
            // Act
            var actual = sut.FromSeed(f);
            // Assert
            var factory  = new SeededFactory <decimal>(f);
            var expected = new NodeComposer <decimal>(
                SpecimenBuilderNodeFactory.CreateTypedNode(typeof(decimal), factory));

            var n = Assert.IsAssignableFrom <ISpecimenBuilderNode>(actual);

            Assert.True(expected.GraphEquals(n, new NodeComparer()));
        }
Esempio n. 13
0
        public void ComposeWithValueFactoryReturnsCorrectResult()
        {
            // Arrange
            var values        = new Queue <string>(new[] { "value1", "value2" });
            var customBuilder = SpecimenBuilderNodeFactory.CreateComposer <PropertyHolder <string> >()
                                .With(x => x.Property, () => values.Dequeue());
            var builder = new CompositeSpecimenBuilder(
                customBuilder,
                Scenario.CreateCoreBuilder());
            // Act
            var result1 = new SpecimenContext(builder).Create <PropertyHolder <string> >();
            var result2 = new SpecimenContext(builder).Create <PropertyHolder <string> >();

            // Assert
            Assert.Equal("value1", result1.Property);
            Assert.Equal("value2", result2.Property);
        }
Esempio n. 14
0
        public void FromDoubleArgFuncReturnsCorrectResult()
        {
            // Fixture setup
            var sut = SpecimenBuilderNodeFactory.CreateComposer <string>();
            Func <int, Version, string> f = (i, _) => i.ToString();
            // Exercise system
            var actual = sut.FromFactory(f);
            // Verify outcome
            var factory  = new SpecimenFactory <int, Version, string>(f);
            var expected = new NodeComposer <string>(
                SpecimenBuilderNodeFactory.CreateTypedNode(typeof(string), factory));

            var n = Assert.IsAssignableFrom <ISpecimenBuilderNode>(actual);

            Assert.True(expected.GraphEquals(n, new NodeComparer()));
            // Teardown
        }
Esempio n. 15
0
        public void CustomizeFromFactoryCorrectlyResolvesSpecimen()
        {
            // Fixture setup
            var instance = new PropertyHolder <float> {
                Property = 89
            };
            var builder = new CompositeSpecimenBuilder(
                SpecimenBuilderNodeFactory.CreateComposer <PropertyHolder <float> >().FromFactory(() => instance).OmitAutoProperties(),
                Scenario.CreateCoreBuilder());
            // Exercise system
            var result = new SpecimenContext(builder).Create <PropertyHolder <float> >();

            // Verify outcome
            Assert.Equal(instance, result);
            Assert.Equal(89, result.Property);
            // Teardown
        }
Esempio n. 16
0
        public void FromSeedReturnsCorrectResult()
        {
            // Fixture setup
            var sut = SpecimenBuilderNodeFactory.CreateComposer <decimal>();
            Func <decimal, decimal> f = d => d;
            // Exercise system
            var actual = sut.FromSeed(f);
            // Verify outcome
            var factory  = new SeededFactory <decimal>(f);
            var expected = new NodeComposer <decimal>(
                SpecimenBuilderNodeFactory.CreateTypedNode(typeof(decimal), factory));

            var n = Assert.IsAssignableFrom <ISpecimenBuilderNode>(actual);

            Assert.True(expected.GraphEquals(n, new NodeComparer()));
            // Teardown
        }
        public void ComposeReturnsCorrectResult()
        {
            // Arrange
            var sut = SpecimenBuilderNodeFactory.CreateComposer <ConcreteType>();
            // Act
            var expectedBuilders = new[]
            {
                new DelegatingSpecimenBuilder(),
                new DelegatingSpecimenBuilder(),
                new DelegatingSpecimenBuilder()
            };
            var actual = sut.Compose(expectedBuilders);
            // Assert
            var nc        = Assert.IsAssignableFrom <NodeComposer <ConcreteType> >(actual);
            var composite = Assert.IsAssignableFrom <CompositeSpecimenBuilder>(nc.Builder);

            Assert.True(expectedBuilders.SequenceEqual(composite));
        }
Esempio n. 18
0
        public void ComposeReturnsCorrectResult()
        {
            // Fixture setup
            var sut = SpecimenBuilderNodeFactory.CreateComposer <GenericUriParser>();
            // Exercise system
            var expectedBuilders = new[]
            {
                new DelegatingSpecimenBuilder(),
                new DelegatingSpecimenBuilder(),
                new DelegatingSpecimenBuilder()
            };
            var actual = sut.Compose(expectedBuilders);
            // Verify outcome
            var nc        = Assert.IsAssignableFrom <NodeComposer <GenericUriParser> >(actual);
            var composite = Assert.IsAssignableFrom <CompositeSpecimenBuilder>(nc.Builder);

            Assert.True(expectedBuilders.SequenceEqual(composite));
            // Teardown
        }
Esempio n. 19
0
        public void ComposeWithSingleArgumentValueFactoryReturnsCorrectResult()
        {
            // Arrange
            var values        = new Queue <string>(new[] { "value1", "value2" });
            var customBuilder = SpecimenBuilderNodeFactory.CreateComposer <PropertyHolder <string> >()
                                .With(x => x.Property, (Queue <string> v) => v.Dequeue());
            var builder = new CompositeSpecimenBuilder(
                customBuilder,
                new FilteringSpecimenBuilder(
                    new FixedBuilder(values),
                    new ExactTypeSpecification(typeof(Queue <string>))),
                Scenario.CreateCoreBuilder());
            // Act
            var result1 = new SpecimenContext(builder).Create <PropertyHolder <string> >();
            var result2 = new SpecimenContext(builder).Create <PropertyHolder <string> >();

            // Assert
            Assert.Equal("value1", result1.Property);
            Assert.Equal("value2", result2.Property);
        }
Esempio n. 20
0
        public void WithExplicitValueReturnsCorrectResult(string value)
        {
            // Fixture setup
            var sut = SpecimenBuilderNodeFactory.CreateComposer <PropertyHolder <string> >();
            var pi  = typeof(PropertyHolder <string>).GetProperty("Property");
            // Exercise system
            var actual = sut.With(x => x.Property, value);
            // Verify outcome
            var expected = new NodeComposer <PropertyHolder <string> >(
                new FilteringSpecimenBuilder(
                    new CompositeSpecimenBuilder(
                        new Postprocessor(
                            new Postprocessor(
                                new NoSpecimenOutputGuard(
                                    new MethodInvoker(
                                        new ModestConstructorQuery()),
                                    new InverseRequestSpecification(
                                        new SeedRequestSpecification(
                                            typeof(PropertyHolder <string>)))),
                                new AutoPropertiesCommand(
                                    typeof(PropertyHolder <string>),
                                    new InverseRequestSpecification(
                                        new EqualRequestSpecification(
                                            pi,
                                            new MemberInfoEqualityComparer()))),
                                new FalseRequestSpecification()
                                ),
                            new BindingCommand <PropertyHolder <string>, string>(x => x.Property, value),
                            new OrRequestSpecification(
                                new SeedRequestSpecification(typeof(PropertyHolder <string>)),
                                new ExactTypeSpecification(typeof(PropertyHolder <string>)))),
                        new SeedIgnoringRelay()),
                    new OrRequestSpecification(
                        new SeedRequestSpecification(typeof(PropertyHolder <string>)),
                        new ExactTypeSpecification(typeof(PropertyHolder <string>)))));

            var n = Assert.IsAssignableFrom <ISpecimenBuilderNode>(actual);

            Assert.True(expected.GraphEquals(n, new NodeComparer()));
            // Teardown
        }
Esempio n. 21
0
        public void WithExplicitSingleArgValueFactoryReturnsCorrectResult()
        {
            // Arrange
            var sut = SpecimenBuilderNodeFactory.CreateComposer <PropertyHolder <string> >();
            var pi  = typeof(PropertyHolder <string>).GetProperty("Property");
            Func <string, string> valueFactory = v => v;
            // Act
            var actual = sut.With(x => x.Property, valueFactory);
            // Assert
            var expected = new NodeComposer <PropertyHolder <string> >(
                new FilteringSpecimenBuilder(
                    new CompositeSpecimenBuilder(
                        new Postprocessor(
                            new Postprocessor(
                                new NoSpecimenOutputGuard(
                                    new MethodInvoker(
                                        new ModestConstructorQuery()),
                                    new InverseRequestSpecification(
                                        new SeedRequestSpecification(
                                            typeof(PropertyHolder <string>)))),
                                new AutoPropertiesCommand(
                                    typeof(PropertyHolder <string>),
                                    new InverseRequestSpecification(
                                        new EqualRequestSpecification(
                                            pi,
                                            new MemberInfoEqualityComparer()))),
                                new FalseRequestSpecification()),
                            new BindingCommand <PropertyHolder <string>, string>(x => x.Property, ctx => valueFactory((string)ctx.Resolve(typeof(string)))),
                            new OrRequestSpecification(
                                new SeedRequestSpecification(typeof(PropertyHolder <string>)),
                                new ExactTypeSpecification(typeof(PropertyHolder <string>)))),
                        new SeedIgnoringRelay()),
                    new OrRequestSpecification(
                        new SeedRequestSpecification(typeof(PropertyHolder <string>)),
                        new ExactTypeSpecification(typeof(PropertyHolder <string>)))));

            var n = Assert.IsAssignableFrom <ISpecimenBuilderNode>(actual);

            Assert.True(expected.GraphEquals(n, new NodeComparer()));
        }
Esempio n. 22
0
        public void ComposeComplexObjectWithAutoPropertiesAndSomeCustomizations()
        {
            // Arrange
            var builder = new CompositeSpecimenBuilder(
                SpecimenBuilderNodeFactory.CreateComposer <DoublePropertyHolder <long, long> >()
                .With(x => x.Property2, 43)
                .WithAutoProperties(),
                SpecimenBuilderNodeFactory.CreateComposer <DoublePropertyHolder <int, string> >()
                .OmitAutoProperties()
                .With(x => x.Property1),
                SpecimenBuilderNodeFactory.CreateComposer <DoublePropertyHolder <DoublePropertyHolder <long, long>, DoublePropertyHolder <int, string> > >()
                .WithAutoProperties(),
                Scenario.CreateCoreBuilder());
            // Act
            var result = new SpecimenContext(builder).Create <DoublePropertyHolder <DoublePropertyHolder <long, long>, DoublePropertyHolder <int, string> > >();

            // Assert
            Assert.Equal(1, result.Property1.Property1);
            Assert.Equal(43, result.Property1.Property2);
            Assert.Equal(1, result.Property2.Property1);
            Assert.Null(result.Property2.Property2);
        }
Esempio n. 23
0
        public void ComposeComplexObjectWithAutoPropertiesAndSomeCustomizations()
        {
            // Fixture setup
            var builder = new CompositeSpecimenBuilder(
                SpecimenBuilderNodeFactory.CreateComposer <DoublePropertyHolder <long, long> >()
                .With(x => x.Property2, 43)
                .WithAutoProperties(),
                SpecimenBuilderNodeFactory.CreateComposer <DoublePropertyHolder <int, string> >()
                .OmitAutoProperties()
                .With(x => x.Property1),
                SpecimenBuilderNodeFactory.CreateComposer <DoublePropertyHolder <DoublePropertyHolder <long, long>, DoublePropertyHolder <int, string> > >()
                .WithAutoProperties(),
                Scenario.CreateCoreBuilder());
            // Exercise system
            var result = new SpecimenContext(builder).Create <DoublePropertyHolder <DoublePropertyHolder <long, long>, DoublePropertyHolder <int, string> > >();

            // Verify outcome
            Assert.Equal(1, result.Property1.Property1);
            Assert.Equal(43, result.Property1.Property2);
            Assert.Equal(1, result.Property2.Property1);
            Assert.Null(result.Property2.Property2);
            // Teardown
        }
        public void WithoutReturnsCorrectResult()
        {
            // Arrange
            var node = new CompositeSpecimenBuilder(
                new DelegatingSpecimenBuilder(),
                SpecimenBuilderNodeFactory.CreateComposer <FieldHolder <short> >(),
                SpecimenBuilderNodeFactory.CreateComposer <PropertyHolder <int> >(),
                SpecimenBuilderNodeFactory.CreateComposer <FieldHolder <short> >(),
                new DelegatingSpecimenBuilder());
            var sut = new CompositeNodeComposer <FieldHolder <short> >(node);
            // Act
            var actual = sut.Without(x => x.Field);
            // Assert
            var expected = new CompositeNodeComposer <FieldHolder <short> >(
                new CompositeSpecimenBuilder(
                    new DelegatingSpecimenBuilder(),
                    (ISpecimenBuilder)SpecimenBuilderNodeFactory.CreateComposer <FieldHolder <short> >().Without(x => x.Field),
                    SpecimenBuilderNodeFactory.CreateComposer <PropertyHolder <int> >(),
                    (ISpecimenBuilder)SpecimenBuilderNodeFactory.CreateComposer <FieldHolder <short> >().Without(x => x.Field),
                    new DelegatingSpecimenBuilder()));
            var n = Assert.IsAssignableFrom <ISpecimenBuilderNode>(actual);

            Assert.True(expected.GraphEquals(n, new NodeComparer()));
        }
        public void OmitAutoPropertiesAfterAddingAutoPropertiesReturnsCorrectResult()
        {
            // Arrange
            var node = new CompositeSpecimenBuilder(
                new DelegatingSpecimenBuilder(),
                SpecimenBuilderNodeFactory.CreateComposer <Version>(),
                SpecimenBuilderNodeFactory.CreateComposer <string>(),
                SpecimenBuilderNodeFactory.CreateComposer <Version>(),
                new DelegatingSpecimenBuilder());
            var sut = new CompositeNodeComposer <Version>(node);
            // Act
            var actual = sut.WithAutoProperties().OmitAutoProperties();
            // Assert
            var expected = new CompositeNodeComposer <Version>(
                new CompositeSpecimenBuilder(
                    new DelegatingSpecimenBuilder(),
                    (ISpecimenBuilder)SpecimenBuilderNodeFactory.CreateComposer <Version>().WithAutoProperties().OmitAutoProperties(),
                    SpecimenBuilderNodeFactory.CreateComposer <string>(),
                    (ISpecimenBuilder)SpecimenBuilderNodeFactory.CreateComposer <Version>().WithAutoProperties().OmitAutoProperties(),
                    new DelegatingSpecimenBuilder()));
            var n = Assert.IsAssignableFrom <ISpecimenBuilderNode>(actual);

            Assert.True(expected.GraphEquals(n, new NodeComparer()));
        }
        public void WithExplicitValueReturnsCorrectResult(string value)
        {
            // Arrange
            var node = new CompositeSpecimenBuilder(
                new DelegatingSpecimenBuilder(),
                SpecimenBuilderNodeFactory.CreateComposer <PropertyHolder <string> >(),
                SpecimenBuilderNodeFactory.CreateComposer <Version>(),
                SpecimenBuilderNodeFactory.CreateComposer <PropertyHolder <string> >(),
                new DelegatingSpecimenBuilder());
            var sut = new CompositeNodeComposer <PropertyHolder <string> >(node);
            // Act
            var actual = sut.With(x => x.Property, value);
            // Assert
            var expected = new CompositeNodeComposer <PropertyHolder <string> >(
                new CompositeSpecimenBuilder(
                    new DelegatingSpecimenBuilder(),
                    (ISpecimenBuilder)SpecimenBuilderNodeFactory.CreateComposer <PropertyHolder <string> >().With(x => x.Property, value),
                    SpecimenBuilderNodeFactory.CreateComposer <Version>(),
                    (ISpecimenBuilder)SpecimenBuilderNodeFactory.CreateComposer <PropertyHolder <string> >().With(x => x.Property, value),
                    new DelegatingSpecimenBuilder()));
            var n = Assert.IsAssignableFrom <ISpecimenBuilderNode>(actual);

            Assert.True(expected.GraphEquals(n, new NodeComparer()));
        }