1

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?

Veikedo
  • 1,453
  • 1
  • 18
  • 25

1 Answers1

1

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?

Mark Seemann
  • 225,310
  • 48
  • 427
  • 736
  • I have a handler `GetDashboardStatistics` which just aggregates other handlers - `IGetPublicationStatistics`, `IGetSwitchboardStatistics`, `IGetAutomationStatistics`, etc. So I've written a test for `GetDashboardStatistics` like this https://pastebin.com/zB5ZVXcC and wonder if I can get rid of `fixture.Freeze` inside the test – Veikedo Sep 05 '18 at 14:19
  • The solution with dummy parameters works well, but I don't like warnings about unused params :) – Veikedo Sep 05 '18 at 14:23