public void When_ResetFcnt_In_NonZero_FcntUp_Or_FcntDown_Should_Have_HasFrameCountChanges_True() { // Non zero fcnt up var target = new LoRaDevice("1231", "12312", this.loRaDeviceClient.Object); target.SetFcntUp(1); target.AcceptFrameCountChanges(); target.ResetFcnt(); Assert.Equal(0, target.FCntUp); Assert.Equal(0, target.FCntDown); Assert.True(target.HasFrameCountChanges); // Non zero fcnt down target = new LoRaDevice("1231", "12312", this.loRaDeviceClient.Object); target.SetFcntDown(1); target.AcceptFrameCountChanges(); target.ResetFcnt(); Assert.Equal(0, target.FCntUp); Assert.Equal(0, target.FCntDown); Assert.True(target.HasFrameCountChanges); // Non zero fcnt down and up target = new LoRaDevice("1231", "12312", this.loRaDeviceClient.Object); target.SetFcntDown(1); target.SetFcntDown(2); target.AcceptFrameCountChanges(); target.ResetFcnt(); Assert.Equal(0, target.FCntUp); Assert.Equal(0, target.FCntDown); Assert.True(target.HasFrameCountChanges); }
public void When_ResetFcnt_In_Device_With_Pending_Changes_Should_Have_HasFrameCountChanges_True() { // Non zero fcnt up var target = new LoRaDevice("1231", "12312", new SingleDeviceConnectionManager(this.loRaDeviceClient.Object)); target.SetFcntUp(1); target.AcceptFrameCountChanges(); target.ResetFcnt(); Assert.Equal(0U, target.FCntUp); Assert.Equal(0U, target.FCntDown); Assert.True(target.HasFrameCountChanges); // Non zero fcnt down target = new LoRaDevice("1231", "12312", new SingleDeviceConnectionManager(this.loRaDeviceClient.Object)); target.SetFcntDown(1); target.AcceptFrameCountChanges(); target.ResetFcnt(); Assert.Equal(0U, target.FCntUp); Assert.Equal(0U, target.FCntDown); Assert.True(target.HasFrameCountChanges); // Non zero fcnt down and up target = new LoRaDevice("1231", "12312", new SingleDeviceConnectionManager(this.loRaDeviceClient.Object)); target.SetFcntDown(1); target.SetFcntDown(2); target.AcceptFrameCountChanges(); target.ResetFcnt(); Assert.Equal(0U, target.FCntUp); Assert.Equal(0U, target.FCntDown); Assert.True(target.HasFrameCountChanges); }
public void When_ResetFcnt_In_Device_With_Pending_Changes_Should_Have_HasFrameCountChanges_True() { var devAddr = new DevAddr(0x1231); // Non zero fcnt up using var target = CreateDefaultDevice(); target.SetFcntUp(1); target.AcceptFrameCountChanges(); target.ResetFcnt(); Assert.Equal(0U, target.FCntUp); Assert.Equal(0U, target.FCntDown); Assert.True(target.HasFrameCountChanges); // Non zero fcnt down using var secondConnectionManager = new SingleDeviceConnectionManager(this.loRaDeviceClient.Object); using var secondTarget = new LoRaDevice(devAddr, new DevEui(0x12312), secondConnectionManager); secondTarget.SetFcntDown(1); secondTarget.AcceptFrameCountChanges(); secondTarget.ResetFcnt(); Assert.Equal(0U, secondTarget.FCntUp); Assert.Equal(0U, secondTarget.FCntDown); Assert.True(secondTarget.HasFrameCountChanges); // Non zero fcnt down and up using var thirdConnectionManager = new SingleDeviceConnectionManager(this.loRaDeviceClient.Object); using var thirdTarget = new LoRaDevice(devAddr, new DevEui(0x12312), thirdConnectionManager); thirdTarget.SetFcntDown(1); thirdTarget.SetFcntDown(2); thirdTarget.AcceptFrameCountChanges(); thirdTarget.ResetFcnt(); Assert.Equal(0U, thirdTarget.FCntUp); Assert.Equal(0U, thirdTarget.FCntDown); Assert.True(thirdTarget.HasFrameCountChanges); }
public async Task When_Device_FcntDown_Change_Is_10_Or_More_Should_Save_Changes(uint startingFcntDown, uint startingFcntUp) { var target = new SingleGatewayFrameCounterUpdateStrategy(); this.deviceClient.Setup(x => x.UpdateReportedPropertiesAsync(It.IsNotNull <TwinCollection>())) .ReturnsAsync(true) .Callback <TwinCollection>(t => { Assert.Equal(startingFcntDown + 10, (uint)t[TwinProperty.FCntDown]); Assert.Equal(startingFcntUp, (uint)t[TwinProperty.FCntUp]); }); var device = new LoRaDevice("1", "2", new SingleDeviceConnectionManager(this.deviceClient.Object)); device.SetFcntUp(startingFcntUp); device.SetFcntDown(startingFcntDown); device.AcceptFrameCountChanges(); for (var i = 1; i <= 15; i++) { await target.NextFcntDown(device, startingFcntUp + 1); await target.SaveChangesAsync(device); } this.deviceClient.VerifyAll(); }
internal static LoRaDevice CreateFromSimulatedDevice( SimulatedDevice simulatedDevice, ILoRaDeviceClient loRaDeviceClient, DefaultLoRaDataRequestHandler requestHandler = null, ILoRaDeviceClientConnectionManager connectionManager = null) { var result = new LoRaDevice(simulatedDevice.LoRaDevice.DevAddr, simulatedDevice.LoRaDevice.DeviceID, connectionManager ?? new SingleDeviceConnectionManager(loRaDeviceClient)) { AppEUI = simulatedDevice.LoRaDevice.AppEUI, AppKey = simulatedDevice.LoRaDevice.AppKey, SensorDecoder = simulatedDevice.LoRaDevice.SensorDecoder, AppSKey = simulatedDevice.LoRaDevice.AppSKey, NwkSKey = simulatedDevice.LoRaDevice.NwkSKey, GatewayID = simulatedDevice.LoRaDevice.GatewayID, IsOurDevice = true, ClassType = (simulatedDevice.ClassType == 'C' || simulatedDevice.ClassType == 'c') ? LoRaDeviceClassType.C : LoRaDeviceClassType.A, }; result.SetFcntDown(simulatedDevice.FrmCntDown); result.SetFcntUp(simulatedDevice.FrmCntUp); result.AcceptFrameCountChanges(); if (requestHandler != null) { result.SetRequestHandler(requestHandler); } return(result); }
public async Task When_Device_Has_Up_To_9_Changes_In_Fcnt_Down_Should_Not_Save_Changes(uint startFcntDown) { var target = new MultiGatewayFrameCounterUpdateStrategy(this.gatewayID, this.deviceApi.Object); var device = new LoRaDevice("1", "2", new SingleDeviceConnectionManager(this.deviceClient.Object)); device.SetFcntDown(startFcntDown); device.AcceptFrameCountChanges(); this.deviceApi.Setup(x => x.NextFCntDownAsync(device.DevEUI, It.IsAny <uint>(), It.IsAny <uint>(), this.gatewayID)) .Returns <string, uint, uint, string>((devEUI, fcntDown, payloadFcnt, gatewayID) => { return(Task.FromResult(fcntDown + 1)); }); for (var i = 1; i <= 9; ++i) { await target.NextFcntDown(device, 10); await target.SaveChangesAsync(device); } this.deviceApi.VerifyAll(); this.deviceClient.VerifyAll(); }
public async Task When_Setting_FcntDown_Should_Save_Frame_Counter() { var target = new LoRaDevice("1231", "12312", this.loRaDeviceClient.Object); this.loRaDeviceClient.Setup(x => x.UpdateReportedPropertiesAsync(It.IsAny <TwinCollection>())) .ReturnsAsync(true); target.SetFcntDown(12); Assert.Equal(12, target.FCntDown); await target.SaveFrameCountChangesAsync(); }
public void When_ResetFcnt_In_NonZero_FcntUp_Or_FcntDown_Should_Have_HasFrameCountChanges_True() { var devAddr = new DevAddr(0x1231); // Non zero fcnt up using var target = CreateDefaultDevice(); target.SetFcntUp(1); target.AcceptFrameCountChanges(); target.ResetFcnt(); Assert.Equal(0U, target.FCntUp); Assert.Equal(0U, target.FCntDown); Assert.True(target.HasFrameCountChanges); // Non zero fcnt down using var secondConnectionManager = new SingleDeviceConnectionManager(this.loRaDeviceClient.Object); using var secondTarget = new LoRaDevice(devAddr, new DevEui(0x12312), secondConnectionManager); secondTarget.SetFcntDown(1); secondTarget.AcceptFrameCountChanges(); secondTarget.ResetFcnt(); Assert.Equal(0U, secondTarget.FCntUp); Assert.Equal(0U, secondTarget.FCntDown); Assert.Equal(0U, secondTarget.LastSavedFCntUp); Assert.Equal(1U, secondTarget.LastSavedFCntDown); Assert.True(secondTarget.HasFrameCountChanges); // Non zero fcnt down and up using var thirdConnectionManager = new SingleDeviceConnectionManager(this.loRaDeviceClient.Object); using var thirdTarget = new LoRaDevice(devAddr, new DevEui(0x12312), thirdConnectionManager); thirdTarget.SetFcntDown(1); thirdTarget.SetFcntDown(2); thirdTarget.AcceptFrameCountChanges(); thirdTarget.ResetFcnt(); Assert.Equal(0U, thirdTarget.FCntUp); Assert.Equal(0U, thirdTarget.FCntDown); Assert.Equal(0U, thirdTarget.LastSavedFCntUp); Assert.Equal(2U, thirdTarget.LastSavedFCntDown); Assert.Empty(thirdTarget.PreferredGatewayID); Assert.Equal(LoRaRegionType.NotSet, thirdTarget.LoRaRegion); Assert.True(thirdTarget.HasFrameCountChanges); }
public async Task When_Device_Has_No_Changes_To_Fcnt_Should_Not_Save_Changes(uint fcntDown, uint fcntUp) { var target = new MultiGatewayFrameCounterUpdateStrategy(this.gatewayID, this.deviceApi.Object); var device = new LoRaDevice("1", "2", new SingleDeviceConnectionManager(this.deviceClient.Object)); device.SetFcntDown(fcntDown); device.SetFcntUp(fcntUp); device.AcceptFrameCountChanges(); await target.SaveChangesAsync(device); this.deviceClient.VerifyAll(); }
public void When_ResetFcnt_In_NonZero_FcntUp_Or_FcntDown_Should_Have_HasFrameCountChanges_True() { // Non zero fcnt up var target = new LoRaDevice("1231", "12312", new SingleDeviceConnectionManager(this.loRaDeviceClient.Object)); target.SetFcntUp(1); target.AcceptFrameCountChanges(); target.ResetFcnt(); Assert.Equal(0U, target.FCntUp); Assert.Equal(0U, target.FCntDown); Assert.True(target.HasFrameCountChanges); // Non zero fcnt down target = new LoRaDevice("1231", "12312", new SingleDeviceConnectionManager(this.loRaDeviceClient.Object)); target.SetFcntDown(1); target.AcceptFrameCountChanges(); target.ResetFcnt(); Assert.Equal(0U, target.FCntUp); Assert.Equal(0U, target.FCntDown); Assert.Equal(0U, target.LastSavedFCntUp); Assert.Equal(1U, target.LastSavedFCntDown); Assert.True(target.HasFrameCountChanges); // Non zero fcnt down and up target = new LoRaDevice("1231", "12312", new SingleDeviceConnectionManager(this.loRaDeviceClient.Object)); target.SetFcntDown(1); target.SetFcntDown(2); target.AcceptFrameCountChanges(); target.ResetFcnt(); Assert.Equal(0U, target.FCntUp); Assert.Equal(0U, target.FCntDown); Assert.Equal(0U, target.LastSavedFCntUp); Assert.Equal(2U, target.LastSavedFCntDown); Assert.Empty(target.PreferredGatewayID); Assert.Equal(LoRaRegionType.NotSet, target.LoRaRegion); Assert.True(target.HasFrameCountChanges); }
public async Task When_Device_Has_Up_To_9_Changes_In_Fcnt_Down_Should_Not_Save_Changes(uint startFcntDown) { var target = new SingleGatewayFrameCounterUpdateStrategy(); var device = new LoRaDevice("1", "2", new SingleDeviceConnectionManager(this.deviceClient.Object)); device.SetFcntDown(startFcntDown); device.AcceptFrameCountChanges(); for (var i = 1; i <= 9; ++i) { await target.NextFcntDown(device, 10); await target.SaveChangesAsync(device); } this.deviceClient.VerifyAll(); }
internal static LoRaDevice CreateFromSimulatedDevice( SimulatedDevice simulatedDevice, ILoRaDeviceClient loRaDeviceClient) { var result = new LoRaDevice(simulatedDevice.LoRaDevice.DevAddr, simulatedDevice.LoRaDevice.DeviceID, loRaDeviceClient) { AppEUI = simulatedDevice.LoRaDevice.AppEUI, AppKey = simulatedDevice.LoRaDevice.AppKey, SensorDecoder = simulatedDevice.LoRaDevice.SensorDecoder, AppSKey = simulatedDevice.LoRaDevice.AppSKey, NwkSKey = simulatedDevice.LoRaDevice.NwkSKey, GatewayID = simulatedDevice.LoRaDevice.GatewayID, IsOurDevice = true, }; result.SetFcntDown(simulatedDevice.FrmCntDown); result.SetFcntUp(simulatedDevice.FrmCntUp); return(result); }