コード例 #1
0
ファイル: Scenario.cs プロジェクト: nandhakumaran/AutoFixture
        public void CombineExplictPropertyWithAutoProperties()
        {
            // Fixture setup
            var expectedText = "Fnaah";

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

            var customizedBuilder = new Postprocessor<DoublePropertyHolder<string, int>>(
                new Postprocessor<DoublePropertyHolder<string, int>>(
                    new MethodInvoker(new ModestConstructorQuery()),
                    specifiedCommand),
                new AutoPropertiesCommand<DoublePropertyHolder<string, int>>(reservedProperty),
                new AnyTypeSpecification());

            var builder = new CompositeSpecimenBuilder(
                customizedBuilder,
                Scenario.CreateAutoPropertyBuilder());
            var container = new SpecimenContext(builder);
            // Exercise system
            var result = container.Resolve(typeof(DoublePropertyHolder<string, int>));
            // Verify outcome
            var actual = Assert.IsAssignableFrom<DoublePropertyHolder<string, int>>(result);
            Assert.Equal(expectedText, actual.Property1);
            Assert.Equal(1, actual.Property2);
            // Teardown
        }
コード例 #2
0
 public void SutIsNode()
 {
     // Fixture setup
     // Exercise system
     var sut = new CompositeSpecimenBuilder();
     // Verify outcome
     Assert.IsAssignableFrom<ISpecimenBuilderNode>(sut);
     // Teardown
 }
コード例 #3
0
 public void SutIsSequenceOfSpecimenBuilders()
 {
     // Fixture setup
     // Exercise system
     var sut = new CompositeSpecimenBuilder();
     // Verify outcome
     Assert.IsAssignableFrom<IEnumerable<ISpecimenBuilder>>(sut);
     // Teardown
 }
コード例 #4
0
 public void SutIsSpecimenBuilder()
 {
     // Fixture setup
     // Exercise system
     var sut = new CompositeSpecimenBuilder();
     // Verify outcome
     Assert.IsInstanceOfType(sut, typeof(ISpecimenBuilder));
     // Teardown
 }
コード例 #5
0
 public void SutIsComposer()
 {
     // Fixture setup
     var dummyNode = new CompositeSpecimenBuilder();
     // Exercise system
     var sut = new CompositeNodeComposer<object>(dummyNode);
     // Verify outcome
     Assert.IsAssignableFrom<ICustomizationComposer<object>>(sut);
     // Teardown
 }
コード例 #6
0
 public void BuildersWillNotBeNullWhenSutIsCreatedWithDefaultConstructor()
 {
     // Fixture setup
     var sut = new CompositeSpecimenBuilder();
     // Exercise system
     IEnumerable<ISpecimenBuilder> result = sut.Builders;
     // Verify outcome
     Assert.NotNull(result);
     // Teardown
 }
コード例 #7
0
 public void SutIsEventArgs()
 {
     // Fixture setup
     var dummyNode = new CompositeSpecimenBuilder();
     // Exercise system
     var sut = new SpecimenBuilderNodeEventArgs(dummyNode);
     // Verify outcome
     Assert.IsAssignableFrom<EventArgs>(sut);
     // Teardown
 }
コード例 #8
0
 public void GraphIsCorrect()
 {
     // Fixture setup
     var expected = new CompositeSpecimenBuilder();
     var sut = new SpecimenBuilderNodeEventArgs(expected);
     // Exercise system
     ISpecimenBuilderNode actual = sut.Graph;
     // Verify outcome
     Assert.Equal(expected, actual);
     // Teardown
 }
コード例 #9
0
        public void BuildersWillNotBeNullWhenSutIsCreatedWithDefaultConstructor()
        {
            // Fixture setup
            var sut = new CompositeSpecimenBuilder();
            // Exercise system
#pragma warning disable 618
            IList<ISpecimenBuilder> result = sut.Builders;
#pragma warning restore 618
            // Verify outcome
            Assert.NotNull(result);
            // Teardown
        }
コード例 #10
0
 public void ComposeSingleNodeReturnsCorrectResult()
 {            
     // Fixture setup
     var dummyNode = new CompositeSpecimenBuilder();
     var sut = new CompositeNodeComposer<uint>(dummyNode);
     ISpecimenBuilderNode expected = new CompositeSpecimenBuilder();
     // Exercise system
     var actual = sut.Compose(new[] { expected });
     // Verify outcome
     var c =
         Assert.IsAssignableFrom<CompositeNodeComposer<uint>>(actual);
     Assert.Equal(expected, c.Node);
     // Teardown
 }
コード例 #11
0
ファイル: Scenario.cs プロジェクト: nandhakumaran/AutoFixture
 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).CreateAnonymous<DoublePropertyHolder<int, int>>();
     // Verify outcome
     Assert.Equal(1, result.Property1);
     Assert.Equal(2, result.Property2);
     // Teardown
 }
コード例 #12
0
 public void BuildersWillMatchParamsArray()
 {
     // Fixture setup
     var expectedBuilders = new ISpecimenBuilder[]
     {
         new DelegatingSpecimenBuilder(),
         new DelegatingSpecimenBuilder(),
         new DelegatingSpecimenBuilder()
     };
     var sut = new CompositeSpecimenBuilder(expectedBuilders[0], expectedBuilders[1], expectedBuilders[2]);
     // Exercise system
     var result = sut.Builders;
     // Verify outcome
     Assert.True(expectedBuilders.SequenceEqual(result), "Builders");
     // Teardown
 }
コード例 #13
0
 public void BuildersWillMatchListParameter()
 {
     // Fixture setup
     var expectedBuilders = new ISpecimenBuilder[]
     {
         new DelegatingSpecimenBuilder(),
         new DelegatingSpecimenBuilder(),
         new DelegatingSpecimenBuilder()
     }.AsEnumerable();
     var sut = new CompositeSpecimenBuilder(expectedBuilders);
     // Exercise system
     var result = sut.Builders;
     // Verify outcome
     Assert.True(expectedBuilders.SequenceEqual(result), "Builders");
     // Teardown
 }
コード例 #14
0
 public void ComposeReturnsCorrectResult()
 {
     // Fixture setup
     var dummyNode = new CompositeSpecimenBuilder();
     var sut = new CompositeNodeComposer<uint>(dummyNode);
     // Exercise system
     var expectedBuilders = new[]
     {
         new DelegatingSpecimenBuilder(),
         new DelegatingSpecimenBuilder(),
         new DelegatingSpecimenBuilder()
     };
     var actual = sut.Compose(expectedBuilders);
     // Verify outcome
     var c =
         Assert.IsAssignableFrom<CompositeNodeComposer<uint>>(actual);
     var composite = 
         Assert.IsAssignableFrom<CompositeSpecimenBuilder>(c.Node);
     Assert.True(expectedBuilders.SequenceEqual(composite));
     // Teardown
 }
コード例 #15
0
ファイル: Scenario.cs プロジェクト: nandhakumaran/AutoFixture
 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).CreateAnonymous<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
 }
コード例 #16
0
        /// <summary>
        /// Customizes the specified fixture by adding the <see cref="Type"/> specific numeric sequence generators.
        /// </summary>
        /// <param name="fixture">The fixture to customize.</param>
        public void Customize(IFixture fixture)
        {
            if (fixture == null)
            {
                throw new ArgumentNullException("fixture");
            }

            var numericBuilders = new CompositeSpecimenBuilder(new ISpecimenBuilder[]
            {
                new ByteSequenceGenerator(),
                new DecimalSequenceGenerator(),
                new DoubleSequenceGenerator(),
                new Int16SequenceGenerator(),
                new Int32SequenceGenerator(),
                new Int64SequenceGenerator(),
                new SByteSequenceGenerator(),
                new SingleSequenceGenerator(),
                new UInt16SequenceGenerator(),
                new UInt32SequenceGenerator(),
                new UInt64SequenceGenerator()
            });

            fixture.Customizations.Add(numericBuilders);
        }
コード例 #17
0
ファイル: Scenario.cs プロジェクト: nandhakumaran/AutoFixture
 public void CreateDoubleMixedParameterizedTypeWithNumberBasedStringGenerator()
 {
     // Fixture setup
     var intGenerator = new Int32SequenceGenerator();
     var builder = new CompositeSpecimenBuilder(
         intGenerator,
         new StringGenerator(() => intGenerator.CreateAnonymous()),
         new Int64SequenceGenerator(),
         new DecimalSequenceGenerator(),
         new BooleanSwitch(),
         new GuidGenerator(),
         new MethodInvoker(new ModestConstructorQuery()),
         new ParameterRequestRelay(),
         new StringSeedRelay(),
         new SeedIgnoringRelay());
     var container = new SpecimenContext(builder);
     // Exercise system
     var result = (TripleParameterType<int, string, int>)container.Resolve(typeof(TripleParameterType<int, string, int>));
     // Verify outcome
     Assert.Equal(1, result.Parameter1);
     Assert.Equal("parameter22", result.Parameter2);
     Assert.Equal(3, result.Parameter3);
     // Teardown
 }
コード例 #18
0
ファイル: Scenario.cs プロジェクト: nandhakumaran/AutoFixture
        public void CreateAndAddProperyValues()
        {
            // Fixture setup
            var ctorInvoker = new MethodInvoker(new ModestConstructorQuery());
            var strCmd = new BindingCommand<DoublePropertyHolder<string, int>, string>(ph => ph.Property1);
            var intCmd = new BindingCommand<DoublePropertyHolder<string, int>, int>(ph => ph.Property2);
            var strPostprocessor = new Postprocessor<DoublePropertyHolder<string, int>>(ctorInvoker, strCmd);
            var intPostprocessor = new Postprocessor<DoublePropertyHolder<string, int>>(strPostprocessor, intCmd);

            var builder = new CompositeSpecimenBuilder(
                new FilteringSpecimenBuilder(intPostprocessor, new ExactTypeSpecification(typeof(DoublePropertyHolder<string, int>))),
                Scenario.CreateAutoPropertyBuilder());
            var container = new SpecimenContext(builder);
            // Exercise system
            var result = container.Resolve(typeof(DoublePropertyHolder<string, int>));
            // Verify outcome
            var actual = Assert.IsAssignableFrom<DoublePropertyHolder<string, int>>(result);
            Assert.False(string.IsNullOrEmpty(actual.Property1), "Property1");
            Assert.Equal(1, actual.Property2);
            // Teardown
        }
コード例 #19
0
ファイル: Scenario.cs プロジェクト: nandhakumaran/AutoFixture
 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).CreateAnonymous<PropertyHolder<int>>();
     // Verify outcome
     Assert.Equal(expectedValue, result.Property);
     // Teardown
 }
コード例 #20
0
ファイル: Scenario.cs プロジェクト: nandhakumaran/AutoFixture
 public void ComposeWithoutCorrectlyCreatesSpecimen()
 {
     // Fixture setup
     var builder = new CompositeSpecimenBuilder(
         SpecimenBuilderNodeFactory.CreateComposer<DoubleFieldHolder<string, int>>().WithAutoProperties().Without(x => x.Field1),
         Scenario.CreateCoreBuilder());
     // Exercise system
     var result = new SpecimenContext(builder).CreateAnonymous<DoubleFieldHolder<string, int>>();
     // Verify outcome
     Assert.Null(result.Field1);
     Assert.Equal(1, result.Field2);
     // Teardown
 }
コード例 #21
0
        public void CreateWillCorrectlyRaiseSpecimenRequestedInCompositeRequest()
        {
            // Fixture setup
            object requestedObject = "The request";
            object subRequest = "Some sub request";

            var spy = new List<RequestTraceEventArgs>();
            var builder2 = new DelegatingSpecimenBuilder { OnCreate = (r, c) => r == requestedObject ? c.Resolve(subRequest) : new NoSpecimen() };
            var builder3 = new DelegatingSpecimenBuilder { OnCreate = (r, c) => r == subRequest ? new object() : new NoSpecimen() };
            var compBuilder = new CompositeSpecimenBuilder(builder2, builder3);

            var sut = new DelegatingTracingBuilder(compBuilder);
            sut.SpecimenRequested += (sender, e) => spy.Add(e);

            var container = new SpecimenContext(sut);
            // Exercise system
            sut.Create(requestedObject, container);
            // Verify outcome
            Assert.Equal(2, spy.Count);
            Assert.Equal(subRequest, spy[1].Request);
            Assert.Equal(2, spy[1].Depth);
            // Teardown
        }
コード例 #22
0
        public void CreateWillTrackCreatedSpecimensComposite()
        {
            // Fixture setup
            object requestedObject = "The request";
            object subRequest = "Some sub request";
            object createdSpecimen = Guid.NewGuid();
            var spy = new List<object>();
            var builder2 = new DelegatingSpecimenBuilder { OnCreate = (r, c) => r == requestedObject ? c.Resolve(subRequest) : new NoSpecimen() };
            var builder3 = new DelegatingSpecimenBuilder { OnCreate = (r, c) => r == subRequest ? createdSpecimen : new NoSpecimen() };
            var compBuilder = new CompositeSpecimenBuilder(builder2, builder3);

            var sut = new DelegatingTracingBuilder(compBuilder);
            sut.SpecimenCreated += (sender, e) => spy.Add(e.Specimen);
            var container = new SpecimenContext(sut);
            // Exercise system
            sut.Create(requestedObject, container);

            // Verify outcome
            Assert.Equal(2, spy.Count);
            Assert.Equal(createdSpecimen, spy[0]);
            Assert.Equal(createdSpecimen, spy[1]);

            // Teardown
        }
コード例 #23
0
 public void LegacyComposeReturnsCorrectResult()
 {
     // Fixture setup
     var dummyNode = new CompositeSpecimenBuilder();
     var sut = new CompositeNodeComposer<UTF8Encoding>(dummyNode);
     // Exercise system
     var actual = sut.Compose();
     // Verify outcome
     Assert.Equal(sut, actual);
     // Teardown
 }
コード例 #24
0
 public void WithExplicitValueReturnsCorrectResult(string value)
 {
     // Fixture setup
     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);
     // Exercise system
     var actual = sut.With(x => x.Property, value);
     // Verify outcome
     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()));
     // Teardown
 }
コード例 #25
0
 public void OmitAutoPropertiesAfterAddingAutoPropertiesReturnsCorrectResult()
 {
     // Fixture setup
     var node = new CompositeSpecimenBuilder(
         new DelegatingSpecimenBuilder(),
         SpecimenBuilderNodeFactory.CreateComposer<Version>(),
         SpecimenBuilderNodeFactory.CreateComposer<string>(),
         SpecimenBuilderNodeFactory.CreateComposer<Version>(),
         new DelegatingSpecimenBuilder());
     var sut = new CompositeNodeComposer<Version>(node);
     // Exercise system
     var actual = sut.WithAutoProperties().OmitAutoProperties();
     // Verify outcome
     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()));
     // Teardown
 }
コード例 #26
0
ファイル: Scenario.cs プロジェクト: nandhakumaran/AutoFixture
 public void CustomDoSetsCorrectProperty()
 {
     // Fixture setup
     var builder = new CompositeSpecimenBuilder(
         SpecimenBuilderNodeFactory.CreateComposer<PropertyHolder<decimal>>().OmitAutoProperties().Do(x => x.SetProperty(6789)),
         Scenario.CreateCoreBuilder());
     // Exercise system
     var result = new SpecimenContext(builder).CreateAnonymous<SingleParameterType<PropertyHolder<decimal>>>();
     // Verify outcome
     Assert.Equal(6789, result.Parameter.Property);
     // Teardown
 }
コード例 #27
0
ファイル: Scenario.cs プロジェクト: nandhakumaran/AutoFixture
 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).CreateAnonymous<PropertyHolder<float>>();
     // Verify outcome
     Assert.Equal(instance, result);
     Assert.Equal(89, result.Property);
     // Teardown
 }
コード例 #28
0
        /// <summary>
        /// Customizes the fixture by freezing the value of <see cref="TargetType"/>.
        /// </summary>
        /// <param name="fixture">The fixture to customize.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="fixture"/> is null.
        /// </exception>
        public void Customize(IFixture fixture)
        {
            if (fixture == null)
            {
                throw new ArgumentNullException(nameof(fixture));
            }

            var specimen = fixture.Create(
                    this.targetType);
            var fixedBuilder = new FixedBuilder(specimen);

            var types = new[]
                {
                    this.targetType,
                    this.registeredType 
                };

            var builder = new CompositeSpecimenBuilder(
                from t in types
                select SpecimenBuilderNodeFactory.CreateTypedNode(
                    t, fixedBuilder) as ISpecimenBuilder);

            fixture.Customizations.Insert(0, builder);
        }
コード例 #29
0
 public void WithoutReturnsCorrectResult()
 {
     // Fixture setup
     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);
     // Exercise system
     var actual = sut.Without(x => x.Field);
     // Verify outcome
     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()));
     // Teardown
 }
コード例 #30
0
 public void DoReturnsCorrectResult()
 {
     // Fixture setup
     var node = new CompositeSpecimenBuilder(
         new DelegatingSpecimenBuilder(),
         SpecimenBuilderNodeFactory.CreateComposer<AppDomainSetup>(),
         SpecimenBuilderNodeFactory.CreateComposer<bool>(),
         SpecimenBuilderNodeFactory.CreateComposer<AppDomainSetup>(),
         new DelegatingSpecimenBuilder());
     var sut = new CompositeNodeComposer<AppDomainSetup>(node);
     Action<AppDomainSetup> a =
         ads => ads.DisallowApplicationBaseProbing = false;
     // Exercise system
     var actual = sut.Do(a);
     // Verify outcome
     var expected = new CompositeNodeComposer<AppDomainSetup>(
         new CompositeSpecimenBuilder(
             new DelegatingSpecimenBuilder(),
             (ISpecimenBuilder)SpecimenBuilderNodeFactory.CreateComposer<AppDomainSetup>().Do(a),
             SpecimenBuilderNodeFactory.CreateComposer<bool>(),
             (ISpecimenBuilder)SpecimenBuilderNodeFactory.CreateComposer<AppDomainSetup>().Do(a),
             new DelegatingSpecimenBuilder()));
     var n = Assert.IsAssignableFrom<ISpecimenBuilderNode>(actual);
     Assert.True(expected.GraphEquals(n, new NodeComparer()));
     // Teardown
 }