You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create a test: I comment query.Handler because just to simplify things, in fact it will execute DbSet.Add()
[Test]publicasyncTaskCreateCorCommandHandlerTest(){varContext=CBERPContextFactory.Create();/*var query = new CreateCorCommandHandler(Context); var command = new CreateCorCommand(); command.Nome = "123123"; command.RGB = "#001122"; var colecaoId = await query.Handle(command, CancellationToken.None);*/varcor=newDomain.Entities.Cor(){Nome="Gray",RGB="#CCC"};Context.Cores.Add(cor);awaitContext.SaveChangesAsync();vardbCor=Context.Cores.Where(p =>p.Id==cor.Id).SingleOrDefault();CBERPContextFactory.Destroy(Context);varcolecaoId=cor.Id;//AssertAssert.IsInstanceOf<long>(colecaoId);Assert.NotZero(colecaoId);Assert.NotNull(dbCor);Assert.AreEqual(cor.Nome,dbCor.Nome);Assert.AreEqual(cor.RGB,dbCor.RGB);}
I expect this test to pass, but instead, I receive the following exception Message: System.ArgumentException : An item with the same key has already been added. Key: 1
If I change the table to be empty by default, and change the test to add more than one entity on database, the auto increment work as expected, resulting in IDs 1 and 2.
Further technical details
EF Core version: 2.2.4
Database Provider: Microsoft.EntityFrameworkCore.InMemory 2.2.4
Operating system: Windows 10
IDE: (e.g. Visual Studio 2017 15.4) VS2019
The text was updated successfully, but these errors were encountered:
This bug is still occurring in preview 5 of EF Core 3.0.
I actually don't think it is a duplicate of #6872 which seems to be more about resetting value generator between the tests. Here the problem is that value generator does not take into account explicit IDs passed in HasData calls and tries to start from 1 for integers.
Auto increment/Identity initial value is not correct when the table has seeds
Steps to reproduce
Create a table with Identity Column Id
Create a test:
I comment query.Handler because just to simplify things, in fact it will execute
DbSet.Add()
I expect this test to pass, but instead, I receive the following exception
Message: System.ArgumentException : An item with the same key has already been added. Key: 1
If I change the table to be empty by default, and change the test to add more than one entity on database, the auto increment work as expected, resulting in IDs 1 and 2.
Further technical details
EF Core version: 2.2.4
Database Provider: Microsoft.EntityFrameworkCore.InMemory 2.2.4
Operating system: Windows 10
IDE: (e.g. Visual Studio 2017 15.4) VS2019
The text was updated successfully, but these errors were encountered: