Skip to content

[Bug]: Mocking a qualified name doesn't generate the mock class #6298

Description

@jpelcis

Description

If you only reference an interface using a qualified name then the mock class isn't generated.

If something else generates the mock class then everything still works as expected.

Expected Behavior

Mock class is generated.

Actual Behavior

Mock class isn't generated.

Steps to Reproduce

using Namespace;
using ITestInterfaceFromUsing = Namespace.ITestInterface;

namespace Namespace
{
    public interface ITestInterface
    {
        string Method();
    }
}

public class Tester
{
    [Test]
    public async Task HowYouReferenceMatters()
    {
        var mock1 = Namespace.ITestInterface.Mock();
        mock1.Method().Returns("value");

        // Not only will mock2 work, but this also fixes mock1
        //var mock2 = ITestInterfaceFromUsing.Mock();
        //mock2.Method().Returns("value");
    }
}

TUnit Version

1.56.25

.NET Version

.NET 10

Operating System

Windows

IDE / Test Runner

dotnet CLI (dotnet test / dotnet run)

Error Output / Stack Trace

error CS1061: 'Mock' does not contain a definition for 'Method' and no accessible extension method 'Method' accepting a first argument of type 'Mock' could be found (are you missing a using directive or an assembly reference?)

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