public void ShouldReturnEmptyEnumerableWhenNoFilesExistInDirectory()
        {
            var          directoryInfo = new DirectoryInfo(_temporaryDirectory);
            const string searchPattern = "*.xml";

            var actual = FileSystemAbstraction.EnumerateFiles(directoryInfo, searchPattern);

            Assert.IsFalse(actual.GetEnumerator().MoveNext());
        }
        public void ShouldReturnEmptyEnumerableWhenSearchPatternIsEmpty()
        {
            CreateFile(Path.Combine(_temporaryDirectory, "test.txt"));

            var          directoryInfo = new DirectoryInfo(_temporaryDirectory);
            const string searchPattern = "";

            var actual = FileSystemAbstraction.EnumerateFiles(directoryInfo, searchPattern);

            Assert.IsFalse(actual.GetEnumerator().MoveNext());
        }
        public void ShouldReturnAllFilesInDirectoryWhenSearchPatternIsAsterisk()
        {
            CreateFile(Path.Combine(_temporaryDirectory, "test.txt"));
            CreateFile(Path.Combine(_temporaryDirectory, "test.xml"));

            var          directoryInfo = new DirectoryInfo(_temporaryDirectory);
            const string searchPattern = "*";

            var actual = FileSystemAbstraction.EnumerateFiles(directoryInfo, searchPattern).ToList();

            Assert.AreEqual(2, actual.Count);
            Assert.IsTrue(actual.Exists(p => p.Name == "test.txt"));
            Assert.IsTrue(actual.Exists(p => p.Name == "test.xml"));
        }
        public void ShouldThrowDirectoryNotFoundExceptionWhenDirectoryDoesNotExist()
        {
            var          directoryInfo = new DirectoryInfo(_temporaryDirectory);
            const string searchPattern = "*.xml";

            Directory.Delete(_temporaryDirectory, true);

            try
            {
                FileSystemAbstraction.EnumerateFiles(directoryInfo, searchPattern);
                Assert.Fail();
            }
            catch (DirectoryNotFoundException)
            {
            }
        }
        public void ShouldThrowArgumentNullExceptionWhenSearchPatternIsNull()
        {
            var          directoryInfo = new DirectoryInfo(_temporaryDirectory);
            const string searchPattern = null;

            try
            {
                FileSystemAbstraction.EnumerateFiles(directoryInfo, searchPattern);
                Assert.Fail();
            }
            catch (ArgumentNullException ex)
            {
                Assert.IsNull(ex.InnerException);
                Assert.AreEqual("searchPattern", ex.ParamName);
            }
        }
        public void ShouldThrowArgumentNullExceptionWhenDirectoryInfoIsNull()
        {
            const DirectoryInfo directoryInfo = null;
            const string        searchPattern = "*.xml";

            try
            {
                FileSystemAbstraction.EnumerateFiles(directoryInfo, searchPattern);
                Assert.Fail();
            }
            catch (ArgumentNullException ex)
            {
                Assert.IsNull(ex.InnerException);
                Assert.AreEqual("directoryInfo", ex.ParamName);
            }
        }
        public void ShouldReturnOnlyReturnFilesFromTopLevelDirectory()
        {
            CreateFile(Path.Combine(_temporaryDirectory, "test.txt"));
            CreateFile(Path.Combine(_temporaryDirectory, "test.xml"));
            Directory.CreateDirectory(Path.Combine(_temporaryDirectory, "sub"));
            CreateFile(Path.Combine(_temporaryDirectory, "sub", "test.csv"));

            var          directoryInfo = new DirectoryInfo(_temporaryDirectory);
            const string searchPattern = "*";

            var actual = FileSystemAbstraction.EnumerateFiles(directoryInfo, searchPattern).ToList();

            Assert.AreEqual(2, actual.Count);
            Assert.IsTrue(actual.Exists(p => p.Name == "test.txt"));
            Assert.IsTrue(actual.Exists(p => p.Name == "test.xml"));
        }