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


C# Filler.Configure方法代码示例

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


在下文中一共展示了Filler.Configure方法的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: ShouldAddMappingSetForGivenType

 public void ShouldAddMappingSetForGivenType()
 {
     var filler = new Filler();
     filler.Configure<Foo>();
     Assert.That(filler.MappingSets.Count(), Is.EqualTo(1));
     Assert.That(filler.MappingSets.First().Type, Is.EqualTo(typeof(Foo)));
 }
开发者ID:chrisjowen,项目名称:FillMe,代码行数:7,代码来源:FillerTests.cs

示例4: 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

示例5: 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

示例6: 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

示例7: ShouldApplyConfigurationActionToMappingSetItems

        public void ShouldApplyConfigurationActionToMappingSetItems()
        {
            var filler = new Filler();
            var generator = MockRepository.GenerateStub<IGenerateDummyData>();
            var generatoB = MockRepository.GenerateStub<IGenerateDummyData>();

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

            Assert.That(filler.MappingSets.Count(), Is.EqualTo(1));

            var mappingSet = filler.MappingSets.First() as MappingSet<Foo>;
            Assert.That(mappingSet.Type, Is.EqualTo(typeof(Foo)));
            Assert.That(mappingSet.MappingItems.Count(), Is.EqualTo(2));
            Assert.That(mappingSet.MappingItems.First().Value.Generator, Is.EqualTo(generator));
            Assert.That(mappingSet.MappingItems.Last().Value.Generator, Is.EqualTo(generatoB));
        }
开发者ID:chrisjowen,项目名称:FillMe,代码行数:19,代码来源:FillerTests.cs

示例8: 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

示例9: 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


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