public async Task CategoryIdByNameTest() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; var dbContext = new ApplicationDbContext(options); dbContext.Categories.Add(new Category { Id = 1, Name = "First", }); dbContext.Categories.Add(new Category { Id = 2, Name = "Second", }); await dbContext.SaveChangesAsync(); var repository = new EfDeletableEntityRepository <Category>(dbContext); var service = new CategoriesService(repository); Assert.Equal(1, service.CategoryIdByName("First")); Assert.Equal(2, service.CategoryIdByName("Second")); }