public async void TestFindById() { // Arrange var options = new DbContextOptionsBuilder <GatewayDbContext>().UseInMemoryDatabase("gateway_test_findbyid"); var db = new GatewayDbContext(options.Options); // db.RemoveRange(db.Gateways); // await db.SaveChangesAsync(); var gateway = new Gateway { Id = 1, Name = "BBB", IPv4 = "192.168.4.12", SerialNumber = "sdsd" }; var data = new List <Gateway> { gateway, new Gateway { Id = 2, Name = "ZZZ", IPv4 = "127.0.0.1", SerialNumber = "qwe123" }, new Gateway { Id = 3, Name = "asd", IPv4 = "127.0.0.1", SerialNumber = "qdsfs" }, }.AsQueryable(); db.AddRange(data); await db.SaveChangesAsync(); var repo = new GatewayRepository(db); // Act var result = await repo.FindById(1); // Assert Assert.Equal("BBB", result.Name); }