Exemple #1
0
        public async Task WorkerConsoleLogService_ConsoleLogs_LogLevel_Expected(bool useStdErrForErroLogsOnly)
        {
            _workerConsoleLogSource  = new WorkerConsoleLogSource();
            _eventManager            = new ScriptEventManager();
            _processRegistry         = new EmptyProcessRegistry();
            _workerConsoleLogService = new WorkerConsoleLogService(_testLogger, _workerConsoleLogSource);
            WorkerProcess workerProcess = new TestWorkerProcess(_eventManager, _processRegistry, _testLogger, _workerConsoleLogSource, null, useStdErrForErroLogsOnly);

            workerProcess.ParseErrorMessageAndLog("Test Message No keyword");
            workerProcess.ParseErrorMessageAndLog("Test Error Message");
            workerProcess.ParseErrorMessageAndLog("Test Warning Message");
            _ = _workerConsoleLogService.ProcessLogs().ContinueWith(t => { });
            await _workerConsoleLogService.StopAsync(System.Threading.CancellationToken.None);

            var allLogs = _testLogger.GetLogMessages();

            Assert.True(allLogs.Count == 3);
            VerifyLogLevel(allLogs, "Test Error Message", LogLevel.Error);
            VerifyLogLevel(allLogs, "Test Warning Message", LogLevel.Warning);
            if (useStdErrForErroLogsOnly)
            {
                VerifyLogLevel(allLogs, "Test Message No keyword", LogLevel.Error);
            }
            else
            {
                VerifyLogLevel(allLogs, "Test Message No keyword", LogLevel.Information);
            }
        }
        public async Task WorkerConsoleLogService_ConsoleLogs_LogLevel_Expected(bool useStdErrForErrorLogsOnly)
        {
            // Arrange
            _workerConsoleLogSource  = new WorkerConsoleLogSource();
            _eventManager            = new ScriptEventManager();
            _processRegistry         = new EmptyProcessRegistry();
            _workerConsoleLogService = new WorkerConsoleLogService(_testUserLogger, _workerConsoleLogSource);
            _serviceProviderMock     = new Mock <IServiceProvider>(MockBehavior.Strict);

            WorkerProcess workerProcess = new TestWorkerProcess(_eventManager, _processRegistry, _testSystemLogger, _workerConsoleLogSource, null, _serviceProviderMock.Object, useStdErrForErrorLogsOnly);

            workerProcess.ParseErrorMessageAndLog("Test Message No keyword");
            workerProcess.ParseErrorMessageAndLog("Test Error Message");
            workerProcess.ParseErrorMessageAndLog("Test Warning Message");
            workerProcess.ParseErrorMessageAndLog("LanguageWorkerConsoleLog[Test Worker Message No keyword]");
            workerProcess.ParseErrorMessageAndLog("LanguageWorkerConsoleLog[Test Worker Error Message]");
            workerProcess.ParseErrorMessageAndLog("LanguageWorkerConsoleLog[Test Worker Warning Message]");

            // Act
            _ = _workerConsoleLogService.ProcessLogs().ContinueWith(t => { });
            await _workerConsoleLogService.StopAsync(System.Threading.CancellationToken.None);

            var userLogs   = _testUserLogger.GetLogMessages();
            var systemLogs = _testSystemLogger.GetLogMessages();

            // Assert
            Assert.True(userLogs.Count == 3);
            Assert.True(systemLogs.Count == 3);

            VerifyLogLevel(userLogs, "Test Error Message", LogLevel.Error);
            VerifyLogLevel(systemLogs, "[Test Worker Error Message]", LogLevel.Error);
            VerifyLogLevel(userLogs, "Test Warning Message", LogLevel.Warning);
            VerifyLogLevel(systemLogs, "[Test Worker Warning Message]", LogLevel.Warning);

            if (useStdErrForErrorLogsOnly)
            {
                VerifyLogLevel(userLogs, "Test Message No keyword", LogLevel.Error);
                VerifyLogLevel(systemLogs, "[Test Worker Message No keyword]", LogLevel.Error);
            }
            else
            {
                VerifyLogLevel(userLogs, "Test Message No keyword", LogLevel.Information);
                VerifyLogLevel(systemLogs, "[Test Worker Message No keyword]", LogLevel.Information);
            }
        }