Пример #1
0
        public void ApplyContextConfigMultiConfig()
        {
            var parser = new XMLLogParser();

            parser.SetConfig(logConfig);
            parser.SetRegistry(logRegistry);

            logRegistry.AddLog(Arg.Any <string>(), Arg.Any <string>()).Returns(logEntry);
            logRegistry.AddFailedLog().Returns(failedLogEntry);

            var configs = new Dictionary <ContextConfigs, object>
            {
                { ContextConfigs.LogSource, "tests" },
                { ContextConfigs.FailureHandling, LogParserFailureHandling.MarkEntriesAsFailed }
            };

            parser.ApplyContextConfig(configs, contextParser =>
            {
                Assert.That(Object.ReferenceEquals(contextParser, parser), Is.False);

                var log = "<fakelog time=\"goodtime\" log=\"my log1\"></fakelog><fakelog log=\"my log2\"></fakelog>";
                using (var ms = CreateStream(log))
                {
                    contextParser.Parse(ms);
                }
            });

            logRegistry.Received(1).AddLog("goodtime", "my log1");
            logRegistry.Received(1).AddFailedLog();
            logRegistry.Received(1).NotifyFailedLogParsed(failedLogEntry);
            logRegistry.Received(1).AddValueToLog(logEntry, LogAttribute.LogSource, "tests");
            logRegistry.Received(2).AddValueToLog(failedLogEntry, Arg.Is <LogAttribute>(att => att == LogAttribute.Message || att == LogAttribute.LogSource), Arg.Any <object>());
        }
Пример #2
0
        public void ApplyContextConfigLogParserFailureHandling()
        {
            var parser = new XMLLogParser();

            parser.SetConfig(logConfig);
            parser.SetRegistry(logRegistry);

            logRegistry.AddLog(Arg.Any <string>(), Arg.Any <string>()).Returns(logEntry);
            logRegistry.AddFailedLog().Returns(failedLogEntry);

            parser.ApplyContextConfig(ContextConfigs.FailureHandling, LogParserFailureHandling.MarkEntriesAsFailed, contextParser =>
            {
                Assert.That(Object.ReferenceEquals(contextParser, parser), Is.False);

                var log = "<fakelog time=\"goodtime\" log=\"my log1\"></fakelog><fakelog log=\"my log2\"></fakelog>";
                using (var ms = CreateStream(log))
                {
                    contextParser.Parse(ms);
                }
            });

            logRegistry.Received(1).AddLog("goodtime", "my log1");
            logRegistry.Received(1).AddFailedLog();
            logRegistry.Received(1).NotifyFailedLogParsed(failedLogEntry);
            logRegistry.DidNotReceive().AddValueToLog(logEntry, Arg.Any <LogAttribute>(), Arg.Any <object>());
            logRegistry.Received().AddValueToLog(failedLogEntry, LogAttribute.Message, Arg.Any <object>());
        }
Пример #3
0
        public void ApplyContextConfigLogSource()
        {
            var parser = new XMLLogParser();

            parser.SetConfig(logConfig);
            parser.SetRegistry(logRegistry);

            logRegistry.AddLog("goodtime", "my log").Returns(logEntry);

            var configs = new Dictionary <ContextConfigs, object>
            {
                { ContextConfigs.LogSource, "tests" }
            };

            parser.ApplyContextConfig(configs, contextParser =>
            {
                Assert.That(Object.ReferenceEquals(contextParser, parser), Is.False);

                var log = "<fakelog time=\"goodtime\" log=\"my log\"></fakelog>";
                using (var ms = CreateStream(log))
                {
                    contextParser.Parse(ms);
                }
            });

            logRegistry.Received().AddLog("goodtime", "my log");
            logRegistry.Received(1).AddValueToLog(logEntry, LogAttribute.LogSource, "tests");
        }
Пример #4
0
            public ILogParser Create(ILogRegistry registry, LogConfig config)
            {
                creationCounter.Increment();

                var parser = new XMLLogParser();

                parser.SetRegistry(registry);
                parser.SetConfig(config);
                return(parser);
            }
Пример #5
0
        public void ApplyContextConfigContextInvalid()
        {
            var parser = new XMLLogParser();

            parser.SetConfig(logConfig);
            parser.SetRegistry(logRegistry);

            Assert.Throws <ArgumentNullException>(() =>
            {
                parser.ApplyContextConfig(null, null);
            });
        }
Пример #6
0
        public void ApplyContextConfigLogHasRootInvalid()
        {
            var parser = new XMLLogParser();

            parser.SetConfig(logConfig);
            parser.SetRegistry(logRegistry);

            Assert.Throws <ArgumentException>(() =>
            {
                parser.ApplyContextConfig(ContextConfigs.LogHasRoot, "false", contextParser =>
                {
                });
            });
        }
Пример #7
0
        public void ApplyContextConfigLogParserFailureHandlingInvalid()
        {
            var parser = new XMLLogParser();

            parser.SetConfig(logConfig);
            parser.SetRegistry(logRegistry);

            Assert.Throws <ArgumentException>(() =>
            {
                parser.ApplyContextConfig(ContextConfigs.FailureHandling, false, contextParser =>
                {
                });
            });
        }
Пример #8
0
        public void BasicTestAsyncCancelled()
        {
            var parser = new XMLLogParser();

            parser.SetConfig(logConfig);
            parser.SetRegistry(logRegistry);

            logRegistry.AddLog("goodtime", "my log").Returns(logEntry);

            var cancellationToken = new System.Threading.CancellationToken(true);

            var log       = "<fakelog time=\"goodtime\" log=\"my log\"></fakelog>";
            var ms        = CreateStream(log);
            var parseTask = parser.ParseAsync(ms, cancellationToken);

            parseTask.ContinueWith(_ => ms.Dispose(), System.Threading.Tasks.TaskContinuationOptions.ExecuteSynchronously).Wait();

            logRegistry.DidNotReceive().AddLog(Arg.Any <string>(), Arg.Any <string>());
            logRegistry.DidNotReceive().AddValueToLog(logEntry, Arg.Any <LogAttribute>(), Arg.Any <object>());
        }
Пример #9
0
        public void ApplyContextConfigLogHasRoot()
        {
            var parser = new XMLLogParser();

            parser.SetConfig(logConfig);
            parser.SetRegistry(logRegistry);

            logRegistry.AddLog(Arg.Any <string>(), Arg.Any <string>()).Returns(logEntry);

            parser.ApplyContextConfig(ContextConfigs.LogHasRoot, true, contextParser =>
            {
                Assert.That(Object.ReferenceEquals(contextParser, parser), Is.False);

                var log = "<myroot><fakelog time=\"goodtime\" log=\"my log\"></fakelog></myroot>";
                using (var ms = CreateStream(log))
                {
                    contextParser.Parse(ms);
                }
            });

            logRegistry.Received(1).AddLog("goodtime", "my log");
            logRegistry.DidNotReceive().AddValueToLog(logEntry, Arg.Any <LogAttribute>(), Arg.Any <object>());
        }
Пример #10
0
        public void LogFile()
        {
            var tmpLogFile = Path.GetTempFileName();

            using (var sw = new StreamWriter(tmpLogFile))
            {
                sw.Write("<fakelog time=\"goodtime-file\" log=\"my log\"></fakelog>");
            }

            Console.WriteLine(tmpLogFile);

            var parser = new XMLLogParser();

            parser.SetConfig(logConfig);
            parser.SetRegistry(logRegistry);

            logRegistry.AddLog("goodtime-file", "my log").Returns(logEntry);

            parser.Parse(tmpLogFile);

            logRegistry.Received().AddLog("goodtime-file", "my log");
            logRegistry.DidNotReceive().AddValueToLog(logEntry, Arg.Any <LogAttribute>(), Arg.Any <object>());
        }