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 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(); }
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); }
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_Up_Should_Not_Save_Changes(uint startFcntUp) { var target = new SingleGatewayFrameCounterUpdateStrategy(); var device = new LoRaDevice("1", "2", new SingleDeviceConnectionManager(this.deviceClient.Object)); device.SetFcntUp(startFcntUp); device.AcceptFrameCountChanges(); for (uint i = 1; i <= 9; ++i) { device.SetFcntUp(i); await target.SaveChangesAsync(device); } this.deviceClient.VerifyAll(); }
public void After_3_Resubmits_Should_Not_Be_Valid_To_Resend_Ack() { var target = new LoRaDevice("1231", "12312", new SingleDeviceConnectionManager(this.loRaDeviceClient.Object)); // 1st time target.SetFcntUp(12); // 1st resubmit target.SetFcntUp(12); Assert.True(target.ValidateConfirmResubmit(12)); // 2nd resubmit target.SetFcntUp(12); Assert.True(target.ValidateConfirmResubmit(12)); // 3rd resubmit target.SetFcntUp(12); Assert.True(target.ValidateConfirmResubmit(12)); // 4rd resubmit target.SetFcntUp(12); Assert.False(target.ValidateConfirmResubmit(12)); // new fcnt up target.SetFcntUp(13); Assert.False(target.ValidateConfirmResubmit(12), "Should not be valid to resubmit old fcntUp"); // resubmit new fcnt up target.SetFcntUp(13); Assert.True(target.ValidateConfirmResubmit(13)); Assert.False(target.ValidateConfirmResubmit(12), "Should not be valid to resubmit old fcntUp"); }
public async Task When_Setting_FcntUp_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.SetFcntUp(12); Assert.Equal(12, target.FCntUp); await target.SaveFrameCountChangesAsync(); }
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 async Task After_Saving_Frame_Counter_Changes_Should_Not_Have_Pending_Changes() { var target = new LoRaDevice("1231", "12312", new SingleDeviceConnectionManager(this.loRaDeviceClient.Object)); this.loRaDeviceClient.Setup(x => x.UpdateReportedPropertiesAsync(It.IsAny <TwinCollection>())) .ReturnsAsync(true); target.SetFcntUp(12); Assert.Equal(12U, target.FCntUp); Assert.Equal(0U, target.LastSavedFCntUp); await target.SaveChangesAsync(); Assert.False(target.HasFrameCountChanges); Assert.Equal(12U, target.LastSavedFCntUp); }
public async Task When_Device_FcntUp_Change_Is_10_Or_More_Should_Save_Changes(uint fcntUp) { var target = new MultiGatewayFrameCounterUpdateStrategy(this.gatewayID, this.deviceApi.Object); this.deviceClient.Setup(x => x.UpdateReportedPropertiesAsync(It.IsNotNull <TwinCollection>())) .ReturnsAsync(true) .Callback <TwinCollection>(t => { Assert.Equal(fcntUp, (uint)t[TwinProperty.FCntUp]); Assert.Equal(0U, (uint)t[TwinProperty.FCntDown]); }); var device = new LoRaDevice("1", "2", new SingleDeviceConnectionManager(this.deviceClient.Object)); device.SetFcntUp(fcntUp); await target.SaveChangesAsync(device); this.deviceApi.VerifyAll(); 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); }
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); }