예제 #1
0
        public static void TestMethods()
        {
            string           tempFileName    = Path.GetTempFileName();
            IRuntimeFileInfo runtimeFileInfo = new RuntimeFileInfo(tempFileName);

            try
            {
                using (Stream writeStream = runtimeFileInfo.OpenWrite())
                {
                    using (TextWriter writer = new StreamWriter(writeStream))
                    {
                        writer.Write("This is AxCrypt!");
                    }
                }
                using (Stream readStream = runtimeFileInfo.OpenRead())
                {
                    using (TextReader reader = new StreamReader(readStream))
                    {
                        string text = reader.ReadToEnd();

                        Assert.That(text, Is.EqualTo("This is AxCrypt!"), "What was written should be read.");
                    }
                }

                DateTime dateTime = DateTime.Parse("2012-02-29 12:00:00", CultureInfo.GetCultureInfo("sv-SE"), DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal);
                runtimeFileInfo.SetFileTimes(dateTime, dateTime + new TimeSpan(3, 0, 0), dateTime + new TimeSpan(5, 0, 0));
                if (OS.Current.Platform == Platform.WindowsDesktop)
                {
                    Assert.That(runtimeFileInfo.CreationTimeUtc, Is.EqualTo(dateTime), "The creation time should be as set.");
                }
                else
                {
                    Assert.That(runtimeFileInfo.CreationTimeUtc, Is.EqualTo(dateTime + new TimeSpan(5, 0, 0)), "The creation time should be as last write time due to bug in Mono.");
                }
                Assert.That(runtimeFileInfo.LastAccessTimeUtc, Is.EqualTo(dateTime + new TimeSpan(3, 0, 0)), "The last access time should be as set.");
                Assert.That(runtimeFileInfo.LastWriteTimeUtc, Is.EqualTo(dateTime + new TimeSpan(5, 0, 0)), "The last write time should be as set.");

                Assert.That(runtimeFileInfo.FullName, Is.EqualTo(tempFileName), "The FullName should be the same as the underlying FileInfo.FullName.");

                string           otherTempFileName        = runtimeFileInfo.FullName + ".copy";
                IRuntimeFileInfo otherTempRuntimeFileInfo = new RuntimeFileInfo(otherTempFileName);
                Assert.That(otherTempRuntimeFileInfo.Exists, Is.False, "The new temp file should not exist.");
                Assert.That(runtimeFileInfo.Exists, Is.True, "The old temp file should exist.");
                runtimeFileInfo.MoveTo(otherTempRuntimeFileInfo.FullName);
                Assert.That(otherTempRuntimeFileInfo.Exists, Is.True, "The new temp file should exist after moving the old here.");
                Assert.That(runtimeFileInfo.Exists, Is.True, "The old temp file should exist still because it has changed to refer to the new file.");
            }
            finally
            {
                runtimeFileInfo.Delete();
            }
            Assert.That(runtimeFileInfo.Exists, Is.False, "The file should have been deleted now.");

            IRuntimeFileInfo notEncryptedRuntimeFileInfo = new RuntimeFileInfo("file.txt");
            IRuntimeFileInfo encryptedRuntimeFileInfo    = notEncryptedRuntimeFileInfo.CreateEncryptedName();

            Assert.That(encryptedRuntimeFileInfo.Name, Is.EqualTo("file-txt.axx"), "The encrypted name should be as expected.");
        }
예제 #2
0
        public static void TestBadArguments()
        {
            Assert.Throws<ArgumentNullException>(() =>
            {
                RuntimeFileInfo rfi = new RuntimeFileInfo(null);

                // Avoid FxCop error
                Object.Equals(rfi, null);
            });
        }
예제 #3
0
        public static void TestBadArguments()
        {
            Assert.Throws <ArgumentNullException>(() =>
            {
                RuntimeFileInfo rfi = new RuntimeFileInfo(null);

                // Avoid FxCop error
                Object.Equals(rfi, null);
            });
        }
예제 #4
0
 public static void TestCreateDirectory()
 {
     string testTempFolder = Path.Combine(Path.GetTempPath(), "AxantumTestCreateDirectory" + Path.DirectorySeparatorChar);
     if (Directory.Exists(testTempFolder))
     {
         Directory.Delete(testTempFolder, true);
     }
     Assert.That(Directory.Exists(testTempFolder), Is.False, "The test folder should not exist now.");
     IRuntimeFileInfo directoryInfo = new RuntimeFileInfo(testTempFolder);
     directoryInfo.CreateFolder();
     Assert.That(Directory.Exists(testTempFolder), Is.True, "The test folder should exist now.");
     if (Directory.Exists(testTempFolder))
     {
         Directory.Delete(testTempFolder, true);
     }
 }
예제 #5
0
        public static void TestCreateDirectory()
        {
            string testTempFolder = Path.Combine(Path.GetTempPath(), "AxantumTestCreateDirectory" + Path.DirectorySeparatorChar);

            if (Directory.Exists(testTempFolder))
            {
                Directory.Delete(testTempFolder, true);
            }
            Assert.That(Directory.Exists(testTempFolder), Is.False, "The test folder should not exist now.");
            IRuntimeFileInfo directoryInfo = new RuntimeFileInfo(testTempFolder);

            directoryInfo.CreateFolder();
            Assert.That(Directory.Exists(testTempFolder), Is.True, "The test folder should exist now.");
            if (Directory.Exists(testTempFolder))
            {
                Directory.Delete(testTempFolder, true);
            }
        }
예제 #6
0
        public static void TestMethods()
        {
            string tempFileName = Path.GetTempFileName();
            IRuntimeFileInfo runtimeFileInfo = new RuntimeFileInfo(tempFileName);
            try
            {
                using (Stream writeStream = runtimeFileInfo.OpenWrite())
                {
                    using (TextWriter writer = new StreamWriter(writeStream))
                    {
                        writer.Write("This is AxCrypt!");
                    }
                }
                using (Stream readStream = runtimeFileInfo.OpenRead())
                {
                    using (TextReader reader = new StreamReader(readStream))
                    {
                        string text = reader.ReadToEnd();

                        Assert.That(text, Is.EqualTo("This is AxCrypt!"), "What was written should be read.");
                    }
                }

                DateTime dateTime = DateTime.Parse("2012-02-29 12:00:00", CultureInfo.GetCultureInfo("sv-SE"), DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal);
                runtimeFileInfo.SetFileTimes(dateTime, dateTime + new TimeSpan(3, 0, 0), dateTime + new TimeSpan(5, 0, 0));
                if (OS.Current.Platform == Platform.WindowsDesktop)
                {
                    Assert.That(runtimeFileInfo.CreationTimeUtc, Is.EqualTo(dateTime), "The creation time should be as set.");
                }
                else
                {
                    Assert.That(runtimeFileInfo.CreationTimeUtc, Is.EqualTo(dateTime + new TimeSpan(5, 0, 0)), "The creation time should be as last write time due to bug in Mono.");
                }
                Assert.That(runtimeFileInfo.LastAccessTimeUtc, Is.EqualTo(dateTime + new TimeSpan(3, 0, 0)), "The last access time should be as set.");
                Assert.That(runtimeFileInfo.LastWriteTimeUtc, Is.EqualTo(dateTime + new TimeSpan(5, 0, 0)), "The last write time should be as set.");

                Assert.That(runtimeFileInfo.FullName, Is.EqualTo(tempFileName), "The FullName should be the same as the underlying FileInfo.FullName.");

                string otherTempFileName = runtimeFileInfo.FullName + ".copy";
                IRuntimeFileInfo otherTempRuntimeFileInfo = new RuntimeFileInfo(otherTempFileName);
                Assert.That(otherTempRuntimeFileInfo.Exists, Is.False, "The new temp file should not exist.");
                Assert.That(runtimeFileInfo.Exists, Is.True, "The old temp file should exist.");
                runtimeFileInfo.MoveTo(otherTempRuntimeFileInfo.FullName);
                Assert.That(otherTempRuntimeFileInfo.Exists, Is.True, "The new temp file should exist after moving the old here.");
                Assert.That(runtimeFileInfo.Exists, Is.True, "The old temp file should exist still because it has changed to refer to the new file.");
            }
            finally
            {
                runtimeFileInfo.Delete();
            }
            Assert.That(runtimeFileInfo.Exists, Is.False, "The file should have been deleted now.");

            IRuntimeFileInfo notEncryptedRuntimeFileInfo = new RuntimeFileInfo("file.txt");
            IRuntimeFileInfo encryptedRuntimeFileInfo = notEncryptedRuntimeFileInfo.CreateEncryptedName();
            Assert.That(encryptedRuntimeFileInfo.Name, Is.EqualTo("file-txt.axx"), "The encrypted name should be as expected.");
        }