Example #1
0
        public void ArchiveAFileWhenTimeIsDue()
        {
            if (IsRunningOnMono)
            {
                Assert.Inconclusive("This test doesnt run on mono, this senerio need to be tetsed manually");
            }

            Delete("MyLog.Tests.1.txt");
            Delete("MyLog.Tests.txt");

            using (var file = new FileStreamProvider(new FileConfiguration()
                {
                    FilePath = @"MyLog.Tests.txt",
                    ArchiveNumbering = ArchiveNumberingOptions.Sequence,
                    Archive = true,
                    AppendToEnd = true,
                    ArchiveEvery = ArchiveOptions.Month,
                }).GetStream())
            {
                file.Write(new byte[1024], 0, 1024);
            }

            using (var file = new FileStreamProvider(new FileConfiguration()
                {
                    FilePath = @"MyLog.Tests.txt",
                    ArchiveNumbering = ArchiveNumberingOptions.Sequence,
                    Archive = true,
                    AppendToEnd = true,
                    ArchiveEvery = ArchiveOptions.Month,
                }).GetStream())
            {
                Assert.AreEqual(1024, file.Length);
            }

            Assert.IsTrue(System.IO.File.Exists("MyLog.Tests.txt"));
            Assert.IsFalse(System.IO.File.Exists("MyLog.Tests.1.txt"));

            // Not working on mono:
            new FileInfo("MyLog.Tests.txt").CreationTime = DateTime.Now.Subtract(TimeSpan.FromDays(100));

            using (var file = new FileStreamProvider(new FileConfiguration()
                {
                    FilePath = @"MyLog.Tests.txt",
                    ArchiveNumbering = ArchiveNumberingOptions.Sequence,
                    Archive = true,
                    AppendToEnd = true,
                    ArchiveEvery = ArchiveOptions.Month,
                }).GetStream())
            {
                Assert.AreEqual(0, file.Length);
            }

            Assert.IsTrue(System.IO.File.Exists("MyLog.Tests.txt"));
            Assert.IsTrue(System.IO.File.Exists("MyLog.Tests.1.txt"));

            Assert.AreEqual(0, new FileInfo("MyLog.Tests.txt").Length);
            Assert.AreEqual(1024, new FileInfo("MyLog.Tests.1.txt").Length);
        }
Example #2
0
        public void ArchiveingAFileUsingSequenceWorks()
        {
            Delete("MyLog.Tests.2.txt");
            Delete("MyLog.Tests.1.txt");
            Delete("MyLog.Tests.txt");

            using (var file = new FileStreamProvider(new FileConfiguration()
                {
                    FilePath = @"MyLog.Tests.txt",
                    ArchiveNumbering = ArchiveNumberingOptions.Sequence,
                    Archive = true,
                }).GetStream())
            {
                file.Write(new byte[1024],0,1024);
            }

            using (var file = new FileStreamProvider(new FileConfiguration()
                {
                    FilePath = @"MyLog.Tests.txt",
                    ArchiveNumbering = ArchiveNumberingOptions.Sequence,
                    Archive = true,
                }).GetStream())
            {
                file.Write(new byte[100], 0, 100);
            }

            Assert.IsTrue(System.IO.File.Exists("MyLog.Tests.txt"));
            Assert.IsTrue(System.IO.File.Exists("MyLog.Tests.1.txt"));

            Assert.AreEqual(100, new FileInfo("MyLog.Tests.txt").Length);
            Assert.AreEqual(1024, new FileInfo("MyLog.Tests.1.txt").Length);

            using (new FileStreamProvider(new FileConfiguration()
                {
                    FilePath = @"MyLog.Tests.txt",
                    ArchiveNumbering = ArchiveNumberingOptions.Sequence,
                    Archive = true,
                }).GetStream())
            {

            }

            Assert.IsTrue(System.IO.File.Exists("MyLog.Tests.2.txt"));

            Assert.AreEqual(0, new FileInfo("MyLog.Tests.txt").Length);
            Assert.AreEqual(100, new FileInfo("MyLog.Tests.2.txt").Length);
            Assert.AreEqual(1024, new FileInfo("MyLog.Tests.1.txt").Length);

            Delete("MyLog.Tests.2.txt");
            Delete("MyLog.Tests.1.txt");
            Delete("MyLog.Tests.txt");
        }