Esempio n. 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();
        }
Esempio n. 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();
        }
Esempio n. 3
0
        public async Task When_Device_Has_Up_To_9_Changes_In_Fcnt_Down_Should_Not_Save_Changes(uint startFcntDown)
        {
            var target = new SingleGatewayFrameCounterUpdateStrategy();

            this.device.SetFcntDown(startFcntDown);
            this.device.AcceptFrameCountChanges();

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

                await target.SaveChangesAsync(this.device);
            }

            this.deviceClient.VerifyAll();
        }