Inheritance: CK.Core.ActivityMonitorTextHelperClient
Beispiel #1
0
        public void sending_log_from_client()
        {
            string logPath = TestHelper.PrepareLogFolder("sending_log_from_client");
            var    c       = new GrandOutputConfiguration()
                             .AddHandler(new Handlers.TextFileConfiguration()
            {
                Path = logPath
            })
                             .AddHandler(new Handlers.BinaryFileConfiguration()
            {
                Path = logPath
            });

            using (var g = new GrandOutput(c))
            {
                var m = new ActivityMonitor(false);
                g.EnsureGrandOutputClient(m);
                var txt = new StupidStringClient();
                m.Output.RegisterClient(txt);
                using (var r = SimpleLogPipeReceiver.Start(m, interProcess: false))
                {
                    RunClient(r.PipeName);
                    r.WaitEnd(false).Should().Be(LogReceiverEndStatus.Normal);
                }
                var stupidLogs = txt.ToString();
                stupidLogs.Should().Contain("From client.")
                .And.Contain("An Exception for the fun.")
                // StupidStringClient does not dump inner exception, only the top message.
                // .And.Contain( "With an inner exception!" )
                .And.Contain("Info n°0")
                .And.Contain("Info n°19");
            }
            // All temporary files have been closed.
            var fileNames = Directory.EnumerateFiles(logPath).ToList();

            fileNames.Should().NotContain(s => s.EndsWith(".tmp"));
            // Brutallity here: opening the binary file as a text.
            // It is enough to check the serialized strings.
            var texts = fileNames.Select(n => File.ReadAllText(n));

            foreach (var logs in texts)
            {
                logs.Should().Contain("From client.")
                .And.Contain("An Exception for the fun.")
                .And.Contain("With an inner exception!")
                .And.Contain("Info n°0")
                .And.Contain("Info n°19");
            }
        }