Exemple #1
0
        public void Mic_Validation_Is_Used_To_Validate_Items(bool isValid)
        {
            using var device = CreateTestDevice();
            using var cache  = new TestDeviceCache(this.noRefreshOptions, (_, _) => isValid);

            cache.Register(device);

            var payload = new LoRaPayloadData(device.DevAddr.Value, new MacHeader(MacMessageType.UnconfirmedDataUp),
                                              FrameControlFlags.None, 1, string.Empty, "payload", FramePort.AppMin,
                                              mic: null, NullLogger.Instance);

            Assert.Equal(isValid, cache.TryGetForPayload(payload, out _));

            var stats = cache.CalculateStatistics();

            Assert.Equal(isValid ? 1 : 0, stats.Hit);
            Assert.Equal(isValid ? 0 : 1, stats.Miss);
        }
Exemple #2
0
        public void Last_Seen_Is_Updated_Depending_On_Cache_Hit(bool cacheHit)
        {
            using var device = CreateTestDevice();
            using var cache  = new TestDeviceCache(this.noRefreshOptions, (_, _) => cacheHit);

            cache.Register(device);

            var payload = new LoRaPayloadData(device.DevAddr.Value, new MacHeader(MacMessageType.UnconfirmedDataUp),
                                              FrameControlFlags.None, 1, string.Empty, "payload", FramePort.AppMin,
                                              mic: null, NullLogger.Instance);

            var lastSeen = device.LastSeen;

            cache.TryGetForPayload(payload, out _);

            if (cacheHit)
            {
                Assert.True(device.LastSeen > lastSeen);
            }
            else
            {
                Assert.Equal(device.LastSeen, lastSeen);
            }
        }