Example #1
0
        public void CleanupLogFilesShouldCallFileServiceToVerifyDirectoryExists()
        {
            //Arrange
            var jobConfig = new SiteCleanupConfiguration {
                SiteName = "Test Site", LogHistoryDaysToKeep = 2, DnnRootDirectoryPath = "/Test"
            };

            //Act
            _job.CleanupLogFiles(jobConfig);

            //Assert
            _localFileServiceMock.Verify(lfs => lfs.DirectoryExists(jobConfig.DnnRootDirectoryPath));
        }
Example #2
0
        public void CleanupLogFilesShouldLogSiteNameAsDebug()
        {
            //Arrange
            var jobConfig = new SiteCleanupConfiguration {
                SiteName = "Test Site"
            };

            //Act
            _job.CleanupLogFiles(jobConfig);

            //Assert
            _loggerMock.Verify(l => l.Debug($"Starting clean of {jobConfig.SiteName}"), Times.Once);
        }
Example #3
0
        public void CleanupLogFilesShouldLogErrorAndReturnIfDaysToKeepIsLessThan2()
        {
            //Arrange
            var jobConfig = new SiteCleanupConfiguration {
                SiteName = "Test Site"
            };

            //Act
            _job.CleanupLogFiles(jobConfig);

            //Assert
            _loggerMock.Verify(l => l.Error($"Unable to process, must keep at least 2 days of logs"), Times.Once);
            _localFileServiceMock.Verify(lfs => lfs.DirectoryExists(It.IsAny <string>()), Times.Never);
        }
Example #4
0
        public void CleanupLogFilesShouldLogErorIfDirectoryDoesNotExist()
        {
            //Arrange
            var jobConfig = new SiteCleanupConfiguration {
                SiteName = "Test Site", LogHistoryDaysToKeep = 2
            };

            _localFileServiceMock.Setup(lfs => lfs.DirectoryExists(jobConfig.DnnRootDirectoryPath)).Returns(false);

            //Act
            _job.CleanupLogFiles(jobConfig);

            //Assert
            _loggerMock.Verify(l => l.Error("Provided directory not fount, no further processing for this site"));
        }
        public void CleanupLogFiles(SiteCleanupConfiguration siteInfo)
        {
            _log.Debug($"Starting clean of {siteInfo.SiteName}");
            if (siteInfo.LogHistoryDaysToKeep < 2)
            {
                _log.Error("Unable to process, must keep at least 2 days of logs");
                return;
            }

            var directoryExists = _localFileService.DirectoryExists(siteInfo.DnnRootDirectoryPath);

            if (!directoryExists)
            {
                _log.Error("Provided directory not fount, no further processing for this site");
                return;
            }

            //Verify that it is a DNN install
            var dnnLogPath   = _localFileService.BuildDnnLogFolderPath(siteInfo.DnnRootDirectoryPath);
            var dnnLogExists = _localFileService.DirectoryExists(dnnLogPath);

            if (!dnnLogExists)
            {
                _log.Error($"Unable to find DNN log folder.  Looked in '{dnnLogPath}'");
                return;
            }

            //Get the list of log files
            _log.Debug($"Searching for files in {dnnLogPath}");
            var logFiles = _localFileService.FindFiles(dnnLogPath, "*.log.resources");

            if (logFiles.Count > siteInfo.LogHistoryDaysToKeep)
            {
                //Get the to delete files
                var toDelete = logFiles.OrderByDescending(lf => lf.CreationTimeUtc).Skip(siteInfo.LogHistoryDaysToKeep);
                foreach (var fileToDelete in toDelete)
                {
                    _log.Debug($"Deleting {fileToDelete.FullName}");
                    _localFileService.DeleteFile(fileToDelete.FullName);
                }
            }
            else
            {
                _log.Debug(
                    $"Found {logFiles.Count} files and log rules allow for up to {siteInfo.LogHistoryDaysToKeep} no action taken");
            }
        }
Example #6
0
        public void CleanupLogFileShouldCallFileServiceToGetDnnLogDirectory()
        {
            //Arrange
            var jobConfig = new SiteCleanupConfiguration {
                SiteName = "Test Site", LogHistoryDaysToKeep = 2
            };
            var fullPath = string.Empty;

            _localFileServiceMock.Setup(lfs => lfs.DirectoryExists(jobConfig.DnnRootDirectoryPath)).Returns(true);
            _localFileServiceMock.Setup(lfs => lfs.BuildDnnLogFolderPath(jobConfig.DnnRootDirectoryPath))
            .Returns(fullPath);

            //Act
            _job.CleanupLogFiles(jobConfig);

            //Assert
            _localFileServiceMock.Verify(lfs => lfs.BuildDnnLogFolderPath(jobConfig.DnnRootDirectoryPath), Times.Once);
        }
Example #7
0
        public void CleanupLogFileShouldLogErrorIfDnnLogPathIsNotFound()
        {
            //Arrange
            var jobConfig = new SiteCleanupConfiguration {
                SiteName = "Test Site", LogHistoryDaysToKeep = 2
            };
            var fullPath = "";

            _localFileServiceMock.Setup(lfs => lfs.DirectoryExists(jobConfig.DnnRootDirectoryPath)).Returns(true);
            _localFileServiceMock.Setup(lfs => lfs.BuildDnnLogFolderPath(jobConfig.DnnRootDirectoryPath))
            .Returns(fullPath);
            _localFileServiceMock.Setup(lfs => lfs.DirectoryExists(fullPath)).Returns(false);

            //Act
            _job.CleanupLogFiles(jobConfig);

            //Assert

            //Assert
            _loggerMock.Verify(lm => lm.Error($"Unable to find DNN log folder.  Looked in '{fullPath}'"), Times.Once);
        }