Exemple #1
0
        public void TestFileExists()
        {
            Exception ex;
            string    filePath;

            using (var file = TempData.CreateFile())
            {
                filePath = file.Path;
                Assert.DoesNotThrow(() => IoCode.FileExists(file.Path, "arg00"));

                ex = Assert.Throws <IOException>(() => IoCode.PathIsFree(filePath));
                Assert.That(ex.Message, Does.Contain(filePath));

                ex = Assert.Throws <DirectoryNotFoundException>(() => IoCode.DirectoryExists(filePath, "arg00"));
                Assert.That(ex.Message, Does.Contain("arg00"));
                Assert.That(ex.Message, Does.Contain("is a file"));
                Assert.That(ex.Message, Does.Contain(filePath));
            }

            Assert.DoesNotThrow(() => IoCode.PathIsFree(filePath));

            ex = Assert.Throws <FileNotFoundException>(() => IoCode.FileExists(filePath, "arg00"));
            Assert.That(ex.Message, Does.Contain("arg00"));
            Assert.That(ex.Message, Does.Contain(filePath));
        }
Exemple #2
0
        public void TestDirectoryExists()
        {
            Exception ex;
            string    dirPath;

            using (var dir = TempData.CreateDirectory())
            {
                dirPath = dir.Path;
                Assert.DoesNotThrow(() => IoCode.DirectoryExists(dir.Path, "arg00"));

                ex = Assert.Throws <IOException>(() => IoCode.PathIsFree(dirPath));
                Assert.That(ex.Message, Does.Contain(dirPath));

                ex = Assert.Throws <FileNotFoundException>(() => IoCode.FileExists(dirPath, "arg00"));
                Assert.That(ex.Message, Does.Contain("arg00"));
                Assert.That(ex.Message, Does.Contain("is a directory"));
                Assert.That(ex.Message, Does.Contain(dirPath));
            }

            Assert.DoesNotThrow(() => IoCode.PathIsFree(dirPath));
            ex = Assert.Throws <DirectoryNotFoundException>(() => IoCode.DirectoryExists(dirPath, "arg00"));
            Assert.That(ex.Message, Does.Contain("arg00"));
            Assert.That(ex.Message, Does.Contain(dirPath));
        }