Skip if connectionstate ID == null

This commit is contained in:
Martijn Scheepers
2021-01-06 11:17:17 +01:00
parent 784a6c9d1a
commit 7530888bbe
2 changed files with 16 additions and 6 deletions

View File

@@ -20,7 +20,7 @@ namespace UCS_Status_Monitor.UnitTest
[TestInitialize]
public void CreateNewDatabase()
{
//database is in bin folder van testporject
//database is in bin folder van testproject
using var dbContext = new MonitorDbContext();
dbContext.Database.EnsureDeleted();
dbContext.Database.EnsureCreated();
@@ -171,10 +171,6 @@ namespace UCS_Status_Monitor.UnitTest
Assert.AreEqual("OK", result.Value);
Assert.AreEqual(4, telemetryController.SystemCount());
Assert.AreEqual(0, telemetryController.DeviceCount());
}
[TestMethod]
@@ -188,16 +184,25 @@ namespace UCS_Status_Monitor.UnitTest
ComputerName = "PXX - UCS99",
};
//list == null
var result = telemetryController.Post(telemetryPacket);
Assert.AreEqual("OK", result.Value);
Assert.AreEqual(1, telemetryController.SystemCount());
Assert.AreEqual(0, telemetryController.DeviceCount());
//empty list
telemetryPacket.Connectionstates = new System.Collections.Generic.List<Models.ConnectionState>();
result = telemetryController.Post(telemetryPacket);
Assert.AreEqual("OK", result.Value);
Assert.AreEqual(0, telemetryController.DeviceCount("PXX - UCS99"));
//list with empty device
telemetryPacket.Connectionstates.Add(new Models.ConnectionState() { });
result = telemetryController.Post(telemetryPacket);
Assert.AreEqual("OK", result.Value);
Assert.AreEqual(0, telemetryController.DeviceCount("PXX - UCS99"));
//only ID
telemetryPacket.Connectionstates.Add(new Models.ConnectionState() { ID = "DX" });
result = telemetryController.Post(telemetryPacket);
Assert.AreEqual("OK", result.Value);

View File

@@ -126,6 +126,11 @@ namespace UCS_Status_Monitor.Controllers
//Update all devices in connectionstate list
foreach (var item in telemetry.Connectionstates)
{
if (item.ID == null)
{
continue;
}
var device = dbContext.UCSDevices.Where(d => d.BoxID == item.ID && d.UCSSystem.UCSSystemId == system.UCSSystemId).SingleOrDefault();
if (device == null)
{
@@ -135,7 +140,7 @@ namespace UCS_Status_Monitor.Controllers
BoxID = item.ID,
State = item.State,
LastStateChange = item.LastStateChange != null ? DateTime.Parse(item.LastStateChange) : DateTime.MinValue,
UCSSystem = system
UCSSystem = system
};
dbContext.UCSDevices.Add(newDevice);
}