Esempio n. 1
0
        public MessageProcessorMultipleGatewayTest()
        {
            this.SecondServerConfiguration = new NetworkServerConfiguration
            {
                GatewayID    = SecondServerGatewayID,
                LogToConsole = true,
                LogLevel     = ((int)LogLevel.Debug).ToString(),
            };

            this.SecondPacketForwarder = new TestPacketForwarder();
            this.SecondLoRaDeviceApi   = new Mock <LoRaDeviceAPIServiceBase>(MockBehavior.Strict);
            this.SecondFrameCounterUpdateStrategyProvider = new LoRaDeviceFrameCounterUpdateStrategyProvider(SecondServerGatewayID, this.SecondLoRaDeviceApi.Object);
            var deduplicationStrategyFactory = new DeduplicationStrategyFactory(this.SecondLoRaDeviceApi.Object);
            var loRaAdrManagerFactory        = new LoRAADRManagerFactory(this.SecondLoRaDeviceApi.Object);
            var adrStrategyProvider          = new LoRaADRStrategyProvider();
            var functionBundlerProvider      = new FunctionBundlerProvider(this.SecondLoRaDeviceApi.Object);

            this.secondRequestHandlerImplementation = new DefaultLoRaDataRequestHandler(this.SecondServerConfiguration, this.SecondFrameCounterUpdateStrategyProvider, new LoRaPayloadDecoder(), deduplicationStrategyFactory, adrStrategyProvider, loRaAdrManagerFactory, functionBundlerProvider);
            this.SecondLoRaDeviceClient             = new Mock <ILoRaDeviceClient>(MockBehavior.Strict);
            this.SecondConnectionManager            = new LoRaDeviceClientConnectionManager(new MemoryCache(new MemoryCacheOptions()
            {
                ExpirationScanFrequency = TimeSpan.FromSeconds(5)
            }));
            this.SecondLoRaDeviceFactory = new TestLoRaDeviceFactory(this.SecondServerConfiguration, this.SecondFrameCounterUpdateStrategyProvider, this.SecondLoRaDeviceClient.Object, deduplicationStrategyFactory, adrStrategyProvider, loRaAdrManagerFactory, functionBundlerProvider, this.SecondConnectionManager);
        }
Esempio n. 2
0
        public MessageProcessorTestBase()
        {
            this.startTime = DateTimeOffset.UtcNow.Ticks;

            this.macAddress          = Utility.GetMacAddress();
            this.ServerConfiguration = new NetworkServerConfiguration
            {
                GatewayID    = ServerGatewayID,
                LogToConsole = true,
                LogLevel     = ((int)LogLevel.Debug).ToString(),
            };

            Logger.Init(new LoggerConfiguration()
            {
                LogLevel     = LogLevel.Debug,
                LogToConsole = true,
            });

            this.PayloadDecoder  = new TestLoRaPayloadDecoder(new LoRaPayloadDecoder());
            this.PacketForwarder = new TestPacketForwarder();
            this.LoRaDeviceApi   = new Mock <LoRaDeviceAPIServiceBase>(MockBehavior.Strict);
            this.FrameCounterUpdateStrategyProvider = new LoRaDeviceFrameCounterUpdateStrategyProvider(ServerGatewayID, this.LoRaDeviceApi.Object);
            var deduplicationFactory    = new DeduplicationStrategyFactory(this.LoRaDeviceApi.Object);
            var adrStrategyProvider     = new LoRaADRStrategyProvider();
            var adrManagerFactory       = new LoRAADRManagerFactory(this.LoRaDeviceApi.Object);
            var functionBundlerProvider = new FunctionBundlerProvider(this.LoRaDeviceApi.Object);

            this.RequestHandlerImplementation = new DefaultLoRaDataRequestHandler(this.ServerConfiguration, this.FrameCounterUpdateStrategyProvider, this.PayloadDecoder, deduplicationFactory, adrStrategyProvider, adrManagerFactory, functionBundlerProvider);
            this.LoRaDeviceClient             = new Mock <ILoRaDeviceClient>(MockBehavior.Strict);
            this.ConnectionManager            = new LoRaDeviceClientConnectionManager(new MemoryCache(new MemoryCacheOptions()
            {
                ExpirationScanFrequency = TimeSpan.FromSeconds(5)
            }));
            this.LoRaDeviceFactory = new TestLoRaDeviceFactory(this.ServerConfiguration, this.FrameCounterUpdateStrategyProvider, this.LoRaDeviceClient.Object, deduplicationFactory, adrStrategyProvider, adrManagerFactory, functionBundlerProvider, this.ConnectionManager);
        }
Esempio n. 3
0
        public async Task CreateIfRequired_Result_Has_Correct_Bundler_Request()
        {
            // arrange
            const string gatewayId = "foo";
            const double rssi      = 2.3;
            var          device    = new SimulatedDevice(TestDeviceInfo.CreateABPDevice(0));

            using var loRaDevice = TestUtils.CreateFromSimulatedDevice(device, new Mock <ILoRaDeviceClientConnectionManager>().Object);
            var payload = device.CreateConfirmedDataUpMessage("foo");

            using var request = WaitableLoRaRequest.Create(TestUtils.GenerateTestRadioMetadata(rssi: rssi), payload);
            var deviceApiServiceMock = new Mock <LoRaDeviceAPIServiceBase>();

            deviceApiServiceMock.Setup(s => s.ExecuteFunctionBundlerAsync(It.IsAny <DevEui>(), It.IsAny <FunctionBundlerRequest>())).ReturnsAsync(new FunctionBundlerResult());
            var subject = new FunctionBundlerProvider(deviceApiServiceMock.Object, NullLoggerFactory.Instance, NullLogger <FunctionBundlerProvider> .Instance);

            // act
            var bundler = subject.CreateIfRequired(gatewayId, payload, loRaDevice, new Mock <IDeduplicationStrategyFactory>().Object, request);

            _ = await bundler.Execute();

            // assert
            deviceApiServiceMock.Verify(s => s.ExecuteFunctionBundlerAsync(loRaDevice.DevEUI,
                                                                           It.Is <FunctionBundlerRequest>(actual => actual.ClientFCntDown == 0 &&
                                                                                                          actual.ClientFCntUp == 1 &&
                                                                                                          actual.GatewayId == gatewayId &&
                                                                                                          actual.Rssi == rssi)));
        }
        public MessageProcessorMultipleGatewayBase(ITestOutputHelper testOutputHelper) : base(testOutputHelper)
        {
            SecondServerConfiguration = new NetworkServerConfiguration
            {
                GatewayID    = SecondServerGatewayID,
                LogToConsole = true,
                LogLevel     = ((int)LogLevel.Debug).ToString(CultureInfo.InvariantCulture),
            };

            SecondDownstreamMessageSender            = new TestDownstreamMessageSender();
            SecondLoRaDeviceApi                      = new Mock <LoRaDeviceAPIServiceBase>(MockBehavior.Strict);
            SecondFrameCounterUpdateStrategyProvider = new LoRaDeviceFrameCounterUpdateStrategyProvider(SecondServerConfiguration, SecondLoRaDeviceApi.Object);
            this.cache = new MemoryCache(new MemoryCacheOptions()
            {
                ExpirationScanFrequency = TimeSpan.FromSeconds(5)
            });

            this.testOutputLoggerFactory = new TestOutputLoggerFactory(testOutputHelper);
            var deduplicationStrategyFactory = new DeduplicationStrategyFactory(this.testOutputLoggerFactory, this.testOutputLoggerFactory.CreateLogger <DeduplicationStrategyFactory>());
            var loRaAdrManagerFactory        = new LoRAADRManagerFactory(SecondLoRaDeviceApi.Object, this.testOutputLoggerFactory);
            var adrStrategyProvider          = new LoRaADRStrategyProvider(this.testOutputLoggerFactory);
            var functionBundlerProvider      = new FunctionBundlerProvider(SecondLoRaDeviceApi.Object, this.testOutputLoggerFactory, this.testOutputLoggerFactory.CreateLogger <FunctionBundlerProvider>());

            SecondConcentratorDeduplication = new ConcentratorDeduplication(this.cache, this.testOutputLoggerFactory.CreateLogger <IConcentratorDeduplication>());

            SecondRequestHandlerImplementation = new DefaultLoRaDataRequestHandler(SecondServerConfiguration,
                                                                                   SecondFrameCounterUpdateStrategyProvider,
                                                                                   SecondConcentratorDeduplication,
                                                                                   new LoRaPayloadDecoder(this.testOutputLoggerFactory.CreateLogger <LoRaPayloadDecoder>()),
                                                                                   deduplicationStrategyFactory,
                                                                                   adrStrategyProvider,
                                                                                   loRaAdrManagerFactory,
                                                                                   functionBundlerProvider,
                                                                                   this.testOutputLoggerFactory.CreateLogger <DefaultLoRaDataRequestHandler>(),
                                                                                   null);
            SecondLoRaDeviceClient = new Mock <ILoRaDeviceClient>(MockBehavior.Strict);
            this.cache             = new MemoryCache(new MemoryCacheOptions()
            {
                ExpirationScanFrequency = TimeSpan.FromSeconds(5)
            });

            var defaultRequestHandler = new DefaultLoRaDataRequestHandler(SecondServerConfiguration,
                                                                          SecondFrameCounterUpdateStrategyProvider,
                                                                          SecondConcentratorDeduplication,
                                                                          new LoRaPayloadDecoder(this.testOutputLoggerFactory.CreateLogger <LoRaPayloadDecoder>()),
                                                                          deduplicationStrategyFactory,
                                                                          adrStrategyProvider,
                                                                          loRaAdrManagerFactory,
                                                                          functionBundlerProvider,
                                                                          this.testOutputLoggerFactory.CreateLogger <DefaultLoRaDataRequestHandler>(),
                                                                          meter: null);

            SecondConnectionManager = new LoRaDeviceClientConnectionManager(this.cache, this.testOutputLoggerFactory.CreateLogger <LoRaDeviceClientConnectionManager>());
            SecondLoRaDeviceFactory = new TestLoRaDeviceFactory(SecondServerConfiguration, SecondLoRaDeviceClient.Object, SecondConnectionManager, DeviceCache, defaultRequestHandler);
        }