Skip to content

[Bug]: Mocking Protected Internal Virtual with Internals Visible To Not Working #5975

@caviyacht

Description

@caviyacht

Description

Whenever you have a class that has a method that is protected internal virtual and the project is set to InternalsVisibleTo, TUnit is generating a wrapped mock that does not adhere to the requirements of method accessibility.

TUnit is generating a method that has protected override when the method that is wrapped should contain protected internal override. If the InternalsVisibleTo is removed from the project, it works as expected, but is not ideal as the internal methods are no longer accessible in the tests project.

Expected Behavior

I would expect that if the tests project is allowed to have access to the internals of the root assembly that it would generate the correct access modifiers for protected internal virtual methods.

Expected format:

Image

Actual Behavior

The current behavior is that the internals visible to is not being adhered correctly when generating wrappers for protected internal virtual methods.

The error:

Image

Internals Visible To:

Image

Method:

Image

Generated method:

Image

Steps to Reproduce

To see the issue, use the following project. This project contains the current setup exposing the issue.

If the project is not used, then:

  • Create a project that has it's internals visible to set to the tests project
  • The project should contain a class that has a protected internal virtual method
  • The test project should attempt to wrap the class in the main project

Sample Project:

TUnitTestApp.zip

TUnit Version

1.45.22

.NET Version

.NET 10

Operating System

Windows

IDE / Test Runner

Visual Studio

Error Output / Stack Trace

Additional Context

No response

IDE-Specific Issue?

  • I've confirmed this issue occurs when running via dotnet test or dotnet run, not just in my IDE

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions