当前位置: 首页>>代码示例>>C#>>正文


C# Filler.Fill方法代码示例

本文整理汇总了C#中Filler.Fill方法的典型用法代码示例。如果您正苦于以下问题:C# Filler.Fill方法的具体用法?C# Filler.Fill怎么用?C# Filler.Fill使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Filler的用法示例。


在下文中一共展示了Filler.Fill方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DependencyOrderingWorksWithSubclassesAsWellAsPrimitives

        public void DependencyOrderingWorksWithSubclassesAsWellAsPrimitives()
        {
            var rootObject = new Foo();
            var filler = new Filler();

            var generator = MockRepository.GenerateStub<IGenerateDummyData>();
            generator.Stub(g => g.Generate(Arg<GenerationContext>.Is.Anything)).Return("Chris");

            var dependentGenerator = MockRepository.GenerateStub<IGenerateDummyData>();
            dependentGenerator.Stub(g => g.Generate(Arg<GenerationContext>.Is.Anything))
                .Do(new GeneratorDelegate(context => string.Format("Hello {0}", context.RootAs<Foo>().Bar.Name)));

            filler.Configure<Goo>(config => config.For(goo => goo.Name).Use(dependentGenerator));
            filler.Configure<Bar>(config => config.For(goo => goo.Name).Use(generator));

            filler.Configure<Foo>(config =>
            {
                config.For(f => f.Goo).Order(2);
                config.For(f => f.Bar).Order(1);
            });

            filler.Fill(rootObject);

            Assert.That(rootObject.Goo.Name, Is.EqualTo("Hello Chris"));
        }
开发者ID:chrisjowen,项目名称:FillMe,代码行数:25,代码来源:FillingDataTests.cs

示例2: CollectionsGenerateDataXTimes

        public void CollectionsGenerateDataXTimes()
        {
            var rootObject = new Foo();
            var filler = new Filler();

            var generator = MockRepository.GenerateStub<IGenerateDummyData>();
            generator.Stub(g => g.Generate(Arg<GenerationContext>.Is.Anything)).Return("Chris");

            filler.Configure<Bar>(config => config.For(goo => goo.Name).Use(generator));
            filler.Configure<Foo>(config => config.For(f => f.Bars).Times(10));

            filler.Fill(rootObject);
            Assert.That(rootObject.Bars.Count, Is.EqualTo(10));
            Assert.That(rootObject.Bars.First().Name, Is.EqualTo("Chris"));
        }
开发者ID:chrisjowen,项目名称:FillMe,代码行数:15,代码来源:FillingDataTests.cs

示例3: TestFillPerson

        public void TestFillPerson()
        {
            Person p = new Person();
            Filler<Person> filler = new Filler<Person>();
            filler.Setup()
                .OnType<IAddress>().CreateInstanceOf<Address>()
                .OnType<string>().Use(new MnemonicString(10))
                .OnProperty(person => person.FirstName).Use<MnemonicString>()
                .OnProperty(person => person.LastName).Use(new RandomListItem<string>("Maik", "Tom", "Anton"))
                .OnProperty(person => person.Age).Use(() => Tynamix.ObjectFiller.Random.Next(12, 83))
                .SetupFor<Address>()
                .OnProperty(x => x.City, x => x.Country).IgnoreIt();

            Person pFilled = filler.Fill(p);

            Assert.True(new List<string>() { "Maik", "Tom", "Anton" }.Contains(pFilled.LastName));
        }
开发者ID:Tynamix,项目名称:ObjectFiller.NET,代码行数:17,代码来源:ObjectFillerTest.cs

示例4: IgnoringPropertiesWillPreventFilling

        public void IgnoringPropertiesWillPreventFilling()
        {
            const string dummyData = "Data";
            var generator = MockRepository.GenerateStub<IGenerateDummyData>();
            generator.Stub(g => g.Generate(Arg<GenerationContext>.Is.Anything)).Return(dummyData);

            var filler = new Filler();
            var rootObject = new Foo();

            filler.Configure<Foo>(config =>{
                config.For(f => f.Description).Use(generator).Ignore();
                config.For(f => f.Name).Use(generator);
            });

            filler.Fill(rootObject);
            Assert.That(rootObject.Name, Is.EqualTo(dummyData));
            Assert.That(rootObject.Description, Is.Null);
        }
开发者ID:chrisjowen,项目名称:FillMe,代码行数:18,代码来源:FillerTests.cs

示例5: CollectionsGenerateDataBetweenXandYTimes

        public void CollectionsGenerateDataBetweenXandYTimes()
        {
            var filler = new Filler();

            var generator = MockRepository.GenerateStub<IGenerateDummyData>();
            generator.Stub(g => g.Generate(Arg<GenerationContext>.Is.Anything)).Return("Chris");

            filler.Configure<Bar>(config => config.For(goo => goo.Name).Use(generator));
            filler.Configure<Foo>(config => config.For(f => f.Bars).Between(10, 20));

            for (var i = 0; i <= 100; i++)
            {
                var rootObject = new Foo();
                filler.Fill(rootObject);
                var bars = rootObject.Bars.Count;
                Assert.That(bars, Is.LessThanOrEqualTo(20));
                Assert.That(bars, Is.GreaterThanOrEqualTo(10));
            }
        }
开发者ID:chrisjowen,项目名称:FillMe,代码行数:19,代码来源:FillingDataTests.cs

示例6: LetsGetSomeMatchesGoingOn

        public void LetsGetSomeMatchesGoingOn()
        {
            var users = new List<User>();

            var filler = new Filler();
            filler.Configure<Bar>().Defaults();
            filler.Configure<Foo>(config =>
            {
                config.For(foo => foo.Bars).Times(Constants.Random.Next(100));
                config.For(foo => foo.Age).Use(new RandomWholeNumberGenerator(10, 21)).Order(1);
                config.For(foo => foo.CalculatedAge).Do(context => context.CurrentAs<Foo>().Age + 20).Order(2);
            }).Defaults();

            filler.Configure<Goo>().Defaults();
            filler.Configure<User>().Defaults();
            filler.Configure<AllowedPartner>(config =>
            {
                config.For(allowedPartner => allowedPartner.MinAge).Use(new MinAgeGenerator());
                config.For(allowedPartner => allowedPartner.MaxAge).Use(new MaxAgeGenerator());
            });

            1000.Times(() => users.Add(filler.Fill(new User())));
            users.ToString();
        }
开发者ID:chrisjowen,项目名称:FillMe,代码行数:24,代码来源:ComplexDependenciesTests.cs

示例7: DependentFieldsWillNotBeUsefulUnlessOrderIsSpecified

        public void DependentFieldsWillNotBeUsefulUnlessOrderIsSpecified()
        {
            var rootObject = new Foo();
            var filler = new Filler();

            var generator = MockRepository.GenerateStub<IGenerateDummyData>();
            generator.Stub(g => g.Generate(Arg<GenerationContext>.Is.Anything)).Return(10);

            var dependentPropertyGenerator = MockRepository.GenerateStub<IGenerateDummyData>();
            dependentPropertyGenerator.Stub(g => g.Generate(Arg<GenerationContext>.Is.Anything)).Do(new GeneratorDelegate(context => context.RootAs<Foo>().Age + 1));

            filler.Configure<Foo>(config =>
            {
                config.For(f => f.CalculatedAge).Use(dependentPropertyGenerator);
                config.For(f => f.Age).Use(generator);
            });

            filler.Fill(rootObject);
            Assert.That(rootObject.Age, Is.EqualTo(10));
            Assert.That(rootObject.CalculatedAge, Is.EqualTo(1));

            filler.Configure<Foo>(config =>
            {
                config.For(f => f.Age).Order(2);
                config.For(f => f.CalculatedAge).Order(1);
            });

            filler.Fill(rootObject);
            Assert.That(rootObject.Age, Is.EqualTo(10));
            Assert.That(rootObject.CalculatedAge, Is.EqualTo(11));
        }
开发者ID:chrisjowen,项目名称:FillMe,代码行数:31,代码来源:FillingDataTests.cs

示例8: ShouldNotFillSubObjectIfRootObjectNotDefined

        public void ShouldNotFillSubObjectIfRootObjectNotDefined()
        {
            const string dummyData = "Data";
            var rootObject = new Foo();
            var filler = new Filler();

            var generator = MockRepository.GenerateStub<IGenerateDummyData>();
            generator.Stub(g => g.Generate(Arg<GenerationContext>.Is.Anything)).Return(dummyData);

            filler.Configure<Bar>(config => config.For(f => f.Name).Use(generator));

            filler.Fill(rootObject);
            Assert.That(rootObject.Bar, Is.Null);
        }
开发者ID:chrisjowen,项目名称:FillMe,代码行数:14,代码来源:FillingDataTests.cs

示例9: FillPerson

            public void FillPerson()
            {
                Person person = new Person();

                Filler<Person> pFiller = new Filler<Person>();
                Person p = pFiller.Fill(person);
            }
开发者ID:GothikX,项目名称:ObjectFiller.NET,代码行数:7,代码来源:LibraryFillingTest.cs


注:本文中的Filler.Fill方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。