Exemplo n.º 1
0
        public void LoggerEaseOfUse()
        {
            var expected = "testing";
            var myLogger = new XLogger();

            myLogger.LogInfo(expected);
            myLogger.LogError(expected);

            Assert.NotNull(myLogger);
            Assert.Equal(2, myLogger.OutputDocument.Root.Elements(XLogger.EntryElementName).Count());
            Assert.Equal(expected, myLogger.OutputDocument.Root.Element(XLogger.EntryElementName).Element(XLogger.DescriptionElementName).Value);
            Assert.Equal(expected, myLogger.OutputDocument.Root.Elements(XLogger.EntryElementName).Last().Element(XLogger.DescriptionElementName).Value);
        }
Exemplo n.º 2
0
        public void XLoggerLogInfoSpecialChars()
        {
            var expected         = "testing123info s a<>><)(*&^%$$#@!";
            var myLogger         = new XLogger();
            var loggedApproxDate = DateTime.Now;

            myLogger.LogInfo(expected);

            Assert.Single(myLogger.OutputDocument.Root.Elements(XLogger.EntryElementName));
            Assert.Equal(MessageSeverity.Information.ToString(), myLogger.OutputDocument.Root.Element(XLogger.EntryElementName).Element(XLogger.TypeElementName).Value);
            Assert.Equal(expected, myLogger.OutputDocument.Root.Element(XLogger.EntryElementName).Element(XLogger.DescriptionElementName).Value);
            if (loggedApproxDate.Minute != 59 || loggedApproxDate.Second < 59 || loggedApproxDate.Millisecond < 999)
            {
                Assert.Equal(loggedApproxDate.ToString("yy-MM-dd-HH"),
                             Convert.ToDateTime(myLogger.OutputDocument.Root.Element(XLogger.EntryElementName).Element(XLogger.TimeElementName).Value).ToString("yy-MM-dd-HH"));
            }
        }
Exemplo n.º 3
0
        public void XLoggerSavesToStream()
        {
            var testInfo = "info";
            var myLogger = new XLogger();
            var output   = new StringWriter();

            try
            {
                myLogger.LogInfo(testInfo);
                myLogger.Save(output);

                var actual   = XDocument.Parse(output.ToString());
                var expected = myLogger.OutputDocument;
                Assert.True(XNode.DeepEquals(expected, actual));
            }
            finally
            {
                output.Dispose();
            }
        }
Exemplo n.º 4
0
        public void XLoggerSavesToFile()
        {
            var expected = "info";
            var myLogger = new XLogger();
            var output   = new FileInfo("test.xml");

            try
            {
                myLogger.LogInfo(expected);
                myLogger.Save(output);
                Assert.True(File.Exists(output.FullName));

                var fromFile = XDocument.Load(output.FullName);
                Assert.True(XNode.DeepEquals(myLogger.OutputDocument, fromFile));
            }
            finally
            {
                output.Delete();
            }
        }
Exemplo n.º 5
0
        public void XLoggerSavesToFileTwiceAndTheFileIsValid()
        {
            var testInfo    = "info";
            var testWarning = "info";
            var myLogger    = new XLogger();
            var output      = new FileInfo("test.xml");

            try
            {
                myLogger.LogInfo(testInfo);
                myLogger.Save(output);
                myLogger.LogWarning(testWarning);
                myLogger.Save(output);

                var fromFile = XDocument.Load(output.FullName);
                Assert.True(XNode.DeepEquals(myLogger.OutputDocument, fromFile));
            }
            finally
            {
                output.Delete();
            }
        }