Example #1
0
 public static TheoryData <IoTHubDeviceInfo> Serialize_Deserialize_Composition_Should_Preserve_Information_TheoryData() => TheoryDataFactory.From(
     from networkSessionKey in new[] { (NetworkSessionKey?)null, TestKeys.CreateNetworkSessionKey(3) }
     select new IoTHubDeviceInfo
 {
     DevAddr    = new DevAddr(1),
     DevEUI     = new DevEui(2),
     GatewayId  = "foo",
     NwkSKey    = networkSessionKey,
     PrimaryKey = TestKeys.CreateAppKey(4).ToString()
 });
Example #2
0
        public async Task When_Initialized_Joined_OTAA_Device_Should_Have_All_Properties()
        {
            var appKey            = TestKeys.CreateAppKey(0xABC0200000000000, 0x09);
            var networkSessionKey = TestKeys.CreateNetworkSessionKey(0xABC0200000000000, 0x09);
            var appSessionKey     = TestKeys.CreateAppSessionKey(0xABCD200000000000, 0x09);
            var joinEui           = new JoinEui(0xABC0200000000009);

            var twin = TestUtils.CreateTwin(
                desired: new Dictionary <string, object>
            {
                { "AppEUI", joinEui.ToString() },
                { "AppKey", appKey.ToString() },
                { "GatewayID", "mygateway" },
                { "SensorDecoder", "DecoderValueSensor" },
                { "$version", 1 },
            },
                reported: new Dictionary <string, object>
            {
                { "$version", 1 },
                { "NwkSKey", networkSessionKey.ToString() },
                { "AppSKey", appSessionKey.ToString() },
                { "DevNonce", "0123" },
                { "DevAddr", "0000AABB" },
            });

            this.loRaDeviceClient.Setup(x => x.GetTwinAsync(CancellationToken.None))
            .ReturnsAsync(twin);

            using var loRaDevice = CreateDefaultDevice();

            await loRaDevice.InitializeAsync(this.configuration);

            Assert.Equal(joinEui, loRaDevice.AppEui);
            Assert.Equal(appKey, loRaDevice.AppKey);
            Assert.Equal("mygateway", loRaDevice.GatewayID);
            Assert.Equal("DecoderValueSensor", loRaDevice.SensorDecoder);
            Assert.False(loRaDevice.IsABP);
            Assert.False(loRaDevice.IsOurDevice);
            Assert.Equal(networkSessionKey, loRaDevice.NwkSKey);
            Assert.Equal(appSessionKey, loRaDevice.AppSKey);
            Assert.Equal(new DevNonce(123), loRaDevice.DevNonce);
            Assert.Equal(new DevAddr(0x0000aabb), loRaDevice.DevAddr);
            Assert.Null(loRaDevice.ReportedDwellTimeSetting);
        }
Example #3
0
        public async Task When_Initialized_New_OTAA_Device_Should_Have_All_Properties()
        {
            var appKey  = TestKeys.CreateAppKey(0xABC0200000000000, 0x09);
            var joinEui = new JoinEui(0xABC0200000000009);

            var twin = TestUtils.CreateTwin(
                desired: new Dictionary <string, object>
            {
                { "AppEUI", joinEui.ToString() },
                { "AppKey", appKey.ToString() },
                { "GatewayID", "mygateway" },
                { "SensorDecoder", "DecoderValueSensor" },
                { "$version", 1 },
            },
                reported: new Dictionary <string, object>
            {
                { "$version", 1 },
            });

            this.loRaDeviceClient.Setup(x => x.GetTwinAsync(CancellationToken.None))
            .ReturnsAsync(twin);

            using var connectionManager = new SingleDeviceConnectionManager(this.loRaDeviceClient.Object);
            using var loRaDevice        = new LoRaDevice(null, new DevEui(0xabc0200000000009), connectionManager);
            await loRaDevice.InitializeAsync(this.configuration);

            Assert.Equal(joinEui, loRaDevice.AppEui);
            Assert.Equal(appKey, loRaDevice.AppKey);
            Assert.Equal("mygateway", loRaDevice.GatewayID);
            Assert.Equal("DecoderValueSensor", loRaDevice.SensorDecoder);
            Assert.Equal(0U, loRaDevice.FCntDown);
            Assert.Equal(0U, loRaDevice.LastSavedFCntDown);
            Assert.Equal(0U, loRaDevice.FCntUp);
            Assert.Equal(0U, loRaDevice.LastSavedFCntUp);
            Assert.False(loRaDevice.HasFrameCountChanges);
            Assert.Null(loRaDevice.AppSKey);
            Assert.Null(loRaDevice.NwkSKey);
            Assert.Null(loRaDevice.DevAddr);
            Assert.Null(loRaDevice.DevNonce);
            Assert.Null(loRaDevice.NetId);
            Assert.False(loRaDevice.IsABP);
            Assert.False(loRaDevice.IsOurDevice);
            Assert.Null(loRaDevice.ReportedDwellTimeSetting);
        }
        public async Task When_Mic_Check_Fails_Join_Process_Should_Fail()
        {
            var simulatedDevice = new SimulatedDevice(TestDeviceInfo.CreateOTAADevice(1, gatewayID: ServerConfiguration.GatewayID));
            var wrongAppKey     = TestKeys.CreateAppKey(0x3000000, 0x30000);

            var joinRequest = simulatedDevice.CreateJoinRequest(wrongAppKey);

            using var loRaDevice = CreateLoRaDevice(simulatedDevice);
            loRaDevice.SetFcntDown(10);
            loRaDevice.SetFcntUp(20);

            var devEui = simulatedDevice.LoRaDevice.DevEui;

            var loRaDeviceRegistryMock = new Mock <ILoRaDeviceRegistry>(MockBehavior.Strict);

            loRaDeviceRegistryMock.Setup(x => x.RegisterDeviceInitializer(It.IsNotNull <ILoRaDeviceInitializer>()));
            loRaDeviceRegistryMock.Setup(x => x.GetDeviceForJoinRequestAsync(devEui, joinRequest.DevNonce))
            .ReturnsAsync(() => loRaDevice);

            // Send to message processor
            using var messageProcessor = new MessageDispatcher(
                      ServerConfiguration,
                      loRaDeviceRegistryMock.Object,
                      FrameCounterUpdateStrategyProvider);

            using var request = CreateWaitableRequest(TestUtils.GenerateTestRadioMetadata(), joinRequest);
            messageProcessor.DispatchRequest(request);
            Assert.True(await request.WaitCompleteAsync());
            Assert.Null(request.ResponseDownlink);

            // Device frame counts were not modified
            Assert.Equal(10U, loRaDevice.FCntDown);
            Assert.Equal(20U, loRaDevice.FCntUp);

            // Twin property were updated
            LoRaDeviceClient.VerifyAll();
            LoRaDeviceApi.VerifyAll();
            loRaDeviceRegistryMock.VerifyAll();

            loRaDeviceRegistryMock.Setup(dr => dr.Dispose());
            LoRaDeviceClient.Setup(ldc => ldc.Dispose());
        }
Example #5
0
 private static Dictionary <string, object> GetEssentialDesiredProperties() =>
 new Dictionary <string, object>
 {
     ["AppEUI"] = new JoinEui(0xABCD1234).ToString(),
     ["AppKey"] = TestKeys.CreateAppKey(1).ToString()
 };