Skip to content

[Bug]: Issue Mocking EF Core EntityEntry #5673

@Connor-Immix

Description

@Connor-Immix

Description

First let me say I absolutely love this library, when I switched to it from xUnit I thought it was broken at first because it was so fast.

Unfortunately I have an error with the mocking library. Mocking the Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry type in EFCore 10 results in a build error.

Expected Behavior

To be able to mock the type without any errors. I want to use it to unit test a dbContext interceptor.

Actual Behavior

The generated source code has the following error preventing build:

'EntityEntryMockImpl.Instance': no suitable method found to override

Drilling down into the generated code the issue appears to be with this block:

 public override global::Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry Instance
 {
 get => _engine.HandleCallWithReturn<global::Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry>(39, "get_Instance", global::System.Array.Empty<object?>(), default!);
 }

Steps to Reproduce

using TUnit.Mocks;
using Microsoft.EntityFrameworkCore.ChangeTracking;

public class ReproduceError
{
    private void MockEntityEntry()
    {
        var mocked = EntityEntry.Mock();
    }
}

TUnit Version

TUnit.Mocks 1.37.36-beta

.NET Version

.NET 10.0

Operating System

Windows

IDE / Test Runner

Visual Studio

Error Output / Stack Trace

'EntityEntryMockImpl.Instance': no suitable method found to override

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