Пример #1
0
        public void Should_log_serilog_with_context()
        {
            var logger = MemoryLogger.Serilog <MemoryLoggerTests>();

            logger.instance.Debug("some");
            logger.messages.Count.Should().Be(1);
            logger.messages[0].Should().Be($"[{GetType().FullName}] some");
        }
Пример #2
0
        public void Should_log_serilog_without_context()
        {
            var logger = MemoryLogger.Serilog();

            logger.instance.Debug("some");
            logger.messages.Count.Should().Be(1);
            logger.messages[0].Should().Be("some");
        }
Пример #3
0
        public void Should_return_completed_task_on_success()
        {
            var logger = MemoryLogger.Serilog();
            var t      = logger.instance.Swallow(async() =>
            {
                await Task.Delay(1);
            });

            t.Wait(5000).Should().BeTrue();
            t.IsCompletedSuccessfully.Should().BeTrue();
            logger.messages.Count.Should().Be(0);
        }
Пример #4
0
        public void Should_write_logs_on_success()
        {
            var details = 101;
            var logger  = MemoryLogger.Serilog <TimingTests>();

            new Timing()
            .Logger(logger.instance)
            .Context("ctx")
            .FailureDetails(() => $"{details++}")
            .Timeout(10000)
            .Expect(() => true);

            logger.messages[0].Should().Be("[maxbl4.Infrastructure.Tests.TimingTests] Should_write_logs_on_success => Begin wait ctx");
            logger.messages[1].Should().MatchRegex(@"\[maxbl4.Infrastructure.Tests.TimingTests\] Should_write_logs_on_success => Wait success ctx after 00:00:00.\d+");
        }
Пример #5
0
        public void Should_throw_with_caller_name()
        {
            var details = 101;
            var logger  = MemoryLogger.Serilog <TimingTests>();
            var ex      = Assert.Throws <TimeoutException>(() =>
                                                           new Timing()
                                                           .Logger(logger.instance)
                                                           .Context("ctx")
                                                           .FailureDetails(() => $"{details++}")
                                                           .Timeout(10)
                                                           .Expect(() => false));

            ex.Message.Should().MatchRegex(@"\[Should_throw_with_caller_name\] Wait failed ctx after 00:00:00.\d+ details 101");
            logger.messages[0].Should().Be("[maxbl4.Infrastructure.Tests.TimingTests] Should_throw_with_caller_name => Begin wait ctx");
            logger.messages[1].Should().MatchRegex(@"\[maxbl4.Infrastructure.Tests.TimingTests\] Should_throw_with_caller_name => Wait failed ctx after 00:00:00.\d+ details 101");
        }
Пример #6
0
        public void Should_call_on_error_and_log()
        {
            var logger = MemoryLogger.Serilog();

            logger.instance.Swallow(() =>
            {
                logger.instance.Information("aaaaaa");
                throw new ArgumentException();
            }, e =>
            {
                logger.instance.Information("bbbbbb");
                throw new ArgumentOutOfRangeException();
            });
            logger.messages.Count.Should().Be(4);
            logger.messages.Should().Contain(x => x.Contains("aaaaa"));
            logger.messages.Should().Contain(x => x.Contains("bbbbb"));
        }
Пример #7
0
        public void Should_continue_observable_after_many_exceptions()
        {
            var logger  = MemoryLogger.Serilog();
            var subject = new Subject <int>();

            var s = "";

            subject.Subscribe(x =>
                              logger.instance.Swallow(() => {
                s += x;
                throw new ArgumentException();
            }));

            subject.OnNext(1);
            subject.OnNext(2);
            s.Should().Be("12");
            logger.messages.Count.Should().Be(2);
        }