示例#1
0
 private static IEnumerable <Category> GetRandomData()
 {
     return
         (new DomainGenerator()
          .With <Category>(g => g.For(category => category.Id, 0, val => val + 1))
          .With <Category>(g => g.For(category => category.Title, new StringGenerator(5, 10, 'H', 'a', 'l')))
          .With <Category>(
              g => g.For(category => category.Description,
                         new StringBuilderGenerator()
                         .Append("Not many", "Lots of", "Some")
                         .Space()
                         .Append("big", "small", "dangerous", "volatile", "futile")
                         .Space()
                         .Append("paintbrushes", "camels", "radio antaennas")
                         .Period(),
                         new NumericStringGenerator(4, 12)))
          .OneToMany <Category, Product>(3, 7, (c, p) => c.Products.Add(p))
          .With <Product>(g => g.For(product => product.Id, 0, val => val + 1))
          .With <Product>(g => g.For(product => product.Title, "title1", "title2", "Another title"))
          .With <Product>(
              g => g.For(product => product.Description,
                         new StringBuilderGenerator()
                         .Append(ListGenerator.FromFile("Adjectives.txt")).Space()
                         .Space().Dot().Dot().Dot().Space().Question(),
                         new StringBuilderGenerator()
                         .Append(ListGenerator.FromFile("Colours.txt")).Space()
                         .Append(ListGenerator.FromFile("Adjectives.txt")).Space()
                         .Append(ListGenerator.FromFile("Nouns.txt"))
                         .Period()))
          .With <Product>(g => g.For(product => product.Price, val => Math.Round(val, 2)))
          .With <Product>(g => g.For(product => product.Created, 31.December(2009), val => val.AddDays(1)))
          .Many <Category>(4, 8));
 }