本文整理汇总了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"));
}
示例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"));
}
示例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)));
}
示例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));
}
}
示例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();
}
示例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);
}
示例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));
}
示例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));
}
示例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);
}