public void When_Structured_Parameters_Are_Passed_They_Are_Replaced()
        {
            var options  = CreateLoggerConfigMonitor();
            var moqInfo  = new Mock <Action <string> >();
            var provider = new Mock <LoRaConsoleLoggerProvider>(options);

            var logger = new TestLoRaConsoleLogger(moqInfo.Object, null, provider.Object);

            logger.LogInformation("{Id}", 1);

            moqInfo.Verify(x => x.Invoke(It.Is <string>(x => x == "1")), Times.Once);
        }
        public void When_EventId_Changes_Output_Is_Written_When_Matching_Or_Omitted(int configuredEventId, int loggedEventId, bool expectsOutput)
        {
            var options = CreateLoggerConfigMonitor();

            options.CurrentValue.EventId = configuredEventId;

            var moqInfo  = new Mock <Action <string> >();
            var provider = new Mock <LoRaConsoleLoggerProvider>(options);

            var logger = new TestLoRaConsoleLogger(moqInfo.Object, null, provider.Object);

            logger.LogInformation(loggedEventId, "Test");

            moqInfo.Verify(x => x.Invoke(It.IsAny <string>()), expectsOutput ? Times.Once : Times.Never);
        }
        public void When_Multiple_Scopes_Set_DevEUI_Preferred_Over_DevAddr_Preferred_Over_StationEUI(string devEuiScope, string devAddrScope, int?stationEuiScope, string expected)
        {
            // arrange
            var options  = CreateLoggerConfigMonitor();
            var moqInfo  = new Mock <Action <string> >();
            var provider = new Mock <LoRaConsoleLoggerProvider>(options);
            var logger   = new TestLoRaConsoleLogger(moqInfo.Object, null, provider.Object);

            // act
            using var euiScope = devEuiScope is { } someDevEuiScope?logger.BeginDeviceScope(DevEui.Parse(someDevEuiScope)) : default;

            using var addrScope = devAddrScope is null ? default : logger.BeginDeviceAddressScope(devAddrScope);
                                  using var statScope = stationEuiScope is { } s?logger.BeginEuiScope(new StationEui ((ulong)s)): default;

                                  logger.LogInformation("foo");

                                  // assert
                                  moqInfo.Verify(x => x.Invoke(expected), Times.Once);
        }
        public void When_Message_Already_Prefixed_Scope_Should_Not_Be_Added()
        {
            var options = CreateLoggerConfigMonitor();

            options.CurrentValue.UseScopes = true;

            var moqInfo  = new Mock <Action <string> >();
            var provider = new Mock <LoRaConsoleLoggerProvider>(options);

            var logger = new TestLoRaConsoleLogger(moqInfo.Object, null, provider.Object);

            var devEUI  = new DevEui(0x12345678);
            var message = devEUI + " test";

            using var scope = logger.BeginDeviceScope(devEUI);
            logger.LogInformation(message);

            moqInfo.Verify(x => x.Invoke(It.Is <string>(x => x == message)), Times.Once);
        }
        public void DevAddr_Scope_Set_In_Message()
        {
            // arrange
            var          options  = CreateLoggerConfigMonitor();
            var          moqInfo  = new Mock <Action <string> >();
            var          provider = new Mock <LoRaConsoleLoggerProvider>(options);
            var          logger   = new TestLoRaConsoleLogger(moqInfo.Object, null, provider.Object);
            const string devAddr  = "12345678ADDR";
            const string message  = "foo";

            // act
            using var scope = logger.BeginDeviceAddressScope(devAddr);
            logger.LogInformation(message);

            // assert
            var expected = string.Concat(devAddr, " ", message);

            moqInfo.Verify(x => x.Invoke(expected), Times.Once);
        }
        public void When_Scope_Settings_Change_DevEUI_Is_Handled_In_The_Message(bool useScopes)
        {
            var options = CreateLoggerConfigMonitor();

            options.CurrentValue.UseScopes = useScopes;

            var moqInfo  = new Mock <Action <string> >();
            var provider = new Mock <LoRaConsoleLoggerProvider>(options);

            var logger = new TestLoRaConsoleLogger(moqInfo.Object, null, provider.Object);

            var          devEUI  = new DevEui(0x12345678);
            const string message = "test";

            using var scope = logger.BeginDeviceScope(devEUI);
            logger.LogInformation(message);

            var expected = useScopes ? devEUI + " " + message : message;

            moqInfo.Verify(x => x.Invoke(It.Is <string>(x => x == expected)), Times.Once);
        }