use testcontext cancel token
This commit is contained in:
@@ -687,7 +687,7 @@ namespace Aperio_Control_Centre.ACSDatabase.UnitTest
|
||||
await db.SaveChangesAsync(cancellationToken);
|
||||
|
||||
//await db.DisableDevice("112233", cancellationToken);
|
||||
}).Wait();
|
||||
}, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(1, db.Loggings.Count());
|
||||
|
||||
@@ -866,6 +866,8 @@ namespace Aperio_Control_Centre.ACSDatabase.UnitTest
|
||||
Assert.IsNull(stateDevice.LastData);
|
||||
}
|
||||
|
||||
public TestContext TestContext { get; set; }
|
||||
|
||||
//[TestMethod]
|
||||
//public void GetState_Test()
|
||||
//{
|
||||
|
||||
@@ -10,6 +10,8 @@ namespace Aperio_Control_Centre.ACSDatabase.UnitTest
|
||||
[TestClass]
|
||||
public class LoggingTest
|
||||
{
|
||||
public TestContext TestContext { get; set; }
|
||||
|
||||
IDbContextFactory<ACSDatabaseContext> _dbContextFactory = default!;
|
||||
|
||||
[TestInitialize]
|
||||
@@ -120,7 +122,7 @@ namespace Aperio_Control_Centre.ACSDatabase.UnitTest
|
||||
{
|
||||
await db.Loggings.AddUserLogAsync(device, user, AccessTypes.Granted, "Userlog message", token);
|
||||
await db.SaveChangesAsync(token);
|
||||
}).Wait();
|
||||
}, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(1, db.Loggings.Count());
|
||||
Logging log = db.Loggings.Last();
|
||||
@@ -151,7 +153,7 @@ namespace Aperio_Control_Centre.ACSDatabase.UnitTest
|
||||
{
|
||||
await db.Loggings.AddUnknownUserLogAsync(device, "A19506B0", CredentialTypes.Desfire, "Unknown user log message", token);
|
||||
await db.SaveChangesAsync(token);
|
||||
}).Wait();
|
||||
}, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(1, db.Loggings.Count());
|
||||
Logging log = db.Loggings.Last();
|
||||
|
||||
@@ -11,13 +11,13 @@ namespace Aperio_Control_Centre.Export.UnitTest.Paxton
|
||||
{
|
||||
//ict;JanWillem;;{'Cards':[{'Number':'19697050','Type':'0','Lost':'0'}]};;Huurder 02 Arbounie;{'AccessLevels':[{'Name':'Arbo Unie', 'Ordinal':'1'}]};;;;2023-jul-14;;;;;;;;;;;;;;;;1581
|
||||
|
||||
PaxtonAuthorizationModel auth = new PaxtonAuthorizationModel
|
||||
PaxtonAuthorizationModel auth = new()
|
||||
{
|
||||
Name = "Arbo Unie",
|
||||
Ordinal = true
|
||||
};
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
StringBuilder sb = new();
|
||||
auth.ToCSV(ref sb);
|
||||
|
||||
Assert.AreEqual("{'Name':'Arbo Unie','Ordinal':'1'}", sb.ToString());
|
||||
@@ -26,13 +26,13 @@ namespace Aperio_Control_Centre.Export.UnitTest.Paxton
|
||||
[TestMethod]
|
||||
public void AuthorizationModel_ToCSV2()
|
||||
{
|
||||
PaxtonAuthorizationModel auth = new PaxtonAuthorizationModel
|
||||
PaxtonAuthorizationModel auth = new()
|
||||
{
|
||||
Name = "Arbo Unie",
|
||||
Ordinal = false
|
||||
};
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
StringBuilder sb = new();
|
||||
auth.ToCSV(ref sb);
|
||||
|
||||
Assert.AreEqual("{'Name':'Arbo Unie','Ordinal':'0'}", sb.ToString());
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Aperio_Control_Centre.Export.Paxton
|
||||
{
|
||||
//{'Number':'19697050','Type':'0','Lost':'0'}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
StringBuilder sb = new();
|
||||
sb.Append("{'Number':'");
|
||||
sb.Append(Number);
|
||||
sb.Append("','Type':'");
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
_logger = new TestingLogger<AperioBase>();
|
||||
|
||||
AperioBase baseDevice = new(_screenLogging, _statusBroadcast, _dbContextFactory, CreateAperioServerOptions(), _logger);
|
||||
baseDevice.SetBaseDevice(new("AA11BB"), aperioConnectionContext, _token).Wait();
|
||||
baseDevice.SetBaseDevice(new("AA11BB"), aperioConnectionContext, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual("AA11BB", baseDevice.Id);
|
||||
Assert.AreNotEqual(0, baseDevice.LastData.Ticks);
|
||||
@@ -95,10 +95,11 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
_ = connectionMoq.Setup(s => s.Transport.Output.WriteAsync(It.IsAny<ReadOnlyMemory<byte>>(), It.IsAny<CancellationToken>()));
|
||||
|
||||
TestingAperioConnectionContext aperioConnectionContext = new();
|
||||
|
||||
aperioConnectionContext.SetConnection(connectionMoq.Object);
|
||||
Assert.AreEqual("XYZ123", aperioConnectionContext.ConnectionId);
|
||||
|
||||
device.SetConnection(aperioConnectionContext, _token).Wait();
|
||||
device.SetConnection(aperioConnectionContext, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual("XYZ123", device.Connection.ConnectionId);
|
||||
|
||||
@@ -133,7 +134,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
aperioConnectionContext.SetConnection(connectionMoq.Object);
|
||||
Assert.AreEqual("241.251.9.0", aperioConnectionContext.Address.ToString());
|
||||
|
||||
device.SetConnection(aperioConnectionContext, _token).Wait();
|
||||
device.SetConnection(aperioConnectionContext, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual("241.251.9.0", device.IPAddress);
|
||||
|
||||
@@ -175,7 +176,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
db.SaveChanges();
|
||||
}
|
||||
|
||||
device.SetConnectionState(ConnectionStates.Online, _token).Wait();
|
||||
device.SetConnectionState(ConnectionStates.Online, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(ConnectionStates.Online, device.ConnectionState);
|
||||
|
||||
@@ -205,7 +206,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
|
||||
Assert.AreEqual(Status.UNKNOWN, device.DeviceStatus);
|
||||
|
||||
device.SetDeviceStatus(Status.FAIL_UNKNOWN_ID, _token).Wait();
|
||||
device.SetDeviceStatus(Status.FAIL_UNKNOWN_ID, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(Status.FAIL_UNKNOWN_ID, device.DeviceStatus);
|
||||
|
||||
@@ -221,10 +222,10 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
|
||||
Assert.IsNotNull(_dbContextFactory);
|
||||
using ACSDatabaseContext context = _dbContextFactory.CreateDbContext();
|
||||
Assert.AreEqual(1, context.Loggings.Count());
|
||||
List<Logging> logs = context.Loggings.Include(d => d.Device).ToList();
|
||||
Assert.IsNotNull(logs);
|
||||
Assert.AreEqual("device Status (FAIL_UNKNOWN_ID)", logs[0].Message);
|
||||
Assert.AreEqual(0, context.Loggings.Count());
|
||||
//List<Logging> logs = context.Loggings.Include(d => d.Device).ToList();
|
||||
//Assert.IsNotNull(logs);
|
||||
//Assert.AreEqual("device Status (FAIL_UNKNOWN_ID)", logs[0].Message);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -236,7 +237,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
|
||||
int eventFired = 0;
|
||||
device.DeviceChanged += (s, e) => { eventFired++; };
|
||||
device.HandleMessage(new TamperStateNotification(new Id("AA11BB"), TamperState.TAMPER), _token).Wait();
|
||||
device.HandleMessage(new TamperStateNotification(new Id("AA11BB"), TamperState.TAMPER), TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(1, eventFired);
|
||||
|
||||
@@ -270,7 +271,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
|
||||
int eventFired = 0;
|
||||
device.DeviceChanged += (s, e) => { eventFired++; };
|
||||
device.HandleMessage(new TamperStateResult(new Id("AA11BB"), TamperState.TAMPER), _token).Wait();
|
||||
device.HandleMessage(new TamperStateResult(new Id("AA11BB"), TamperState.TAMPER), TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(1, eventFired);
|
||||
|
||||
@@ -469,7 +470,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
|
||||
int eventFired = 0;
|
||||
device.DeviceChanged += (s, e) => { eventFired++; };
|
||||
device.HandleMessage(new DtcNotification(new("AA11BB"), new DtcInfo(new DTC(DTCEnumerations.Type.VOLTAGE_BELOW_MIN, DTCEnumerations.Source.BACKUP_BATTERY, 10), 35689, true, false, true)), _token).Wait();
|
||||
device.HandleMessage(new DtcNotification(new("AA11BB"), new DtcInfo(new DTC(DTCEnumerations.Type.VOLTAGE_BELOW_MIN, DTCEnumerations.Source.BACKUP_BATTERY, 10), 35689, true, false, true)), TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(0, eventFired);
|
||||
|
||||
@@ -499,7 +500,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
GetDtcStatusResult dtc = new(new("AA11BB"));
|
||||
dtc.DTCs.Add(new DtcInfo(new DTC(DTCEnumerations.Type.VOLTAGE_BELOW_MIN, DTCEnumerations.Source.BACKUP_BATTERY, 10), 35689, true, false, true));
|
||||
|
||||
device.HandleMessage(dtc, _token).Wait();
|
||||
device.HandleMessage(dtc, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(0, eventFired);
|
||||
|
||||
@@ -528,7 +529,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
|
||||
int eventFired = 0;
|
||||
device.DeviceChanged += (s, e) => { eventFired++; };
|
||||
device.HandleMessage(new ClearDtcResult(new DeviceId("AA11BB"), Status.OK), _token).Wait();
|
||||
device.HandleMessage(new ClearDtcResult(new DeviceId("AA11BB"), Status.OK), TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(1, eventFired);
|
||||
|
||||
@@ -546,10 +547,10 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
|
||||
Assert.IsNotNull(_dbContextFactory);
|
||||
using ACSDatabaseContext context = _dbContextFactory.CreateDbContext();
|
||||
Assert.AreEqual(1, context.Loggings.Count());
|
||||
List<Logging> logs = context.Loggings.Include(d => d.Device).ToList();
|
||||
Assert.IsNotNull(logs);
|
||||
Assert.AreEqual("device Status (OK)", logs[0].Message);
|
||||
Assert.AreEqual(0, context.Loggings.Count());
|
||||
//List<Logging> logs = context.Loggings.Include(d => d.Device).ToList();
|
||||
//Assert.IsNotNull(logs);
|
||||
//Assert.AreEqual("device Status (OK)", logs[0].Message);
|
||||
}
|
||||
|
||||
//[TestMethod]
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -167,7 +167,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
Assert.IsNotNull(_logger);
|
||||
Assert.HasCount(3, _logger.Messages);
|
||||
Assert.AreEqual("Warning - 64.226.1.0:1234 - ABDCEDFG - Connected", _logger.Messages[0]);
|
||||
Assert.AreEqual("Error - 64.226.1.0 - ABDCEDFG => Exception: System.Exception: Exception\r\n at Aperio_Control_Centre.AperioServer.TestingAperioConnectionContext.Receive(CancellationTokenSource linkedCts) in D:\\Visual Studio Projecten\\Aperio_Control_Centre\\Aperio_Control_Centre.UnitTest\\AperioServer\\Setups\\TestingAperioConnectionContext.cs:line 81\r\n at Aperio_Control_Centre.AperioServer.AperioConnectionHandler.OnConnectedAsync(ConnectionContext connection) in D:\\Visual Studio Projecten\\Aperio_Control_Centre\\Aperio_Control_Centre\\AperioServer\\AperioConnectionHandler.cs:line 71", _logger.Messages[1]);
|
||||
Assert.AreEqual("Error - 64.226.1.0 - ABDCEDFG => Exception: System.Exception: Exception\r\n at Aperio_Control_Centre.AperioServer.TestingAperioConnectionContext.Receive(CancellationTokenSource linkedCts) in D:\\Visual Studio Projecten\\Aperio_Control_Centre\\Aperio_Control_Centre.UnitTest\\AperioServer\\Setups\\TestingAperioConnectionContext.cs:line 80\r\n at Aperio_Control_Centre.AperioServer.AperioConnectionHandler.OnConnectedAsync(ConnectionContext connection) in D:\\Visual Studio Projecten\\Aperio_Control_Centre\\Aperio_Control_Centre\\AperioServer\\AperioConnectionHandler.cs:line 71", _logger.Messages[1]);
|
||||
Assert.AreEqual("Warning - 64.226.1.0 - ABDCEDFG - Connection closed, connected for ??", _logger.Messages[2]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
_logger = new TestingLogger<AperioDoor>();
|
||||
|
||||
AperioDoor door = new(_screenLogging, _statusBroadcast, _dbContextFactory, CreateAperioServerOptions(), _logger);
|
||||
door.SetBaseDevice(new("AA11BB"), _aperioConnectionContext, _token).Wait();
|
||||
door.SetBaseDevice(new("AA11BB"), _aperioConnectionContext, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
//Assert.AreEqual(Enumerations.DoorMode.UNKNOWN, door.GetDoorMode());
|
||||
Assert.AreEqual(DoorState.UNKNOWN, door.DoorState);
|
||||
@@ -125,7 +125,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
|
||||
int eventFired = 0;
|
||||
device.DeviceChanged += (s, e) => { eventFired++; };
|
||||
device.HandleMessage(new DoorStateNotification(new("AA11BB"), DoorState.CLOSED), _token).Wait();
|
||||
device.HandleMessage(new DoorStateNotification(new("AA11BB"), DoorState.CLOSED), TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(1, eventFired);
|
||||
|
||||
@@ -161,7 +161,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
|
||||
int eventFired = 0;
|
||||
device.DeviceChanged += (s, e) => { eventFired++; };
|
||||
device.HandleMessage(new LockStateNotification(new("AA11BB"), LockState.JAMMED), _token).Wait();
|
||||
device.HandleMessage(new LockStateNotification(new("AA11BB"), LockState.JAMMED), TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(1, eventFired);
|
||||
|
||||
@@ -204,9 +204,9 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
|
||||
int eventFired = 0;
|
||||
device.DeviceChanged += (s, e) => { eventFired++; };
|
||||
device.HandleMessage(new DoorModeNotification(new("AA11BB"), DoorMode.INSIDEOUT_LOCKED), _token).Wait();
|
||||
device.HandleMessage(new DoorModeNotification(new("AA11BB"), DoorMode.INSIDEOUT_LOCKED), TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(0, eventFired);
|
||||
Assert.AreEqual(1, eventFired);
|
||||
|
||||
Assert.AreEqual(DoorMode.INSIDEOUT_LOCKED, device.GetDoorMode());
|
||||
|
||||
@@ -229,9 +229,9 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
|
||||
int eventFired = 0;
|
||||
device.DeviceChanged += (s, e) => { eventFired++; };
|
||||
device.HandleMessage(new GetSupportedDoorModesResult(new("AA11BB"), modes), _token).Wait();
|
||||
device.HandleMessage(new GetSupportedDoorModesResult(new("AA11BB"), modes), TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(0, eventFired);
|
||||
Assert.AreEqual(1, eventFired);
|
||||
|
||||
Assert.AreEqual(DoorMode.UNKNOWN, device.GetDoorMode());
|
||||
|
||||
@@ -258,7 +258,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
|
||||
CredentialNotification notification = new();
|
||||
|
||||
device.CredentialRequest(notification, "1234", _token).Wait(_token);
|
||||
device.CredentialRequest(notification, "1234", TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.IsNotNull(_aperioConnectionContext);
|
||||
Assert.HasCount(1, _aperioConnectionContext.DeviceWrites);
|
||||
@@ -290,7 +290,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
new CredentialBlock(CredentialBlockType.MIFAREUID, [0x00, 0x00])
|
||||
]);
|
||||
|
||||
device.CredentialRequest(notification, "1234", _token).Wait(_token);
|
||||
device.CredentialRequest(notification, "1234", TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.IsNotNull(_aperioConnectionContext);
|
||||
Assert.HasCount(1, _aperioConnectionContext.DeviceWrites);
|
||||
@@ -322,7 +322,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
new CredentialBlock(CredentialBlockType.MIFAREUID, [0x00, 0x00])
|
||||
]);
|
||||
|
||||
device.CredentialRequest(notification, "1234", _token).Wait(_token);
|
||||
device.CredentialRequest(notification, "1234", TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.IsNotNull(_aperioConnectionContext);
|
||||
Assert.HasCount(1, _aperioConnectionContext.DeviceWrites);
|
||||
@@ -355,7 +355,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
new CredentialBlock(CredentialBlockType.MIFAREUID, [0x00, 0x00])
|
||||
]);
|
||||
|
||||
device.HandleMessage(notification, _token).Wait();
|
||||
device.HandleMessage(notification, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.IsNotNull(_aperioConnectionContext);
|
||||
Assert.HasCount(1, _aperioConnectionContext.DeviceWrites);
|
||||
@@ -435,7 +435,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
|
||||
int eventFired = 0;
|
||||
device.DeviceChanged += (s, e) => { eventFired++; };
|
||||
device.HandleMessage(new DoorStateResult(new("AA11BB"), DoorState.OPEN), _token).Wait();
|
||||
device.HandleMessage(new DoorStateResult(new("AA11BB"), DoorState.OPEN), TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(1, eventFired);
|
||||
|
||||
@@ -470,7 +470,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
|
||||
int eventFired = 0;
|
||||
device.DeviceChanged += (s, e) => { eventFired++; };
|
||||
device.HandleMessage(new DoorStateNotification(new("AA11BB"), DoorState.CLOSED), _token).Wait();
|
||||
device.HandleMessage(new DoorStateNotification(new("AA11BB"), DoorState.CLOSED), TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(1, eventFired);
|
||||
|
||||
@@ -507,7 +507,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
|
||||
int eventFired = 0;
|
||||
device.DeviceChanged += (s, e) => { eventFired++; };
|
||||
device.HandleMessage(new LockStateResult(new("AA11BB"), LockState.LOCKED), _token).Wait();
|
||||
device.HandleMessage(new LockStateResult(new("AA11BB"), LockState.LOCKED), TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(1, eventFired);
|
||||
|
||||
@@ -543,7 +543,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
|
||||
int eventFired = 0;
|
||||
device.DeviceChanged += (s, e) => { eventFired++; };
|
||||
device.HandleMessage(new LockStateNotification(new("AA11BB"), LockState.JAMMED), _token).Wait();
|
||||
device.HandleMessage(new LockStateNotification(new("AA11BB"), LockState.JAMMED), TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(1, eventFired);
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
_logger = new TestingLogger<AperioHubDevice>();
|
||||
|
||||
using AperioHubDevice hubDevice = new(_screenLogging, _statusBroadcast, _dbContextFactory, CreateAperioServerOptions(), _logger);
|
||||
hubDevice.SetDevice(new("AA99BB"), _aperioConnectionContext, _token).Wait();
|
||||
hubDevice.SetDevice(new("AA99BB"), _aperioConnectionContext, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual("AA99BB", hubDevice.Id);
|
||||
Assert.AreNotEqual(0, hubDevice.LastData.Ticks);
|
||||
@@ -88,7 +88,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
// Device = new("AA11BB"),
|
||||
// Time = new Time(new DateTime(2025, 9, 1)),
|
||||
//}, _token).Wait();
|
||||
device.HandleMessage(new TimeNotification(new DeviceId("AA11BB"), new Time(new DateTime(2025, 9, 1))), _token).Wait();
|
||||
device.HandleMessage(new TimeNotification(new DeviceId("AA11BB"), new Time(new DateTime(2025, 9, 1))), TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(0, eventFired);
|
||||
|
||||
@@ -122,7 +122,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
// Device = new("AA11BB"),
|
||||
// Result = Status.FAIL_PERMISSION
|
||||
//}, _token).Wait();
|
||||
device.HandleMessage(new SetTimeResult(new DeviceId("AA11BB"), Status.FAIL_PERMISSION), _token).Wait();
|
||||
device.HandleMessage(new SetTimeResult(new DeviceId("AA11BB"), Status.FAIL_PERMISSION), TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(0, eventFired);
|
||||
|
||||
@@ -158,7 +158,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
// Device = new("AA11BB"),
|
||||
// Time = new Time(new DateTime(2025, 9, 1))
|
||||
//}, _token).Wait();
|
||||
device.HandleMessage(new GetTimeResult(new DeviceId("AA11BB"), new Time(new DateTime(2025, 9, 1))), _token).Wait();
|
||||
device.HandleMessage(new GetTimeResult(new DeviceId("AA11BB"), new Time(new DateTime(2025, 9, 1))), TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(0, eventFired);
|
||||
|
||||
@@ -188,7 +188,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
|
||||
int eventFired = 0;
|
||||
device.DeviceChanged += (s, e) => { eventFired++; };
|
||||
device.GetDeviceTimeFromDevice(_token).Wait();
|
||||
device.GetDeviceTimeFromDevice(TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(0, eventFired);
|
||||
|
||||
@@ -217,7 +217,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
|
||||
int eventFired = 0;
|
||||
device.DeviceChanged += (s, e) => { eventFired++; };
|
||||
device.SetDeviceTimeOnDevice(_token).Wait();
|
||||
device.SetDeviceTimeOnDevice(TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(0, eventFired);
|
||||
|
||||
@@ -247,7 +247,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
|
||||
int eventFired = 0;
|
||||
device.DeviceChanged += (s, e) => { eventFired++; };
|
||||
device.GetStatusFromDevice(_token).Wait();
|
||||
device.GetStatusFromDevice(TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(0, eventFired);
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
_logger = new TestingLogger<AperioLockDevice>();
|
||||
|
||||
AperioLockDevice lockDevice = new(_screenLogging, _statusBroadcast, _dbContextFactory, CreateAperioServerOptions(), _logger);
|
||||
lockDevice.SetDevice(new("AA1234"), new("445566"), _aperioConnectionContext, _token).Wait();
|
||||
lockDevice.SetDevice(new("AA1234"), new("445566"), _aperioConnectionContext, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual("AA1234", lockDevice.Id);
|
||||
Assert.AreEqual("445566", lockDevice.HubDeviceId.ToIdString());
|
||||
@@ -115,7 +115,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
Assert.IsNotNull(_logger);
|
||||
|
||||
device = new(_screenLogging, _statusBroadcast, _dbContextFactory, CreateAperioServerOptions(), _logger);
|
||||
device.SetDevice(new("AA11BB"), new("FFEECC"), _aperioConnectionContext, _token).Wait();
|
||||
device.SetDevice(new("AA11BB"), new("FFEECC"), _aperioConnectionContext, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.IsNotNull(device.Connection);
|
||||
|
||||
@@ -151,7 +151,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
|
||||
int eventFired = 0;
|
||||
device.DeviceChanged += (s, e) => { eventFired++; };
|
||||
device.SetBatteryState(BatteryStates.Low, _token).Wait();
|
||||
device.SetBatteryState(BatteryStates.Low, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(1, eventFired);
|
||||
|
||||
@@ -224,12 +224,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
|
||||
int eventFired = 0;
|
||||
device.DeviceChanged += (s, e) => { eventFired++; };
|
||||
//device.HandleMessage(new KeyCylinderStateNotification()
|
||||
//{
|
||||
// DeviceGroupId = new("AA11BB"),
|
||||
// State = KeyCylinderState.USED
|
||||
//}, _token).Wait();
|
||||
device.HandleMessage(new KeyCylinderStateNotification(new Id("AA11BB"), KeyCylinderState.USED), _token).Wait();
|
||||
device.HandleMessage(new KeyCylinderStateNotification(new Id("AA11BB"), KeyCylinderState.USED), TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(1, eventFired);
|
||||
|
||||
@@ -266,12 +261,8 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
|
||||
int eventFired = 0;
|
||||
device.DeviceChanged += (s, e) => { eventFired++; };
|
||||
//device.HandleMessage(new HandleStateNotification()
|
||||
//{
|
||||
// DeviceGroupId = new("AA11BB"),
|
||||
// State = HandleState.BOTH_USED
|
||||
//}, _token).Wait();
|
||||
device.HandleMessage(new HandleStateNotification(new Id("AA11BB"), HandleState.BOTH_USED), _token).Wait();
|
||||
|
||||
device.HandleMessage(new HandleStateNotification(new Id("AA11BB"), HandleState.BOTH_USED), TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(1, eventFired);
|
||||
|
||||
@@ -290,13 +281,12 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
Assert.IsNotNull(_dbContextFactory);
|
||||
ACSDatabaseContext context = _dbContextFactory.CreateDbContext();
|
||||
|
||||
Assert.AreEqual(1, context.Loggings.Count());
|
||||
Assert.AreEqual(0, context.Loggings.Count());
|
||||
|
||||
List<Logging> logs = context.Loggings.Include(d => d.Device).ToList();
|
||||
Assert.IsNotNull(logs);
|
||||
Assert.AreEqual("HandleState (BOTH_USED)", logs[0].Message);
|
||||
|
||||
Assert.AreEqual(HandleState.BOTH_USED, logs[0].Device?.HandleState);
|
||||
//List<Logging> logs = context.Loggings.Include(d => d.Device).ToList();
|
||||
//Assert.IsNotNull(logs);
|
||||
//Assert.AreEqual("HandleState (BOTH_USED)", logs[0].Message);
|
||||
//Assert.AreEqual(HandleState.BOTH_USED, logs[0].Device?.HandleState);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -308,12 +298,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
|
||||
int eventFired = 0;
|
||||
device.DeviceChanged += (s, e) => { eventFired++; };
|
||||
//device.HandleMessage(new GetAuditTrailResult()
|
||||
//{
|
||||
// Device = new("AA11BB"),
|
||||
// Result = Status.OK
|
||||
//}, _token).Wait();
|
||||
device.HandleMessage(new GetAuditTrailResult(new DeviceId("AA11BB"), Status.OK), _token).Wait();
|
||||
device.HandleMessage(new GetAuditTrailResult(new DeviceId("AA11BB"), Status.OK), TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(1, eventFired);
|
||||
|
||||
@@ -332,11 +317,11 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
Assert.IsNotNull(_dbContextFactory);
|
||||
using ACSDatabaseContext context = _dbContextFactory.CreateDbContext();
|
||||
|
||||
Assert.AreEqual(1, context.Loggings.Count());
|
||||
Assert.AreEqual(0, context.Loggings.Count());
|
||||
|
||||
List<Logging> logs = context.Loggings.Include(d => d.Device).ToList();
|
||||
Assert.IsNotNull(logs);
|
||||
Assert.AreEqual("device Status (OK)", logs[0].Message);
|
||||
//List<Logging> logs = context.Loggings.Include(d => d.Device).ToList();
|
||||
//Assert.IsNotNull(logs);
|
||||
//Assert.AreEqual("device Status (OK)", logs[0].Message);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -348,16 +333,8 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
|
||||
int eventFired = 0;
|
||||
device.DeviceChanged += (s, e) => { eventFired++; };
|
||||
//device.HandleMessage(new AuditTrailNotification()
|
||||
//{
|
||||
// Device = new("AA11BB"),
|
||||
// TimeStamp = new(0),
|
||||
// AccessDecision = AccessDecision.DENIED,
|
||||
// MessageType = AuditTrailMessageType.AUDIT_TRAIL_ITEM,
|
||||
// //Credential = [new(CredentialBlockType.MIFAREUID, [0x00, 0x01, 0x02])],
|
||||
// PacketSequence = new()
|
||||
//}, _token).Wait();
|
||||
device.HandleMessage(new AuditTrailNotification(new DeviceId("AA11BB"), new PacketSequenceNumber(), AuditTrailMessageType.AUDIT_TRAIL_ITEM, new TimeStamp(), AccessDecision.DENIED), _token).Wait();
|
||||
|
||||
device.HandleMessage(new AuditTrailNotification(new DeviceId("AA11BB"), new PacketSequenceNumber(), AuditTrailMessageType.AUDIT_TRAIL_ITEM, new TimeStamp(), AccessDecision.DENIED), TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(0, eventFired);
|
||||
|
||||
@@ -390,7 +367,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
|
||||
int eventFired = 0;
|
||||
device.DeviceChanged += (s, e) => { eventFired++; };
|
||||
device.GetStatusFromDevice(_token).Wait();
|
||||
device.GetStatusFromDevice(TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(0, eventFired);
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
_aperioConnectionContext.Features.Set<IScreenLoggerBridge>(_screenLogging);
|
||||
|
||||
AperioOptaDevice optaDevice = new(_screenLogging, _statusBroadcast, _dbContextFactory, CreateAperioServerOptions(), _logger);
|
||||
optaDevice.SetDevice(_deviceDefinition.DeviceIdentity, _aperioConnectionContext, _token).Wait();
|
||||
optaDevice.SetDevice(_deviceDefinition.DeviceIdentity, _aperioConnectionContext, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual("0412F5", optaDevice.Id);
|
||||
Assert.AreNotEqual(0, optaDevice.LastData.Ticks);
|
||||
@@ -101,7 +101,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
Assert.IsNotNull(_logger);
|
||||
|
||||
AperioOptaDevice device = new(_screenLogging, _statusBroadcast, _dbContextFactory, CreateAperioServerOptions(), _logger);
|
||||
device.SetDevice(new("DEAD00"), _aperioConnectionContext, _token).Wait();
|
||||
device.SetDevice(new("DEAD00"), _aperioConnectionContext, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual("DEAD00", device.Id);
|
||||
Assert.IsNotNull(device.Connection);
|
||||
@@ -157,7 +157,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
{
|
||||
eventFired++;
|
||||
};
|
||||
device.HandleMessage(new ActivatorStateNotification(new("AA11BB"), activatorInfo), _token).Wait();
|
||||
device.HandleMessage(new ActivatorStateNotification(new("AA11BB"), activatorInfo), TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(0, eventFired);
|
||||
|
||||
@@ -208,7 +208,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
{
|
||||
eventFired++;
|
||||
};
|
||||
device.HandleMessage(new ActivatorStateNotification(new("AA11BB"), activatorInfo), _token).Wait();
|
||||
device.HandleMessage(new ActivatorStateNotification(new("AA11BB"), activatorInfo), TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(0, eventFired);
|
||||
|
||||
@@ -258,7 +258,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
{
|
||||
eventFired++;
|
||||
};
|
||||
device.HandleMessage(new ActivatorStateNotification(new("AA11BB"), activatorInfo), _token).Wait();
|
||||
device.HandleMessage(new ActivatorStateNotification(new("AA11BB"), activatorInfo), TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(0, eventFired);
|
||||
|
||||
@@ -295,7 +295,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
|
||||
int eventFired = 0;
|
||||
device.DeviceChanged += (s, e) => { eventFired++; };
|
||||
device.GetStatusFromDevice(_token).Wait();
|
||||
device.GetStatusFromDevice(TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(0, eventFired);
|
||||
|
||||
|
||||
@@ -3,53 +3,23 @@ using Aperio_Control_Centre.ACSDatabase;
|
||||
using Aperio_Control_Centre.ACSDatabase.Models;
|
||||
using Aperio_Control_Centre.ACSDatabase.Types;
|
||||
using Aperio_Control_Centre.AperioServer;
|
||||
using Aperio_Control_Centre.AperioServer.Devices;
|
||||
using Aperio_Control_Centre.ScreenLogging;
|
||||
using Aperio_Control_Centre.StatusBroadcast;
|
||||
using Aperio_Control_Centre.UnitTest.AperioServer.Setups;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Moq;
|
||||
using System.Net;
|
||||
|
||||
namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
{
|
||||
[TestClass]
|
||||
public class AperioTestSetup
|
||||
{
|
||||
//private protected IDbContextFactory<ACSDatabaseContext>? _dbContextFactory;
|
||||
|
||||
//private protected Mock<ConnectionContext> _connectionMoq = new();
|
||||
//private protected TestingAperioConnectionContext? _aperioConnectionContext;
|
||||
|
||||
//private protected ILogger<AperioDeviceList>? _deviceListLogger;
|
||||
|
||||
//private protected TestingScreenLoggerBridge? _screenLogging;
|
||||
//private protected TestingStatusBroadcastHandler? _statusBroadcast;
|
||||
|
||||
//private protected AperioDeviceList? _devicesList;
|
||||
|
||||
//private protected IOptions<ACSOptions>? _options;
|
||||
public required TestContext TestContext { get; set; }
|
||||
|
||||
private protected CancellationTokenSource _cts = new();
|
||||
private protected CancellationToken _token;
|
||||
|
||||
//private static readonly Dictionary<string, string?> inMemorySettings = new()
|
||||
// {
|
||||
// { "ACS:UseAuthorization", "false" }
|
||||
// };
|
||||
//private readonly IConfiguration configuration = new ConfigurationBuilder()
|
||||
// .AddInMemoryCollection(inMemorySettings)
|
||||
// .Build();
|
||||
|
||||
|
||||
public IDbContextFactory<ACSDatabaseContext> CreateDataBaseFactory()
|
||||
public static IDbContextFactory<ACSDatabaseContext> CreateDataBaseFactory()
|
||||
{
|
||||
//Runs before each test. (Optional)
|
||||
Guid jitter = Guid.NewGuid();
|
||||
string databasename = $"TestDb{jitter}";
|
||||
DbContextOptions<ACSDatabaseContext> dbOptions = new DbContextOptionsBuilder<ACSDatabaseContext>()
|
||||
@@ -67,10 +37,8 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
return mockDbFactory.Object;
|
||||
}
|
||||
|
||||
public IAperioConnectionContext CreateAperioConnectionContext(IScreenLoggerBridge screenLogger)
|
||||
public static IAperioConnectionContext CreateAperioConnectionContext(IScreenLoggerBridge screenLogger)
|
||||
{
|
||||
//string connectionid = "ABDCEDFG";
|
||||
|
||||
var connectionMoq = new Mock<ConnectionContext>();
|
||||
|
||||
connectionMoq.SetupProperty(p => p.ConnectionId, "ABDCEDFG");
|
||||
@@ -86,14 +54,11 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
|
||||
TestingAperioConnectionContext aperioConnectionContext = new();
|
||||
aperioConnectionContext.SetConnection(connectionMoq.Object);
|
||||
//_aperioConnectionContext = new TestingAperioConnectionContext();
|
||||
//_aperioConnectionContext = new AperioConnectionContext();
|
||||
//_aperioConnectionContext.SetConnection(_connectionMoq.Object);
|
||||
|
||||
return aperioConnectionContext;
|
||||
}
|
||||
|
||||
public IOptions<AperioServerOptions> CreateAperioServerOptions()
|
||||
public static IOptions<AperioServerOptions> CreateAperioServerOptions()
|
||||
{
|
||||
var options = Options.Create<AperioServerOptions>(new AperioServerOptions()
|
||||
{
|
||||
@@ -102,68 +67,6 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
return options;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//[TestInitialize]
|
||||
//public void Setup()
|
||||
//{
|
||||
// //Runs before each test. (Optional)
|
||||
// Guid jitter = Guid.NewGuid();
|
||||
// DbContextOptions<ACSDatabaseContext> dbOptions = new DbContextOptionsBuilder<ACSDatabaseContext>()
|
||||
// .UseInMemoryDatabase(databaseName: $"TestDb{jitter}")
|
||||
// .Options;
|
||||
|
||||
// Mock<IDbContextFactory<ACSDatabaseContext>> mockDbFactory = new();
|
||||
// mockDbFactory.Setup(f => f.CreateDbContext())
|
||||
// .Returns(() => new ACSDatabaseContext(dbOptions));
|
||||
// mockDbFactory.Setup(f => f.CreateDbContextAsync(It.IsAny<CancellationToken>()))
|
||||
// .ReturnsAsync(() => new ACSDatabaseContext(dbOptions));
|
||||
|
||||
// SeedDatabase(mockDbFactory.Object.CreateDbContext());
|
||||
|
||||
// //_dbContextFactory = mockDbFactory.Object;
|
||||
// //_deviceListLogger = Mock.Of<ILogger<AperioDeviceList>>();
|
||||
|
||||
// //_screenLogging = new TestingScreenLoggerBridge();
|
||||
// //_statusBroadcast = new TestingStatusBroadcastHandler();
|
||||
|
||||
// //_connectionMoq = new Mock<ConnectionContext>();
|
||||
// //_ = _connectionMoq.Setup(s => s.RemoteEndPoint).Returns(new IPEndPoint(IPAddress.Parse("64.226.1.0"), 1234));
|
||||
// //_ = _connectionMoq.Setup(s => s.Transport.Output.WriteAsync(It.IsAny<ReadOnlyMemory<byte>>(), It.IsAny<CancellationToken>()));
|
||||
// //_ = _connectionMoq.Setup(s => s.Features.Get<TestingScreenLoggerBridge>()).Returns(_screenLogging);
|
||||
|
||||
// //_aperioConnectionContext = new TestingAperioConnectionContext();
|
||||
// //_aperioConnectionContext.SetConnection(_connectionMoq.Object);
|
||||
// //_aperioConnectionContext = new TestingAperioConnectionContext();
|
||||
// //_aperioConnectionContext = new AperioConnectionContext();
|
||||
// //_aperioConnectionContext.SetConnection(_connectionMoq.Object);
|
||||
|
||||
// //_options = Options.Create();
|
||||
// //_options = Options.Create<ACSOptions>(new ACSOptions()
|
||||
// //{
|
||||
// // SectorKey = "SECTORKEY"
|
||||
// //});
|
||||
|
||||
// //ServiceCollection services = new();
|
||||
// //services.AddTransient<AperioHubDevice>();
|
||||
// //services.AddTransient<AperioLockDevice>();
|
||||
// //services.AddTransient<AperioOptaDevice>();
|
||||
// //services.AddSingleton<IScreenLoggerBridge>(_screenLogging);
|
||||
// //services.AddSingleton<IStatusBroadcastHandler>(_statusBroadcast);
|
||||
// //services.AddDbContextFactory<ACSDatabaseContext>(o =>
|
||||
// //{
|
||||
// // o.UseInMemoryDatabase(databaseName: $"TestDb{jitter}");
|
||||
// //});
|
||||
// //services.Configure<ACSOptions>(o => o = _options.Value);
|
||||
// ////services.ConfigureOptions<ACSOptions>(options);
|
||||
|
||||
// ///ServiceProvider serviceProvider = services.BuildServiceProvider();
|
||||
|
||||
// //_devicesList = new(serviceProvider, _deviceListLogger, _screenLogging);
|
||||
//}
|
||||
|
||||
private static void SeedDatabase(ACSDatabaseContext dbContext)
|
||||
{
|
||||
dbContext.Devices.Add(new Device()
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
|
||||
int eventFired = 0;
|
||||
deviceList.DeviceListChanged += (s, e) => { eventFired++; };
|
||||
deviceList.RemoveDevice(new Id("bla"), _token).Wait();
|
||||
deviceList.RemoveDevice(new Id("bla"), TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(0, eventFired);
|
||||
|
||||
@@ -84,7 +84,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
|
||||
int eventFired = 0;
|
||||
deviceList.DeviceListChanged += (s, e) => { eventFired++; };
|
||||
deviceList.AddOrUpdateDevice(deviceDefinition, aperioConnectionContext, _token).Wait();
|
||||
deviceList.AddOrUpdateDevice(deviceDefinition, aperioConnectionContext, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(1, eventFired);
|
||||
|
||||
@@ -110,7 +110,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
|
||||
int eventFired = 0;
|
||||
deviceList.DeviceListChanged += (s, e) => { eventFired++; };
|
||||
deviceList.AddOrUpdateDevice(deviceDefinition, aperioConnectionContext, _token).Wait();
|
||||
deviceList.AddOrUpdateDevice(deviceDefinition, aperioConnectionContext, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(1, eventFired);
|
||||
|
||||
@@ -136,7 +136,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
|
||||
int eventFired = 0;
|
||||
deviceList.DeviceListChanged += (s, e) => { eventFired++; };
|
||||
deviceList.AddOrUpdateDevice(deviceDefinition, aperioConnectionContext, _token).Wait();
|
||||
deviceList.AddOrUpdateDevice(deviceDefinition, aperioConnectionContext, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(1, eventFired);
|
||||
|
||||
@@ -164,7 +164,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
|
||||
int eventFired = 0;
|
||||
deviceList.DeviceListChanged += (s, e) => { eventFired++; };
|
||||
deviceList.AddOrUpdateDevice(deviceDefinition, aperioConnectionContext, _token).Wait();
|
||||
deviceList.AddOrUpdateDevice(deviceDefinition, aperioConnectionContext, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(1, eventFired);
|
||||
Assert.AreEqual(1, deviceList.GetConnections().Count());
|
||||
@@ -184,7 +184,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
aperioConnectionContext = CreateAperioConnectionContext(_screenLogging);
|
||||
aperioConnectionContext.ConnectionId = "987654321";
|
||||
eventFired = 0;
|
||||
deviceList.AddOrUpdateDevice(deviceDefinition, aperioConnectionContext, _token).Wait();
|
||||
deviceList.AddOrUpdateDevice(deviceDefinition, aperioConnectionContext, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(1, eventFired);
|
||||
Assert.AreEqual(1, deviceList.GetConnections().Count());
|
||||
@@ -213,7 +213,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
|
||||
//remove device
|
||||
eventFired = 0;
|
||||
deviceList.RemoveDevice(new Id("AA11BB"), _token).Wait();
|
||||
deviceList.RemoveDevice(new Id("AA11BB"), TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(1, eventFired);
|
||||
Assert.AreEqual(0, deviceList.GetConnections().Count());
|
||||
@@ -234,7 +234,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
|
||||
int eventFired = 0;
|
||||
deviceList.DeviceListChanged += (s, e) => { eventFired++; };
|
||||
deviceList.AddOrUpdateDevice(deviceDefinition, aperioConnectionContext, _token).Wait();
|
||||
deviceList.AddOrUpdateDevice(deviceDefinition, aperioConnectionContext, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(1, eventFired);
|
||||
Assert.AreEqual(1, deviceList.GetConnections().Count());
|
||||
@@ -254,7 +254,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
eventFired = 0;
|
||||
aperioConnectionContext = CreateAperioConnectionContext(_screenLogging);
|
||||
aperioConnectionContext.ConnectionId = "987654321";
|
||||
deviceList.AddOrUpdateDevice(deviceDefinition, aperioConnectionContext, _token).Wait();
|
||||
deviceList.AddOrUpdateDevice(deviceDefinition, aperioConnectionContext, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
device = deviceList.GetDevice(new Id("0392BC"));
|
||||
Assert.IsNotNull(device);
|
||||
@@ -278,7 +278,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
|
||||
//------- remove hub ----------------
|
||||
eventFired = 0;
|
||||
deviceList.RemoveDevice(new Id("0392BC"), _token).Wait();
|
||||
deviceList.RemoveDevice(new Id("0392BC"), TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(1, eventFired);
|
||||
|
||||
@@ -300,7 +300,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
|
||||
int eventFired = 0;
|
||||
deviceList.DeviceListChanged += (s, e) => { eventFired++; };
|
||||
deviceList.AddOrUpdateDevice(deviceDefinition, aperioConnectionContext, _token).Wait();
|
||||
deviceList.AddOrUpdateDevice(deviceDefinition, aperioConnectionContext, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(1, eventFired);
|
||||
Assert.AreEqual(1, deviceList.GetConnections().Count());
|
||||
@@ -320,7 +320,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
eventFired = 0;
|
||||
aperioConnectionContext = CreateAperioConnectionContext(_screenLogging);
|
||||
aperioConnectionContext.ConnectionId = "987654321";
|
||||
deviceList.AddOrUpdateDevice(deviceDefinition, aperioConnectionContext, _token).Wait();
|
||||
deviceList.AddOrUpdateDevice(deviceDefinition, aperioConnectionContext, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
device = deviceList.GetDevice(new Id("0392BC"));
|
||||
Assert.IsNotNull(device);
|
||||
@@ -344,7 +344,7 @@ namespace Aperio_Control_Centre.UnitTest.AperioServer
|
||||
|
||||
//------- remove opta ----------------
|
||||
eventFired = 0;
|
||||
deviceList.RemoveDevice(new Id("0392BC"), _token).Wait();
|
||||
deviceList.RemoveDevice(new Id("0392BC"), TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.AreEqual(1, eventFired);
|
||||
Assert.AreEqual(0, deviceList.GetConnections().Count());
|
||||
|
||||
@@ -10,6 +10,8 @@ namespace Aperio_Control_Centre.UnitTest.ApiTest
|
||||
[TestClass]
|
||||
public class AddLog_Test : ApiTestSetup
|
||||
{
|
||||
public TestContext TestContext { get; set; }
|
||||
|
||||
[TestMethod]
|
||||
public void AddLog_UndifinedProductclass()
|
||||
{
|
||||
@@ -213,7 +215,7 @@ namespace Aperio_Control_Centre.UnitTest.ApiTest
|
||||
Task.Run(async () =>
|
||||
{
|
||||
result = await _apiController.AddLog(requestModel, _token);
|
||||
}).Wait();
|
||||
}, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
//json result
|
||||
Assert.IsNotNull(result);
|
||||
|
||||
@@ -8,6 +8,8 @@ namespace Aperio_Control_Centre.UnitTest.ApiTest
|
||||
[TestClass]
|
||||
public class UnlockTime_Test : ApiTestSetup
|
||||
{
|
||||
public TestContext TestContext { get; set; }
|
||||
|
||||
[TestMethod]
|
||||
public void UnlockTime_NewDevice()
|
||||
{
|
||||
@@ -26,7 +28,7 @@ namespace Aperio_Control_Centre.UnitTest.ApiTest
|
||||
{
|
||||
time = await apiDevice.GetUnlockTime(db, _token);
|
||||
}
|
||||
}).GetAwaiter().GetResult();
|
||||
}, TestContext.CancellationToken).GetAwaiter().GetResult();
|
||||
|
||||
Assert.IsNotNull(apiDevice);
|
||||
|
||||
@@ -62,7 +64,7 @@ namespace Aperio_Control_Centre.UnitTest.ApiTest
|
||||
{
|
||||
time = await apiDevice.GetUnlockTime(db, _token);
|
||||
}
|
||||
}).GetAwaiter().GetResult();
|
||||
}, TestContext.CancellationToken).GetAwaiter().GetResult();
|
||||
|
||||
Assert.IsNotNull(apiDevice);
|
||||
|
||||
@@ -98,7 +100,7 @@ namespace Aperio_Control_Centre.UnitTest.ApiTest
|
||||
{
|
||||
time = await apiDevice.GetUnlockTime(db, _token);
|
||||
}
|
||||
}).GetAwaiter().GetResult();
|
||||
}, TestContext.CancellationToken).GetAwaiter().GetResult();
|
||||
|
||||
Assert.IsNotNull(apiDevice);
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@ namespace Aperio_Control_Centre.UnitTest.CredentialChecker
|
||||
[TestClass]
|
||||
public class CheckAuthorization_Test : CredentialCheckerSetup
|
||||
{
|
||||
public TestContext TestContext { get; set; }
|
||||
|
||||
[TestMethod]
|
||||
public void CheckAuthorization_NoUserGroup()
|
||||
{
|
||||
@@ -31,7 +33,7 @@ namespace Aperio_Control_Centre.UnitTest.CredentialChecker
|
||||
Task.Run(async () =>
|
||||
{
|
||||
success = await checker.CheckAuthorization(token);
|
||||
}).Wait();
|
||||
}, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.IsFalse(success);
|
||||
|
||||
@@ -76,7 +78,7 @@ namespace Aperio_Control_Centre.UnitTest.CredentialChecker
|
||||
Task.Run(async () =>
|
||||
{
|
||||
success = await checker.CheckAuthorization(token);
|
||||
}).Wait();
|
||||
}, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.IsFalse(success);
|
||||
|
||||
@@ -120,7 +122,7 @@ namespace Aperio_Control_Centre.UnitTest.CredentialChecker
|
||||
Task.Run(async () =>
|
||||
{
|
||||
success = await checker.CheckAuthorization(token);
|
||||
}).Wait();
|
||||
}, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.IsFalse(success);
|
||||
|
||||
@@ -164,7 +166,7 @@ namespace Aperio_Control_Centre.UnitTest.CredentialChecker
|
||||
Task.Run(async () =>
|
||||
{
|
||||
success = await checker.CheckAuthorization(token);
|
||||
}).Wait();
|
||||
}, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.IsTrue(success);
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@ namespace Aperio_Control_Centre.UnitTest.CredentialChecker
|
||||
[TestClass]
|
||||
public class CheckDevice_Test : CredentialCheckerSetup
|
||||
{
|
||||
public TestContext TestContext { get; set; }
|
||||
|
||||
[TestMethod]
|
||||
public void CheckDevice_UnknownDevice()
|
||||
{
|
||||
@@ -24,7 +26,7 @@ namespace Aperio_Control_Centre.UnitTest.CredentialChecker
|
||||
Task.Run(async () =>
|
||||
{
|
||||
success = await checker.CheckDevice("XYZ", cts.Token);
|
||||
}).Wait();
|
||||
}, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.IsFalse(success);
|
||||
Assert.IsNull(checker.Device);
|
||||
@@ -63,7 +65,7 @@ namespace Aperio_Control_Centre.UnitTest.CredentialChecker
|
||||
Task.Run(async () =>
|
||||
{
|
||||
success = await checker.CheckDevice("AA11BB", token);
|
||||
}).Wait();
|
||||
}, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.IsFalse(success);
|
||||
Assert.IsNotNull(checker.Device);
|
||||
@@ -100,7 +102,7 @@ namespace Aperio_Control_Centre.UnitTest.CredentialChecker
|
||||
Task.Run(async () =>
|
||||
{
|
||||
success = await checker.CheckDevice("112233", token);
|
||||
}).Wait();
|
||||
}, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.IsTrue(success);
|
||||
Assert.IsNotNull(checker.Device);
|
||||
|
||||
@@ -12,6 +12,8 @@ namespace Aperio_Control_Centre.UnitTest.CredentialChecker
|
||||
[TestClass]
|
||||
public class CheckMifare_API_Test : CredentialCheckerSetup
|
||||
{
|
||||
public TestContext TestContext { get; set; }
|
||||
|
||||
[TestMethod]
|
||||
public void CheckMifare_API_WrongSize()
|
||||
{
|
||||
@@ -39,7 +41,7 @@ namespace Aperio_Control_Centre.UnitTest.CredentialChecker
|
||||
Task.Run(async () =>
|
||||
{
|
||||
success = await checker.CheckMifare(credentialRequest, token);
|
||||
}).Wait();
|
||||
}, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.IsFalse(success);
|
||||
Assert.IsNull(checker.CredentialData);
|
||||
@@ -89,7 +91,7 @@ namespace Aperio_Control_Centre.UnitTest.CredentialChecker
|
||||
Task.Run(async () =>
|
||||
{
|
||||
success = await checker.CheckMifare(credentialRequest, token);
|
||||
}).Wait();
|
||||
}, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.IsFalse(success);
|
||||
Assert.IsNotNull(checker.CredentialData);
|
||||
@@ -140,7 +142,7 @@ namespace Aperio_Control_Centre.UnitTest.CredentialChecker
|
||||
Task.Run(async () =>
|
||||
{
|
||||
success = await checker.CheckMifare(credentialRequest, token);
|
||||
}).Wait();
|
||||
}, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.IsTrue(success);
|
||||
Assert.IsNotNull(checker.CredentialData);
|
||||
|
||||
@@ -13,6 +13,8 @@ namespace Aperio_Control_Centre.UnitTest.CredentialChecker
|
||||
[TestClass]
|
||||
public class CheckMifare_Aperio_Test : CredentialCheckerSetup
|
||||
{
|
||||
public TestContext TestContext { get; set; }
|
||||
|
||||
[TestMethod]
|
||||
public void CheckMifare_Aperio_WrongSize()
|
||||
{
|
||||
@@ -33,7 +35,7 @@ namespace Aperio_Control_Centre.UnitTest.CredentialChecker
|
||||
Task.Run(async () =>
|
||||
{
|
||||
success = await checker.CheckMifare(mifareUID, dynamicData, token);
|
||||
}).Wait();
|
||||
}, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.IsFalse(success);
|
||||
Assert.IsNull(checker.CredentialData);
|
||||
@@ -76,7 +78,7 @@ namespace Aperio_Control_Centre.UnitTest.CredentialChecker
|
||||
Task.Run(async () =>
|
||||
{
|
||||
success = await checker.CheckMifare(mifareUID, dynamicData, token);
|
||||
}).Wait();
|
||||
}, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.IsFalse(success);
|
||||
Assert.IsNotNull(checker.CredentialData);
|
||||
@@ -122,7 +124,7 @@ namespace Aperio_Control_Centre.UnitTest.CredentialChecker
|
||||
Task.Run(async () =>
|
||||
{
|
||||
success = await checker.CheckMifare(mifareUID, dynamicData, token);
|
||||
}).Wait();
|
||||
}, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.IsTrue(success);
|
||||
Assert.IsNotNull(checker.CredentialData);
|
||||
|
||||
@@ -12,6 +12,8 @@ namespace Aperio_Control_Centre.UnitTest.CredentialChecker
|
||||
[TestClass]
|
||||
public class CheckSectorKey_Test : CredentialCheckerSetup
|
||||
{
|
||||
public TestContext TestContext { get; set; }
|
||||
|
||||
private readonly string SectorKey = "B3DC49B384C1D5F34C8E232316D65821";
|
||||
|
||||
[TestMethod]
|
||||
@@ -37,7 +39,7 @@ namespace Aperio_Control_Centre.UnitTest.CredentialChecker
|
||||
Task.Run(async () =>
|
||||
{
|
||||
success = await checker.CheckSectorKey("", token);
|
||||
}).Wait();
|
||||
}, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.IsFalse(success);
|
||||
|
||||
@@ -84,7 +86,7 @@ namespace Aperio_Control_Centre.UnitTest.CredentialChecker
|
||||
Task.Run(async () =>
|
||||
{
|
||||
success = await checker.CheckSectorKey(SectorKey, token);
|
||||
}).Wait();
|
||||
}, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.IsFalse(success);
|
||||
|
||||
@@ -130,7 +132,7 @@ namespace Aperio_Control_Centre.UnitTest.CredentialChecker
|
||||
Task.Run(async () =>
|
||||
{
|
||||
success = await checker.CheckSectorKey(SectorKey, token);
|
||||
}).Wait();
|
||||
}, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.IsTrue(success);
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ namespace Aperio_Control_Centre.UnitTest.CredentialChecker
|
||||
[TestClass]
|
||||
public class CheckUser_Test : CredentialCheckerSetup
|
||||
{
|
||||
public TestContext TestContext { get; set; }
|
||||
|
||||
[TestMethod]
|
||||
public void CheckUser_UnknownUser()
|
||||
{
|
||||
@@ -32,7 +34,7 @@ namespace Aperio_Control_Centre.UnitTest.CredentialChecker
|
||||
Task.Run(async () =>
|
||||
{
|
||||
success = await checker.CheckUser(token);
|
||||
}).Wait();
|
||||
}, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
|
||||
Assert.IsFalse(success);
|
||||
@@ -79,7 +81,7 @@ namespace Aperio_Control_Centre.UnitTest.CredentialChecker
|
||||
Task.Run(async () =>
|
||||
{
|
||||
success = await checker.CheckUser(token);
|
||||
}).Wait();
|
||||
}, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.IsFalse(success);
|
||||
Assert.IsNotNull(checker.User);
|
||||
@@ -125,7 +127,7 @@ namespace Aperio_Control_Centre.UnitTest.CredentialChecker
|
||||
Task.Run(async () =>
|
||||
{
|
||||
success = await checker.CheckUser(token);
|
||||
}).Wait();
|
||||
}, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.IsFalse(success);
|
||||
Assert.IsNotNull(checker.User);
|
||||
@@ -170,7 +172,7 @@ namespace Aperio_Control_Centre.UnitTest.CredentialChecker
|
||||
Task.Run(async () =>
|
||||
{
|
||||
success = await checker.CheckUser(token);
|
||||
}).Wait();
|
||||
}, TestContext.CancellationToken).Wait(TestContext.CancellationToken);
|
||||
|
||||
Assert.IsTrue(success);
|
||||
Assert.IsNotNull(checker.User);
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using Aperio_Control_Centre.Aadp.Enumerations;
|
||||
using Aperio_Control_Centre.ScreenLogging;
|
||||
using Aperio_Control_Centre.UnitTest.AperioServer.Setups;
|
||||
using Aperio_Control_Centre.ScreenLogging;
|
||||
using System.Net;
|
||||
|
||||
namespace Aperio_Control_Centre.UnitTest
|
||||
@@ -8,6 +6,8 @@ namespace Aperio_Control_Centre.UnitTest
|
||||
[TestClass]
|
||||
public class ScreenLogging_Test
|
||||
{
|
||||
public TestContext TestContext { get; set; }
|
||||
|
||||
[TestMethod]
|
||||
public void Screenlogging_AddScreenLog_Test()
|
||||
{
|
||||
@@ -73,7 +73,7 @@ namespace Aperio_Control_Centre.UnitTest
|
||||
tasks.Add(Task.Run(() => { screenLogging.AddScreenlog(new SystemScreenLog() { IPAddress = IPAddress.Parse("11.22.33.8"), Message = "Msg 8" }); ; return true; }));
|
||||
tasks.Add(Task.Run(() => { screenLogging.AddScreenlog(new SystemScreenLog() { IPAddress = IPAddress.Parse("11.22.33.9"), Message = "Msg 9" }); ; return true; }));
|
||||
}
|
||||
Task.WaitAll(tasks.ToArray());
|
||||
Task.WaitAll(tasks.ToArray(), TestContext.CancellationToken);
|
||||
Thread.Sleep(500);
|
||||
|
||||
Assert.AreEqual(100, eventFired);
|
||||
|
||||
Reference in New Issue
Block a user