public async void TestFindAll() { // Arrange var options = new DbContextOptionsBuilder <GatewayDbContext>().UseInMemoryDatabase("device_test_findall"); var db = new GatewayDbContext(options.Options); var gateway = new Gateway { Id = 1, Name = "ZZZ", IPv4 = "127.0.0.1", SerialNumber = "qwe123" }; var device = new Device { Id = 1, CreatedDate = new DateTime(), Status = Status.Online, UID = 1, Vendor = "Vendor", GatewayId = 1 }; var data = new List <Device> { device, new Device { Id = 2, CreatedDate = new DateTime(), Status = Status.Online, UID = 1, Vendor = "Vendor", GatewayId = 1 }, new Device { Id = 3, CreatedDate = new DateTime(), Status = Status.Online, UID = 1, Vendor = "Vendor", GatewayId = 1 } }; db.Add(gateway); db.AddRange(data); db.SaveChanges(); var repo = new DeviceRepository(db); // Act var result = await repo.FindAll(); // Assert Assert.Contains(device, result); }
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); }
public async void TestGet() { // Arrange 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" }, }; var options = new DbContextOptionsBuilder <GatewayDbContext>().UseInMemoryDatabase("gateway_test_get"); var db = new GatewayDbContext(options.Options); db.AddRange(data); db.SaveChanges(); var repo = new GatewayRepository(db); var loggerMock = new Mock <ILogger <GatewayController> >(); var controller = new GatewayController(repo, loggerMock.Object); // Act var result = await controller.Get(); // Assert Assert.Contains(gateway, result); }