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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With