Freeze enum value in AutoFixture
.net, autofixture, c#
Solution
`Freeze` `Inject` and `Register` are slightly different.
Use `Inject` for the described behavior, as the following test demonstrates:
[Fact]
public void Test()
{
var fixture = new Fixture();
var expected = Letters.D;
fixture.Inject(expected);
var letter = fixture.Create<Letters>();
var anotherLetter = fixture.Create<Letters>();
Assert.Equal(expected, letter);
Assert.Equal(expected, anotherLetter);
}
The problem with the question's sample code is that the parameter (seed) isn't used as the frozen value.
Problem
We have an enum: ``` enum Letters { A, B, C, D, E } ``` When I try: ``` var frozenLetter = fixture.Freeze(Letters.D); ``` Strangely, frozenLetter == A. ``` var letter = fixture.Create<Letters>(); var anotherLetter = fixture.Create<Letters>(); ``` Letter and anotherLetter both equal A, so the Letters type has been frozen, but to the first constant in the enum rather than the one specified. Is there a way to freeze an enum to the constant I wish?