Esempio n. 1
0
        public void ChangedTargetAndGiven1000LinesOfLog_LogWriteInDefaultTarget_ThenNumberLinesInTargetIsCorrect()
        {
            // Arrange
            LogTarget   logTarget  = new LogTarget();
            ILogService logService = Log.SetLogTargetAndRestartLog(logTarget);

            // Act
            for (int i = 0; i < 1000; i++)
            {
                logService.Log($"Line {i.ToString("D4")}");
            }

            // Asset
            Assert.AreEqual(1000, logTarget.LineNumber);
        }
Esempio n. 2
0
        public async Task ChangedTargetAndGiven4000LinesOfLogIn4Task_LogWriteInDefaultTarget_ThenNumberLinesInTargetIsCorrect()
        {
            // Arrange
            LogTarget   logTarget  = new LogTarget();
            ILogService logService = Log.SetLogTargetAndRestartLog(logTarget);

            // Act
            Task t = Task.WhenAll(
                Task.Run(() => Write1000Lines(logService, 1)),
                Task.Run(() => Write1000Lines(logService, 2)),
                Task.Run(() => Write1000Lines(logService, 3)),
                Task.Run(() => Write1000Lines(logService, 4)));
            await t;
            await Task.Delay(TimeSpan.FromSeconds(5));

            // Assert
            Assert.IsTrue(t.IsCompleted);
            Assert.IsFalse(t.IsFaulted);
            Assert.AreEqual(logTarget.LineNumber, logTarget.LinesWrote.Count);
            Assert.AreEqual(4000, logTarget.LineNumber);
        }