Make it easier to mock DbSet.Add
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.4k
- PR merge metrics
- PR metrics pending
Description
##upgrading from EF Core 5.0.2 to 6.0.1 making Nunit unit test to fail
Currently I have upgraded from .net core 5 to .net 6, so I also have to update ef core from 5 to 6.0.1. However doing this is failing some of my unit test written in nunit and using Moq.
Issue is occuring while mocking 'InternalEntityEntry' class which is sealed in 6.0.1 but abstract in 5.0.2.
Below is the code that I am using to create Moq:
```
var entry = new Mock(new Mock().Object,
new EntityType(typeof(T), new Model(), true, ConfigurationSource.Explicit)).Object;
var entityEntry = new Mock>(entry);
entityEntry.SetupGet(self => self.Entity).Returns(data);
mockSet.Setup(d => d.AddAsync(It.IsAny(), default)).Returns(() => new ValueTask>(entityEntry.Object));
```
and below is the error received:
```
System.NotSupportedException : Type to mock (InternalEntityEntry) must be an interface, a delegate, or a non-sealed, non-static class.
```
Help me in resolving this.
### Include provider and version information
EF Core version: 6.0.1
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 6.0
Operating system:
IDE: Visual Studio 2022
Contributor guide
Assessment
This issue has not been assessed yet.