public void DeviceRegistrationTest() { var controller = new DevicesController(); var response = controller.Post(new Device()).Value as DeviceRegistrationResult; Assert.True(response.success); }
public async Task AddADevice() { //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" }); await context.SaveChangesAsync(); var testContext = BuildContext(nameBD); //Tests var device = new Peripheral() { UID = 1, Vendor = "Device 1", Date = DateTime.Parse("2021-02-16T16:17:00"), Status = true }; var controller = new DevicesController(testContext); var response = await controller.Post(device, "gw-001"); //Verification var result = response.Result; Assert.IsNotNull(result); var countDevices = await testContext.Peripherals.CountAsync(); Assert.AreEqual(1, countDevices); var countRelations = await testContext.PeripheralGateways.CountAsync(); Assert.AreEqual(1, countRelations); }
public async Task AddADeviceToAFullGateway() { //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 }); context.Peripherals.Add(new Peripheral() { UID = 4, Vendor = "Device 4", Date = DateTime.Parse("2021-02-16T16:20:00"), Status = true }); context.PeripheralGateways.Add(new PeripheralsGateways() { GatewaySerialNumber = "gw-001", PeripheralId = 4 }); context.Peripherals.Add(new Peripheral() { UID = 5, Vendor = "Device 5", Date = DateTime.Parse("2021-02-16T16:21:00"), Status = false }); context.PeripheralGateways.Add(new PeripheralsGateways() { GatewaySerialNumber = "gw-001", PeripheralId = 5 }); context.Peripherals.Add(new Peripheral() { UID = 6, Vendor = "Device 6", Date = DateTime.Parse("2021-02-16T16:22:00"), Status = true }); context.PeripheralGateways.Add(new PeripheralsGateways() { GatewaySerialNumber = "gw-001", PeripheralId = 6 }); context.Peripherals.Add(new Peripheral() { UID = 7, Vendor = "Device 7", Date = DateTime.Parse("2021-02-16T16:23:00"), Status = true }); context.PeripheralGateways.Add(new PeripheralsGateways() { GatewaySerialNumber = "gw-001", PeripheralId = 7 }); context.Peripherals.Add(new Peripheral() { UID = 8, Vendor = "Device 8", Date = DateTime.Parse("2021-02-16T16:24:00"), Status = false }); context.PeripheralGateways.Add(new PeripheralsGateways() { GatewaySerialNumber = "gw-001", PeripheralId = 8 }); context.Peripherals.Add(new Peripheral() { UID = 9, Vendor = "Device 9", Date = DateTime.Parse("2021-02-16T16:25:00"), Status = true }); context.PeripheralGateways.Add(new PeripheralsGateways() { GatewaySerialNumber = "gw-001", PeripheralId = 9 }); context.Peripherals.Add(new Peripheral() { UID = 10, Vendor = "Device 10", Date = DateTime.Parse("2021-02-16T16:26:00"), Status = true }); context.PeripheralGateways.Add(new PeripheralsGateways() { GatewaySerialNumber = "gw-001", PeripheralId = 10 }); await context.SaveChangesAsync(); var testContext = BuildContext(nameBD); //Tests var device = new Peripheral() { UID = 11, Vendor = "Device 11", Date = DateTime.Parse("2021-02-16T16:27:00"), Status = true }; var controller = new DevicesController(testContext); var response = await controller.Post(device, "gw-001"); //Verification var result = response.Result as BadRequestObjectResult; //Bad Request Http Status Code Assert.AreEqual(400, result.StatusCode); var countDevices = await testContext.Peripherals.CountAsync(); Assert.AreEqual(10, countDevices); var countRelations = await testContext.PeripheralGateways.CountAsync(); Assert.AreEqual(10, countRelations); }