Please see the code below:
Guid product1Guid = Guid.NewGuid();
Guid product2Guid = Guid.NewGuid();
Products = new List<Product>();
var product1 = new Product(product1Guid), "Product 1");
var product2 = new Product(product1Guid), "Product 2");
Products.Add(product1);
Products.Add(product2);
This code is used by five of my test methods. Where do I put this code? The options are:
1) OneTimeSetup method: An answerer of another question advises against this because Product is mutable and in the future one test could accidentally mutate the state meaning all the following tests fail.
2) Create a method inside the test class (which returns the list): An answerer of another question advises against this because you should not stub a simple data object.
3) Put the code above in each test method. This seems to violate the DRY principle.
4) Create a Helper class, which is external to the test class (which returns the list):. I am not sure if this is normal.
I realise that all of the options above will work. I am trying to follow the principle of least astonishment here so that Developers who look at my code in future will know what to expect.