示例#1
0
        public void Test05FileSpecificPath()
        {
            var tempPath = Path.GetTempPath();
            var fileName = TempData.GetTempName();
            var filePath = Path.Combine(tempPath, fileName);

            using (var file = TempData.CreateFile(tempPath, fileName))
            {
                Assert.AreEqual(file.Path, filePath);
                Assert.IsNotNull(file.Info, "Info is null");
                Assert.IsTrue(file.Info.Exists, "File should exist");
            }
            Assert.IsFalse(File.Exists(filePath), "File should NOT exist");
        }
示例#2
0
        public void TestFileStreamSpecificPathSubDirectory()
        {
            var tempPath = Path.Combine(Path.GetTempPath(), TempData.GetTempName());

            Assert.IsFalse(Directory.Exists(tempPath), "Directory should NOT exist");
            var fileName = TempData.GetTempName();
            var filePath = Path.Combine(tempPath, fileName);

            using (var file = TempData.CreateFileStream(tempPath, fileName))
            {
                Assert.AreEqual(file.Name, filePath);
                Assert.IsTrue(File.Exists(filePath), "File should exist");
            }
            Assert.IsFalse(File.Exists(filePath), "File should NOT exist");
            Directory.Delete(tempPath);
        }
示例#3
0
        public void TestDirectorySpecificPathSubDirectory()
        {
            var tempPath = Path.Combine(Path.GetTempPath(), TempData.GetTempName());

            Assert.IsFalse(Directory.Exists(tempPath), "Directory should NOT exist");
            var dirName = TempData.GetTempName();
            var dirPath = Path.Combine(tempPath, dirName);

            using (var directory = TempData.CreateDirectory(tempPath, dirName))
            {
                Assert.AreEqual(directory.Path, dirPath);
                Assert.IsNotNull(directory.Info, "Info is null");
                Assert.IsTrue(directory.Info.Exists, "Directory should exist");
            }
            Assert.IsFalse(File.Exists(dirPath), "Directory should NOT exist");
            Directory.Delete(tempPath);
        }
示例#4
0
        public void TestFileWrapperWithCustomPath()
        {
            var tempPath = Path.GetTempPath();
            var fileName = TempData.GetTempName();
            var filePath = Path.Combine(tempPath, fileName);

            using (var file = new TempData.TempFile(filePath))
            {
                Assert.AreEqual(filePath, file.Path);
                NAssert.NotNull(file.Info, "Info is null");
                Assert.IsFalse(file.Info.Exists, "File should not exist");

                using (File.Create(filePath)) { }
                file.Info.Refresh();
                Assert.IsTrue(file.Info.Exists, "File should exist");
            }
            Assert.IsFalse(File.Exists(filePath), "File should NOT exist");
        }
示例#5
0
        public void Test03DirectorySpecificPath()
        {
            var tempPath = Path.GetTempPath();
            var dirName  = TempData.GetTempName();
            var dirPath  = Path.Combine(tempPath, dirName);

            using (var dir = TempData.CreateFile(tempPath, dirName))
            {
                Assert.AreEqual(dir.Path, dirPath);
                Assert.IsNotNull(dir.Info, "Info is null");
                Assert.IsTrue(dir.Info.Exists, "Directory should exist");
            }
            Assert.IsFalse(File.Exists(dirPath), "Directory should NOT exist");

            using (var dir = TempData.CreateFile(null, dirName))
            {
                Assert.AreEqual(dir.Path, dirPath);
                Assert.IsNotNull(dir.Info, "Info is null");
                Assert.IsTrue(dir.Info.Exists, "Directory should exist");
            }
            Assert.IsFalse(File.Exists(dirPath), "Directory should NOT exist");
        }