Veikedo
Veikedo

Reputation: 1503

AutoFixture deep freeze of object

I have a class

public class GetDashboardStatisticsResult
{
  public GetPublicationStatisticsResult Publications { get; set; }
  public GetSwitchboardStatisticsResult Switchboard { get; set; }
}

Which I use in my test like this

public async Task Should_return_correct_statistics([Frozen] GetDashboardStatisticsResult expectedResult);

And I wonder if there is there a way to freeze GetDashboardStatisticsResult together with its properties?

So at the end we have three types frozen - GetDashboardStatisticsResult, GetPublicationStatisticsResult and GetSwitchboardStatisticsResult?

Upvotes: 1

Views: 427

Answers (1)

Mark Seemann
Mark Seemann

Reputation: 233150

I don't think AutoFixture has any feature that enables something like that, but you could, possibly, work around it like this:

[Theory, AutoData]
public async Task Should_return_correct_statistics(
    [Frozen]GetPublicationStatisticsResult dummy1,
    [Frozen]GetSwitchboardStatisticsResult dummy2,
    [Frozen]GetDashboardStatisticsResult expectedResult)
{
    // Test goes here...
}

The best solution is probably to reconsider the design of the types in question. I've never encountered needing such a feature. What problem are you trying to solve?

Upvotes: 1

Related Questions