My test requires that I set the Response property on an immutable Rsvp object (see below) to a specific value.
public class Rsvp
{
public string Response { get; private set; }
public Rsvp(string response)
{
Response = response;
}
}
I initially tried to do this using Build<Rsvp>().With(x => x.Rsvp, "Attending"), but realized this only supports writable properties.
I replaced that with Build<Rsvp>().FromFactory(new Rsvp("Attending")). This works, but is cumbersome for more complex objects where it doesn't matter what some of the properties are.
For instance, if the Rsvp object had a CreatedDate property, this method of instantiating the object would force me to write Build<Rsvp>().FromFactory(new Rsvp("Attending", fixture.Create<DateTime>())).
Is there a way to only specify values for meaning properties for an immutable object?