1

I have this model:

public class OrderProperty
{
    [Required] public int Id { get; set; }
    [Required] public int Order { get; set; }
}

The Order property starts at 0 instead of 1. When I use NBuilder to build me a list of OrderProperties, it automatically sets the first Order to 1

Builder<OrderProperty>.CreateListOfSize(10).Build().ToList()

Is there a way to tell it to start from 0 instead?

r3plica
  • 13,017
  • 23
  • 128
  • 290
  • The docs recommend you read the [tests](https://github.com/garethdown44/nbuilder/blob/master/Source/FizzWare.NBuilder.FunctionalTests/ListBuilderTests.cs), the tests suggest that something like `.TheFirst(1).With(x => x.Order = 0)` should work. (Disclaimer, ironically or otherwise: not tested.) – Jeroen Mostert Feb 04 '20 at 11:34

1 Answers1

2

you can do simply like this.

Builder<OrderProperty>.CreateListOfSize(10).All().With(x => x.Order -=1).Build().ToList();
rabin prajapati
  • 280
  • 4
  • 9
  • Is it possible to do it for "TheFirst" and "TheNext" also? I tried: `Builder.CreateListOfSize(10).All().TheFirst(5).With(m => m.CategoryId = "A").With(m => m.Order -= 1).TheNext(5).With(m => m.CategoryId = "B").With(m => m.Order -= 1).Build().ToList()` but it didn't work – r3plica Feb 04 '20 at 16:40