How can I reset an EF7 InMemory provider between unit tests?

后端 未结 7 1191
忘掉有多难
忘掉有多难 2021-01-31 13:01

I am trying to use the EF7 InMemory provider for unit tests, but the persistent nature of the InMemory database between tests is causing me problems.

The following code d

7条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-31 13:55

    Bit late to the party, but i also ran into the same issue but what i ended up doing was.

    Specifying a different database name for each test.

    optionsBuilder.UseInMemoryDatabase(Guid.NewGuid().ToString());
    

    That way you dont have to add

    _context.Database.EnsureDeleted();
    

    in all your tests

提交回复
热议问题