public async Task Test_Get_Method_Without_Id() { var result = await testingInstance.Get(null); var expectedList = DevicesRepositoryMock.GetTestingDevices().OrderBy(x => x.Entry_Id).ToList(); var asOkObjectResult = Assert.IsAssignableFrom <OkObjectResult>(result); var resultList = asOkObjectResult.Value as IQueryable <Device>; var resultListSorted = resultList.OrderBy(x => x.Entry_Id).ToList(); Assert.Equal(expectedList, resultListSorted); }
public async Task GetAllDevicesOfAGatewayByItsSerialNumber() { //Setting all var nameBD = Guid.NewGuid().ToString(); var context = BuildContext(nameBD); context.Gateways.Add(new Gateway() { SerialNumber = "gw-001", Name = "Gateway 1", IpAddress = "10.0.0.1" }); context.Peripherals.Add(new Peripheral() { UID = 1, Vendor = "Device 1", Date = DateTime.Parse("2021-02-16T16:17:00"), Status = true }); context.PeripheralGateways.Add(new PeripheralsGateways() { GatewaySerialNumber = "gw-001", PeripheralId = 1 }); context.Peripherals.Add(new Peripheral() { UID = 2, Vendor = "Device 2", Date = DateTime.Parse("2021-02-16T16:18:00"), Status = false }); context.PeripheralGateways.Add(new PeripheralsGateways() { GatewaySerialNumber = "gw-001", PeripheralId = 2 }); context.Peripherals.Add(new Peripheral() { UID = 3, Vendor = "Device 3", Date = DateTime.Parse("2021-02-16T16:19:00"), Status = true }); context.PeripheralGateways.Add(new PeripheralsGateways() { GatewaySerialNumber = "gw-001", PeripheralId = 3 }); await context.SaveChangesAsync(); var testContext = BuildContext(nameBD); //Tests var controller = new DevicesController(testContext); var response = await controller.Get("gw-001"); //Verification var devices = response.Value; //A total of 3 Devices Assert.AreEqual(3, devices.Count); }
public async Task GetADeviceByNonExistingUID() { //Setting all var nameBD = Guid.NewGuid().ToString(); var context = BuildContext(nameBD); context.Gateways.Add(new Gateway() { SerialNumber = "gw-001", Name = "Gateway 1", IpAddress = "10.0.0.1" }); context.Peripherals.Add(new Peripheral() { UID = 1, Vendor = "Device 1", Date = DateTime.Parse("2021-02-16T16:17:00"), Status = true }); context.PeripheralGateways.Add(new PeripheralsGateways() { GatewaySerialNumber = "gw-001", PeripheralId = 1 }); context.Peripherals.Add(new Peripheral() { UID = 2, Vendor = "Device 2", Date = DateTime.Parse("2021-02-16T16:18:00"), Status = false }); context.PeripheralGateways.Add(new PeripheralsGateways() { GatewaySerialNumber = "gw-001", PeripheralId = 2 }); await context.SaveChangesAsync(); var testContext = BuildContext(nameBD); //Tests var uid = 3; var controller = new DevicesController(testContext); var response = await controller.Get(uid); //Verification var result = response.Result as StatusCodeResult; //Not Found Http Status Code Assert.AreEqual(404, result.StatusCode); }