minicover
minicover copied to clipboard
Using Records with `with` keyword results in "Common Language Runtime detected an invalid program"
So we use have simple tests using records and with
statement:
[Fact]
public void GivenValidate_WhenSourceContractIsDefault_ThenItShouldBeInvalid()
{
var validationResult = new AddLeaseChangeModelValidator().Validate(
GetValidModel(m => m with { SourceContractVersion = 0 })
);
validationResult.IsValid.Should().BeFalse();
}
GetValidModel looks like this:
private static LeaseChangeModel GetValidModel(Func<LeaseChangeModel, LeaseChangeModel>? func = null)
{
var model = new LeaseChangeModel
(
IndividualLeaseAgreementNumber: "dummy_IndividualLeaseAgreementNumber",
//...
);
if (func is not null)
{
return func(model);
}
return model;
}
This works perfectly with good old classes with public getter / setter. But breaks using records.
System.InvalidProgramException : Common Language Runtime detected an invalid program.
On our CI/CD we run minicover 3.4.4
I tried locally with 3.4.8 and get the same result.
I wonder if this is perhaps a Mono.Cecil limitation.