Beispiel #1
0
        public void ShouldKeepOnly2Files()
        {
            DateTime startDateOfLastWrite = DateTime.Now.AddDays(-5);

            CreateLogFiles(startDateOfLastWrite, 1, 50);

            Assert.AreEqual(Directory.GetFiles(_logFolder).Count(), 50);

            var sut = new LogFileArchiver(new FileSystemFactory(""), _archiveLocation, fileSystemType);

            sut.Start(_logFolder, TimeSpan.FromSeconds(1));
            Thread.Sleep(TimeSpan.FromSeconds(2));

            Assert.AreEqual(2, Directory.GetFiles(_logFolder).Count());
        }
Beispiel #2
0
        public void ShouldDeleteFilesOldestFiles()
        {
            DateTime startDateOfLastWrite = DateTime.Now.AddDays(-5);

            CreateLogFiles(startDateOfLastWrite, 1, 50);

            Assert.AreEqual(Directory.GetFiles(_logFolder).Count(), 50);

            var sut = new LogFileArchiver(new FileSystemFactory(""), _archiveLocation, fileSystemType);

            sut.Start(_logFolder, TimeSpan.FromSeconds(1));
            Thread.Sleep(TimeSpan.FromSeconds(2));

            startDateOfLastWrite = startDateOfLastWrite.AddMinutes(1 * 20);

            var fileInfos = new DirectoryInfo(_logFolder).GetFiles("*." + Constants.JarFileExtension)
                            .OrderBy(f => f.LastWriteTime)
                            .ToList();

            Assert.GreaterOrEqual(fileInfos[0].LastWriteTime, startDateOfLastWrite);
        }