public void LogMessageWithDifferentLogLevelsShoulCallCorrectLogger(LogLevel level, string methodName)
        {
            // ARRANGE
            const string?message = "message";

            // ACT
            MethodInfo?methodInfo = _app.GetType().GetMethod(methodName, new Type[] { typeof(string) });

            methodInfo?.Invoke(_app, new object[] { message });
            // ASSERT
            _logMock.AssertLogged(level, appTemplate + message, Times.Once());
        }
Exemple #2
0
        public async Task MissingEntityShouldNotLogErrorAndNotBreakOtherApps()
        {
            // ARRANGE
            await InitializeFakeDaemon().ConfigureAwait(false);

            bool eventRun = false, event2Run = false;

            App
            .Entity("binary_sensor.pir")
            .StateChanges
            .Subscribe(_ => eventRun = true);

            App
            .Entity("binary_sensor.pir")
            .StateChanges
            .Subscribe(_ => App.Entity("light.do_not_exist").TurnOn());

            App
            .Entity("binary_sensor.pir")
            .StateChanges
            .Subscribe(_ => event2Run = true);

            DefaultHassClientMock.AddChangedEvent("binary_sensor.pir", "off", "on");

            await RunFakeDaemonUntilTimeout().ConfigureAwait(false);

            LoggerMock.AssertLogged(LogLevel.Error, Times.Never());
            Assert.True(eventRun);
            Assert.True(event2Run);
        }
Exemple #3
0
        public async Task FromUnavailableShouldNotBreak()
        {
            // ARRANGE
            await InitializeFakeDaemon().ConfigureAwait(false);

            bool eventRun = false, event2Run = false;

            App
            .Entity("binary_sensor.pir")
            .StateChanges
            .Subscribe(_ => eventRun = true);

            App
            .Entity("binary_sensor.pir")
            .StateChanges
            .Where(e => e.New.State == "on")
            .Subscribe(_ =>
            {
                int x = int.Parse("ss", CultureInfo.InvariantCulture);
            });

            App
            .Entity("binary_sensor.pir")
            .StateChanges
            .Subscribe(_ => event2Run = true);

            AddEventFakeFromUnavailable();

            await RunFakeDaemonUntilTimeout().ConfigureAwait(false);

            LoggerMock.AssertLogged(LogLevel.Error, Times.Never());
            Assert.False(eventRun);
            Assert.False(event2Run);
        }
Exemple #4
0
        public async Task ARunTimeErrorInAttributeSelectorShouldNotBreakOtherApps()
        {
            // ARRANGE
            await InitializeFakeDaemon().ConfigureAwait(false);

            bool eventRun = false, event2Run = false;

            App
            .Entity("binary_sensor.pir")
            .StateChanges
            .Subscribe(_ => eventRun = true);

            App
            .Entity("binary_sensor.pir")
            .StateChanges
            .Where(e => e.New.Attribute !.an_int == "WTF this is not an int!!")
            .Subscribe(_ =>
            {
                int x = int.Parse("ss", CultureInfo.InvariantCulture);
            });

            App
            .Entity("binary_sensor.pir")
            .StateChanges
            .Subscribe(_ => event2Run = true);

            AddDefaultEvent();

            await RunFakeDaemonUntilTimeout().ConfigureAwait(false);

            LoggerMock.AssertLogged(LogLevel.Error, Times.Once());
            Assert.True(eventRun);
            Assert.True(event2Run);
        }
Exemple #5
0
        public async Task ARunTimeErrorShouldNotBreakOtherApps()
        {
            // ARRANGE
            await InitializeFakeDaemon().ConfigureAwait(false);

            bool eventRun = false;

            App
            .Entity("binary_sensor.pir")
            .WhenStateChange("on")
            .Call((entity, from, to) =>
            {
                // Do conversion error
                int x = int.Parse("ss");
                return(Task.CompletedTask);
            }).Execute();

            App
            .Entity("binary_sensor.pir")
            .WhenStateChange("on")
            .Call((entity, from, to) =>
            {
                // Do conversion error
                eventRun = true;
                return(Task.CompletedTask);
            }).Execute();

            DefaultHassClientMock.AddChangedEvent("binary_sensor.pir", "off", "on");

            await RunFakeDaemonUntilTimeout().ConfigureAwait(false);

            LoggerMock.AssertLogged(LogLevel.Error, Times.Once());
            Assert.True(eventRun);
        }
Exemple #6
0
        public async Task ARunTimeErrorShouldNotBreakOtherApps()
        {
            // ARRANGE
            await InitializeFakeDaemon().ConfigureAwait(false);

            bool eventRun = false, event2Run = false;

            App
            .Entity("binary_sensor.pir")
            .StateChanges
            .Subscribe(_ => eventRun = true);

            App
            .Entity("binary_sensor.pir")
            .StateChanges
            .Subscribe(_ =>
            {
                int x = int.Parse("ss", CultureInfo.InvariantCulture);
            });

            App
            .Entity("binary_sensor.pir")
            .StateChanges
            .Subscribe(_ => event2Run = true);

            DefaultHassClientMock.AddChangedEvent("binary_sensor.pir", "off", "on");

            await RunFakeDaemonUntilTimeout().ConfigureAwait(false);

            LoggerMock.AssertLogged(LogLevel.Error, Times.Once());
            Assert.True(eventRun);
            Assert.True(event2Run);
        }
Exemple #7
0
        public void FaultyApplicationShouldLogError()
        {
            // ARRANGE
            var path = Path.Combine(FaultyAppPath, "CompileErrors");

            // ACT
            var loggerMock = new LoggerMock();
            var cm         = new CodeManager(path, loggerMock.Logger);

            // ASSERT
            loggerMock.AssertLogged(LogLevel.Error, Times.Once());
        }
Exemple #8
0
        public void InsanceAppsThatHasMissingExecuteAndSupressLogsShouldNotLogError()
        {
            // ARRANGE
            var path      = Path.Combine(FaultyAppPath, "SupressLogs");
            var moqDaemon = new Mock <INetDaemonHost>();
            var moqLogger = new LoggerMock();

            // ACT
            var codeManager = new CodeManager(path, moqLogger.Logger);

            // ASSERT
            moqLogger.AssertLogged(LogLevel.Error, Times.Exactly(1));
        }
        public async Task RunInFailureShouldLogError()
        {
            // ARRANGE
            await InitializeFakeDaemon().ConfigureAwait(false);

            // ACT
            DefaultDaemonRxApp.RunIn(TimeSpan.FromMilliseconds(100), () => throw new Exception("RxError"));

            // ASSERT
            await Task.Delay(150).ConfigureAwait(false);

            await RunFakeDaemonUntilTimeout().ConfigureAwait(false);

            LoggerMock.AssertLogged(LogLevel.Error, Times.Once());
        }
Exemple #10
0
        public void FaultyApplicationShouldLogError()
        {
            // ARRANGE
            var path       = Path.Combine(FaultyAppPath, "CompileErrors");
            var loggerMock = new LoggerMock();

            var(daemonApps, _) = DaemonCompiler.GetDaemonApps(path, loggerMock.Logger);
            var netDaemonSettings = CreateSettings(path);

            // ACT
            var cm = new CodeManager(daemonApps, loggerMock.Logger, new YamlConfig(netDaemonSettings));

            // ASSERT
            loggerMock.AssertLogged(LogLevel.Error, Times.AtLeastOnce());
        }
Exemple #11
0
        public async Task ChangedEventHaveNullDataShouldThrowException()
        {
            // ARRANGE
            DefaultHassClientMock.FakeEvents.Enqueue(new HassEvent
            {
                EventType = "state_changed",
                Data      = null
            });

            // ACT
            await RunDefauldDaemonUntilCanceled();

            //ASSERT
            LoggerMock.AssertLogged(LogLevel.Error, Times.AtLeastOnce());
        }
Exemple #12
0
        public async Task CreateObservableTimerFailureShouldLogError()
        {
            // ARRANGE
            await using var app = new BaseTestRxApp();
            await app.StartUpAsync(DefaultDaemonHost).ConfigureAwait(false);

            app.IsEnabled = true;

            // ACT
            using var disposable = app.CreateObservableTimer(DateTime.Now, TimeSpan.FromMilliseconds(10), () => throw new Exception("Hello!"));

            await Task.Delay(150).ConfigureAwait(false);

            // ASSERT
            LoggerMock.AssertLogged(LogLevel.Error, Times.AtLeastOnce());
        }
Exemple #13
0
        public void InsanceAppsThatHasMissingExecuteShouldLogError()
        {
            // ARRANGE
            var path      = Path.Combine(FaultyAppPath, "ExecuteWarnings");
            var moqDaemon = new Mock <INetDaemonHost>();
            var moqLogger = new LoggerMock();

            var(daemonApps, _) = DaemonCompiler.GetDaemonApps(path, moqLogger.Logger);
            var configMock = new Mock <IYamlConfig>();

            // ACT
            var codeManager = new CodeManager(daemonApps, moqLogger.Logger, configMock.Object);

            // ASSERT
            moqLogger.AssertLogged(LogLevel.Error, Times.Exactly(13));
        }
        public async Task ChangedEventHaveNullDataShouldThrowException()
        {
            // ARRANGE
            await InitializeFakeDaemon().ConfigureAwait(false);

            DefaultHassClientMock.FakeEvents.Enqueue(new HassEvent
            {
                EventType = "state_changed",
                Data      = null
            });

            // ACT
            await RunFakeDaemonUntilTimeout().ConfigureAwait(false);

            //ASSERT
            LoggerMock.AssertLogged(LogLevel.Error, Times.AtLeastOnce());
        }
Exemple #15
0
        public async Task CamerassFuncExceptionLogsError()
        {
            // ARRANGE
            DefaultDaemonHost.InternalState["id"] = new EntityState {
                EntityId = "id"
            };

            // ACT
            var x = await Assert.ThrowsAsync <Exception>(() => DefaultDaemonApp
                                                         .Cameras(n => throw new Exception("Some error"))
                                                         .TurnOn()
                                                         .ExecuteAsync());

            // ASSERT
            DefaultHassClientMock.VerifyCallServiceTimes("turn_on", Times.Never());
            LoggerMock.AssertLogged(LogLevel.Error, Times.AtLeastOnce());
            Assert.Equal("Some error", x.Message);
        }
Exemple #16
0
        public async Task ARunTimeErrorShouldLogError()
        {
            // ARRANGE
            await InitializeFakeDaemon().ConfigureAwait(false);

            App
            .Entity("binary_sensor.pir")
            .StateChanges
            .Subscribe(s =>
            {
                int x = int.Parse("ss");
            });

            DefaultHassClientMock.AddChangedEvent("binary_sensor.pir", "off", "on");

            await RunFakeDaemonUntilTimeout().ConfigureAwait(false);

            LoggerMock.AssertLogged(LogLevel.Error, Times.Once());
        }
Exemple #17
0
        public async Task ARunTimeErrorShouldLogWarning()
        {
            // ARRANGE

            App
            .Entity("binary_sensor.pir")
            .WhenStateChange("on")
            .Call((entity, from, to) =>
            {
                // Do conversion error
                int x = int.Parse("ss");
                return(Task.CompletedTask);
            }).Execute();

            DefaultHassClientMock.AddChangedEvent("binary_sensor.pir", "off", "on");

            await RunDefauldDaemonUntilCanceled();

            LoggerMock.AssertLogged(LogLevel.Warning, Times.Once());
        }