I have the following types:
public enum Status
{
Online,
Offline
}
public class User
{
private readonly Status _status;
public User(Status status) { _status = status; }
public Status Status {get {return _status; }}
public string Name {get;set;}
}
Now, when executing fixture.CreateMany<User>
I want AutoFixture to return two Users
, one per status. All other properties - like Name
- should be filled with anonymous data.
Question:
How to configure AutoFixture to do this?
I tried the following this:
Register collection that news up the
User
object:fixture.Register( () => Enum.GetValues(typeof(Status)).Cast<Status>().Select(s => new User(s)));
The problem with this approach is that AutoFixture doesn't fill the other properties like
Name
Customize
User
to use a factory and register a collection that usesfixture.Create
:f.Customize<User>(c => c.FromFactory((Status s) => new User(s))); f.Register(() => Enum.GetValues(typeof(Status)) .Cast<Status>() .Select(s => (User)f.Create(new SeededRequest(typeof(User), s), new SpecimenContext(f))));
That didn't work either. The seed isn't being used.
Status
property isn'treadonly
.First
"never" returns (I waited at least 30 seconds). – Ruination