aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

Support exclusion of Razor Page code behind classes from code coverage

Open Kralizek opened this issue 1 year ago • 0 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

I am trying to exclude the classes generated from the code behind of Razor pages from the code coverage report.

Generated classes use the Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemAttribute at assembly level, making it useless for "targeting" generated classes.

Describe the solution you'd like

It would be helpful if generated classes could be decorated with a class-level attribute that can be targeted when excluding classes from code coverage.

The already existing System.Runtime.CompilerServices.CompilerGeneratedAttribute attribute would be enough.

Additional context

    [global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemMetadataAttribute("RouteTemplate", "/contacts/{contactId:guid}")]
    [global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemMetadataAttribute("Identifier", "/Pages/Contacts/View.cshtml")]
    [global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdateAttribute]
    #nullable restore
    internal sealed class Pages_Contacts_View : global::Microsoft.AspNetCore.Mvc.RazorPages.Page

The instances of RazorCompiledItemMetadataAttribute aren't useful as the same attribute is used with the assembly decorator at the beginning of the file.

[assembly: global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemAttribute(typeof(Sample.Pages.Contacts.Pages_Contacts_View), @"mvc.1.0.razor-page", @"/Pages/Contacts/View.cshtml")]

Kralizek avatar Aug 25 '24 17:08 Kralizek