Example #1
0
        public void XmlLoggerBasicTest()
        {
            var path = @"x:\deployments\1234\log.xml";
            var fileSystem = new Mock<IFileSystem>();
            var file = new Mock<FileBase>();
            var id = Guid.NewGuid().ToString();
            var message = Guid.NewGuid().ToString();
            var doc = new XDocument(new XElement("entries", 
                new XElement("entry",
                    new XAttribute("time", "2013-12-08T01:58:24.0247841Z"),
                    new XAttribute("id", id),
                    new XAttribute("type", "0"),
                    new XElement("message", message)
                )
            ));
            var mem = new MemoryStream();
            doc.Save(mem);

            // Setup
            fileSystem.SetupGet(f => f.File)
                      .Returns(file.Object);
            file.Setup(f => f.Exists(path))
                .Returns(true);
            file.Setup(f => f.OpenRead(path))
                .Returns(() => { mem.Position = 0; return mem; });

            // Test
            var logger = new XmlLogger(fileSystem.Object, path, Mock.Of<IAnalytics>());
            var entries = logger.GetLogEntries();

            // Assert
            Assert.Equal(1, entries.Count());
            Assert.Equal(id, entries.First().Id);
            Assert.Equal(message, entries.First().Message);
        }
Example #2
0
        public IEnumerable <LogEntry> GetLogEntries(string id)
        {
            ITracer tracer = _traceFactory.GetTracer();

            using (tracer.Step("DeploymentManager.GetLogEntries(id)"))
            {
                string path = GetLogPath(id, ensureDirectory: false);

                if (!_fileSystem.File.Exists(path))
                {
                    throw new FileNotFoundException(String.Format(CultureInfo.CurrentCulture, Resources.Error_NoLogFound, id));
                }

                VerifyDeployment(id);

                var             logger  = new XmlLogger(_fileSystem, path);
                List <LogEntry> entries = logger.GetLogEntries().ToList();

                // Determine if there's details to show at all
                foreach (var e in entries)
                {
                    e.HasDetails = logger.GetLogEntryDetails(e.Id).Any();
                }

                return(entries);
            }
        }
Example #3
0
        private ILogger GetLogger(string id)
        {
            var path      = GetLogPath(id);
            var xmlLogger = new XmlLogger(_fileSystem, path);

            return(new CascadeLogger(xmlLogger, _globalLogger));
        }
Example #4
0
        public ILogger GetLogger(string id)
        {
            var path      = GetLogPath(id);
            var xmlLogger = new XmlLogger(path, _analytics);

            return(new ProgressLogger(id, _status, new CascadeLogger(xmlLogger, _globalLogger)));
        }
Example #5
0
        public ILogger GetLogger(string id)
        {
            var path      = GetLogPath(id);
            var xmlLogger = new XmlLogger(_fileSystem, path);

            return(new ProgressLogger(id, _status, new CascadeLogger(xmlLogger, _globalLogger)));
        }
Example #6
0
        public void XmlLoggerFileNotExistTest()
        {
            var path = @"x:\deployments\1234\log.xml";
            var fileSystem = new Mock<IFileSystem>();

            // Setup
            fileSystem.SetupGet(f => f.File)
                      .Returns(Mock.Of<FileBase>());

            // Test
            var logger = new XmlLogger(fileSystem.Object, path, Mock.Of<IAnalytics>());
            var entries = logger.GetLogEntries();
            
            // Assert
            Assert.Equal(0, entries.Count());
        }
Example #7
0
        public IEnumerable <LogEntry> GetLogEntryDetails(string id, string entryId)
        {
            ITracer tracer = _traceFactory.GetTracer();

            using (tracer.Step("DeploymentManager.GetLogEntryDetails(id, entryId)"))
            {
                string path = GetLogPath(id, ensureDirectory: false);

                if (!_fileSystem.File.Exists(path))
                {
                    throw new FileNotFoundException(String.Format(CultureInfo.CurrentCulture, Resources.Error_NoLogFound, id));
                }

                VerifyDeployment(id);

                var logger = new XmlLogger(_fileSystem, path);

                return(logger.GetLogEntryDetails(entryId).ToList());
            }
        }
Example #8
0
        public void XmlLoggerMalformedXmlTest()
        {
            var path = @"x:\deployments\1234\log.xml";
            var fileSystem = new Mock<IFileSystem>();
            var file = new Mock<FileBase>();
            var analytics = new Mock<IAnalytics>();
            var bytes = Encoding.UTF8.GetBytes("<invalid xml");
            var mem = new MemoryStream();
            mem.Write(bytes, 0, bytes.Length);

            // Setup
            fileSystem.SetupGet(f => f.File)
                      .Returns(file.Object);
            file.Setup(f => f.Exists(path))
                .Returns(true);
            file.Setup(f => f.OpenRead(path))
                .Returns(() => { mem.Position = 0; return mem; });

            // Test
            var logger = new XmlLogger(fileSystem.Object, path, analytics.Object);
            var entries = logger.GetLogEntries();

            // Assert
            Assert.Equal(0, entries.Count());
            analytics.Verify(a => a.UnexpectedException(It.IsAny<Exception>()), Times.Once);
        }
Example #9
0
 private ILogger GetLogger(string id)
 {
     var path = GetLogPath(id);
     var xmlLogger = new XmlLogger(_fileSystem, path);
     return new CascadeLogger(xmlLogger, _globalLogger);
 }
Example #10
0
        public IEnumerable<LogEntry> GetLogEntryDetails(string id, string entryId)
        {
            ITracer tracer = _traceFactory.GetTracer();
            using (tracer.Step("DeploymentManager.GetLogEntryDetails(id, entryId)"))
            {
                string path = GetLogPath(id, ensureDirectory: false);

                if (!_fileSystem.File.Exists(path))
                {
                    throw new FileNotFoundException(String.Format(CultureInfo.CurrentCulture, Resources.Error_NoLogFound, id));
                }

                VerifyDeployment(id);

                var logger = new XmlLogger(_fileSystem, path);

                return logger.GetLogEntryDetails(entryId).ToList();
            }
        }
Example #11
0
        public IEnumerable<LogEntry> GetLogEntries(string id)
        {
            ITracer tracer = _traceFactory.GetTracer();
            using (tracer.Step("DeploymentManager.GetLogEntries(id)"))
            {
                string path = GetLogPath(id, ensureDirectory: false);

                if (!_fileSystem.File.Exists(path))
                {
                    throw new FileNotFoundException(String.Format(CultureInfo.CurrentCulture, Resources.Error_NoLogFound, id));
                }

                VerifyDeployment(id);

                var logger = new XmlLogger(_fileSystem, path);
                List<LogEntry> entries = logger.GetLogEntries().ToList();

                // Determine if there's details to show at all
                foreach (var e in entries)
                {
                    e.HasDetails = logger.GetLogEntryDetails(e.Id).Any();
                }

                return entries;
            }
        }
Example #12
0
 public InnerXmlLogger(XmlLogger parent, XElement element)
 {
     _parent  = parent;
     _element = element;
 }
Example #13
0
 public ILogger GetLogger(string id)
 {
     var path = GetLogPath(id);
     var xmlLogger = new XmlLogger(_fileSystem, path);
     return new ProgressLogger(id, _status, new CascadeLogger(xmlLogger, _globalLogger));
 }
 public ILogger GetLogger(string id)
 {
     var path = GetLogPath(id);
     var xmlLogger = new XmlLogger(path, _analytics);
     return new ProgressLogger(id, _status, new CascadeLogger(xmlLogger, _globalLogger));
 }
Example #15
0
 public InnerXmlLogger(XmlLogger parent, XElement element)
 {
     _parent = parent;
     _element = element;
 }