[Frozen] attribute is used to freeze instances of objects. It is applied on test method parameters.
We will consider simple examples with string comparison test.
Without [Frozen] attribute
using Ploeh.AutoFixture.Xunit2; using Xunit; [Theory, InlineAutoData] public void No_Frozen_Attribute_Generates_Random_Strings( string one, string two) { Assert.Equal(one, two); }
Result: Failed
Using [Frozen] attribute
Applying [Frozen] on the first parameter of type string, will return the same values for all subsequent parameters.
[Theory, InlineAutoData] public void Frozen_On_Parameter_Name_Freeze_Object_Instance( [Frozen]string one, string two) { Assert.Equal(one, two); }
Result: Passed
Using [Frozen] attribute – Order is important!
Applying [Frozen] attribute on the second parameter will generate two random strings.
But if we have third parameter of type ‘string’, then it will have the same value as ‘two’.
[Theory, InlineAutoData] public void Frozen_On_Parameter_Name_Order_Is_Important( string one, [Frozen]string two) { Assert.Equal(one, two); }
Result: Failed