Пример #1
0
        public async Task When_Device_FcntDown_Change_Is_10_Or_More_Should_Save_Changes(uint startingFcntDown, uint startingFcntUp)
        {
            var target = new SingleGatewayFrameCounterUpdateStrategy();

            var savedTwinCollections = new List <TwinCollection>();

            this.deviceClient.Setup(x => x.UpdateReportedPropertiesAsync(It.IsNotNull <TwinCollection>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(true)
            .Callback <TwinCollection, CancellationToken>((t, _) => savedTwinCollections.Add(t));

            this.device.SetFcntUp(startingFcntUp);
            this.device.SetFcntDown(startingFcntDown);
            this.device.AcceptFrameCountChanges();

            for (var i = 1; i <= 15; i++)
            {
                await target.NextFcntDown(this.device, startingFcntUp + 1);

                await target.SaveChangesAsync(this.device);
            }

            var savedTwinCollection = Assert.Single(savedTwinCollections);

            Assert.Equal(startingFcntDown + 10, (uint)savedTwinCollection[TwinProperty.FCntDown]);
            Assert.Equal(startingFcntUp, (uint)savedTwinCollection[TwinProperty.FCntUp]);
            this.deviceClient.VerifyAll();
        }
Пример #2
0
        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();
        }
Пример #3
0
        public async Task When_Device_With_0_As_Fcnt_Is_Loaded_Reset_Should_Not_Save_Reported_Properties()
        {
            var target = new SingleGatewayFrameCounterUpdateStrategy();

            await target.ResetAsync(this.device, 1, string.Empty);

            Assert.False(this.device.HasFrameCountChanges);
            this.deviceClient.VerifyAll();
        }
Пример #4
0
        public async Task When_Device_With_0_As_Fcnt_Is_Loaded_Reset_Should_Not_Save_Reported_Properties()
        {
            var target = new SingleGatewayFrameCounterUpdateStrategy();

            var device = new LoRaDevice("1", "2", new SingleDeviceConnectionManager(this.deviceClient.Object));
            await target.ResetAsync(device);

            Assert.False(device.HasFrameCountChanges);
            this.deviceClient.VerifyAll();
        }
Пример #5
0
        public async Task When_Device_Has_No_Changes_To_Fcnt_Should_Not_Save_Changes(uint fcntDown, uint fcntUp)
        {
            var target = new SingleGatewayFrameCounterUpdateStrategy();

            this.device.SetFcntDown(fcntDown);
            this.device.SetFcntUp(fcntUp);
            this.device.AcceptFrameCountChanges();

            await target.SaveChangesAsync(this.device);

            this.deviceClient.VerifyAll();
        }
Пример #6
0
        public async Task When_Device_Has_No_Changes_To_Fcnt_Should_Not_Save_Changes(uint fcntDown, uint fcntUp)
        {
            var target = new SingleGatewayFrameCounterUpdateStrategy();

            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();
        }
Пример #7
0
        public async Task When_Device_Has_Up_To_9_Changes_In_Fcnt_Up_Should_Not_Save_Changes(uint startFcntUp)
        {
            var target = new SingleGatewayFrameCounterUpdateStrategy();

            this.device.SetFcntUp(startFcntUp);
            this.device.AcceptFrameCountChanges();

            for (uint i = 1; i <= 9; ++i)
            {
                this.device.SetFcntUp(i);
                await target.SaveChangesAsync(this.device);
            }

            this.deviceClient.VerifyAll();
        }
Пример #8
0
        public async Task When_Device_FcntUp_Change_Is_10_Or_More_Should_Save_Changes(uint fcntUp)
        {
            var target = new SingleGatewayFrameCounterUpdateStrategy();

            TwinCollection savedTwinCollection = null;

            this.deviceClient.Setup(x => x.UpdateReportedPropertiesAsync(It.IsNotNull <TwinCollection>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(true)
            .Callback <TwinCollection, CancellationToken>((t, _) => savedTwinCollection = t);

            this.device.SetFcntUp(fcntUp);
            await target.SaveChangesAsync(this.device);

            Assert.Equal(fcntUp, (uint)savedTwinCollection[TwinProperty.FCntUp]);
            Assert.Equal(0U, (uint)savedTwinCollection[TwinProperty.FCntDown]);
            this.deviceClient.VerifyAll();
        }
Пример #9
0
        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();
        }
Пример #10
0
 public LoRaDeviceFrameCounterUpdateStrategyFactory(string gatewayID, LoRaDeviceAPIServiceBase loRaDeviceAPIService)
 {
     this.multiGateway  = new MultiGatewayFrameCounterUpdateStrategy(gatewayID, loRaDeviceAPIService);
     this.singleGateway = new SingleGatewayFrameCounterUpdateStrategy();
 }