public void StructuredTextLoggerUsesHighestChildTypeToUpdateParentType()
        {
            //Arrange
            var analytics = new Mock<IAnalytics>();
            var logger = new StructuredTextLogger(@"x:\log.log", analytics.Object);
            var fileSystemInfo = GetTextLoggerMockFileSystem();
            const string message = "Message 1";
            const string error = "Error 1";
            FileSystemHelpers.Instance = fileSystemInfo.FileSystem;

            //Act
            var sublogger = logger.Log(message, LogEntryType.Message);
            sublogger.Log(error, LogEntryType.Error);
            var entries = logger.GetLogEntries();

            //Assert
            Assert.Equal(1, entries.Count());
            Assert.Equal(message, entries.First().Message);
            Assert.Equal(LogEntryType.Error, entries.First().Type);

            var subEntries = logger.GetLogEntryDetails(entries.First().Id);

            Assert.Equal(1, subEntries.Count());
            Assert.Equal(error, subEntries.First().Message);
            Assert.Equal(LogEntryType.Error, subEntries.First().Type);

            //Clean up
            fileSystemInfo.MemoryStream.RealDispose();
        }
예제 #2
0
        public void StructuredTextLoggerLogFunction(string message, LogEntryType type)
        {
            //Arrange
            var fileSystem = new Mock<IFileSystem>();
            var fileBase = new Mock<FileBase>();
            var stream = new TestMemoryStream();
            var analytics = new Mock<IAnalytics>();
            var logger = new StructuredTextLogger(@"x:\log.log", analytics.Object);

            fileSystem.Setup(f => f.File).Returns(fileBase.Object);

            fileBase.Setup(f => f.Open(It.IsAny<string>(), It.IsAny<FileMode>(), It.IsAny<FileAccess>(), It.IsAny<FileShare>()))
                    .Returns(stream);
            fileBase.Setup(f => f.OpenRead(It.IsAny<string>()))
                    .Returns((string path) => 
                    {
                        stream.Position = 0;
                        return stream;
                    });
            fileBase.Setup(f => f.ReadAllText(It.IsAny<string>()))
                    .Returns((string path) =>
                    {
                        using (var reader = new StreamReader(fileBase.Object.OpenRead(path)))
                        {
                            return reader.ReadToEnd();
                        }
                    });
            fileBase.Setup(f => f.ReadAllLines(It.IsAny<string>()))
                    .Returns((string path) =>
                    {
                        return fileBase.Object.ReadAllText(path).Split(new[] { System.Environment.NewLine }, StringSplitOptions.None);
                    });

            FileSystemHelpers.Instance = fileSystem.Object;

            //Act
            logger.Log(message, type);
            var entries = logger.GetLogEntries();

            //Assert
            Assert.Equal(1, entries.Count());
            Assert.Equal(message, entries.First().Message);
            Assert.Equal(type, entries.First().Type);
            stream.RealDispose();
        }
        public void StructuredTextLoggerLogFunction(string message, LogEntryType type)
        {
            //Arrange
            var analytics = new Mock<IAnalytics>();
            var logger = new StructuredTextLogger(@"x:\log.log", analytics.Object);
            var fileSystemInfo = GetTextLoggerMockFileSystem();
            FileSystemHelpers.Instance = fileSystemInfo.FileSystem;

            //Act
            logger.Log(message, type);
            var entries = logger.GetLogEntries();

            //Assert
            Assert.Equal(1, entries.Count());
            Assert.Equal(message, entries.First().Message);
            Assert.Equal(type, entries.First().Type);

            //Clean up
            fileSystemInfo.MemoryStream.RealDispose();
        }
예제 #4
0
        public void CreateDeployment(DeployResult deployResult, string details)
        {
            var id = deployResult.Id;
            string path = Path.Combine(_environment.DeploymentsPath, id);
            IDeploymentStatusFile statusFile = _status.Open(id);
            if (statusFile != null)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.Conflict, String.Format("Deployment with id '{0}' exists", id)));
            }

            FileSystemHelpers.EnsureDirectory(path);
            statusFile = _status.Create(id);
            statusFile.Status = deployResult.Status;
            statusFile.Message = deployResult.Message;
            statusFile.Deployer = deployResult.Deployer;
            statusFile.Author = deployResult.Author;
            statusFile.AuthorEmail = deployResult.AuthorEmail;
            statusFile.StartTime = deployResult.StartTime;
            statusFile.EndTime = deployResult.EndTime;

            // miscellaneous
            statusFile.Complete = true;
            statusFile.IsReadOnly = true;
            statusFile.IsTemporary = false;
            statusFile.ReceivedTime = deployResult.StartTime;
            // keep it simple regardless of success or failure
            statusFile.LastSuccessEndTime = deployResult.EndTime;
            statusFile.Save();

            if (deployResult.Current)
            {
                _status.ActiveDeploymentId = id;
            }

            var logger = new StructuredTextLogger(Path.Combine(path, DeploymentManager.TextLogFile), _analytics);
            ILogger innerLogger;
            if (deployResult.Status == DeployStatus.Success)
            {
                innerLogger = logger.Log("Deployment successful.");
            }
            else
            {
                innerLogger = logger.Log("Deployment failed.", LogEntryType.Error);
            }

            if (!String.IsNullOrEmpty(details))
            {
                innerLogger.Log(details);
            }
        }