Unitverse icon indicating copy to clipboard operation
Unitverse copied to clipboard

Support Primary Constructors

Open msalzig opened this issue 10 months ago • 0 comments

When generating tests, the code for instantiating the test class is not generated correctly if the class has a primary constructor. The constructor parameters are missing.

Example:

public class RequestHandler(IOptions<CommonOptions> options) { private readonly CommonOptions _options = options.Value!; }

Generated test class:

`public class RequestHandlerTests { private readonly RequestHandler testClass;

public RequestHandlerTests ()
{
    _testClass = new CustomerAccountEventsRequestHandler( the construtor parameter is missing here );
}

}`

Expected test class:

`public class RequestHandlerTests { private readonly CustomerAccountEventsRequestHandler _testClass; private readonly IOptions<CommonOptions> _options;

public RequestHandlerTests ()
{
    _options = Substitute.For<IOptions< CommonOptions >>();
    _testClass = new CustomerAccountEventsRequestHandler(_options);
}

}`

msalzig avatar Apr 18 '25 04:04 msalzig