2
Vote

Searchpattern works wrong

description

Following Test doesn't work:
        [Test]
        public void MockDirectory_GetDirectories_TestPatterns()
        {
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                { @"c:\folder1\folder2\folder3\file.txt", new MockFileData("Demo text content") },
                { @"c:\folder1\folder4\file2.txt", new MockFileData("Demo text content 2") },
            });


            var dirInfo = fileSystem.DirectoryInfo.FromDirectoryName(@"c:\folder1\");

            var directories = dirInfo.GetDirectories(@"folder*").ToLookup(p => p.FullName);

            //Check that it does not returns itself
            Assert.IsFalse(directories.Contains(@"c:\folder1\"));

            //Check that it correctly returns all child directories
            Assert.AreEqual(2, directories.Count());
            Assert.IsTrue(directories.Contains(@"c:\folder1\folder2\"));
            Assert.IsTrue(directories.Contains(@"c:\folder1\folder4\"));

            directories = dirInfo.GetDirectories(@"*").ToLookup(p => p.FullName);
            //Check that it does not returns itself
            Assert.IsFalse(directories.Contains(@"c:\folder1\"));

            //Check that it correctly returns all child directories
            Assert.AreEqual(2, directories.Count());
            Assert.IsTrue(directories.Contains(@"c:\folder1\folder2\"));
            Assert.IsTrue(directories.Contains(@"c:\folder1\folder4\"));

            directories = dirInfo.GetDirectories(@"*.*").ToLookup(p => p.FullName);
            //Check that it does not returns itself
            Assert.IsFalse(directories.Contains(@"c:\folder1\"));

            //Check that it correctly returns all child directories
            Assert.AreEqual(2, directories.Count());
            Assert.IsTrue(directories.Contains(@"c:\folder1\folder2\"));
            Assert.IsTrue(directories.Contains(@"c:\folder1\folder4\"));
        }
fast the same Test for local file system works:
        [Test]
        public void MockDirectory_LocalFS_GetDirectories_Patterns()
        {
            var fileSystem = new System.IO.Abstractions.FileSystem();

            var dirInfo = fileSystem.DirectoryInfo.FromDirectoryName(@"c:\folder1\");

            var directories = dirInfo.GetDirectories(@"folder*").ToLookup(p => p.FullName);

            //Check that it does not returns itself
            Assert.IsFalse(directories.Contains(@"c:\folder1\"));

            //Check that it correctly returns all child directories
            Assert.AreEqual(2, directories.Count());
            Assert.IsTrue(directories.Contains(@"c:\folder1\folder2"));
            Assert.IsTrue(directories.Contains(@"c:\folder1\folder4"));

            directories = dirInfo.GetDirectories(@"*").ToLookup(p => p.FullName);
            //Check that it does not returns itself
            Assert.IsFalse(directories.Contains(@"c:\folder1"));

            //Check that it correctly returns all child directories
            Assert.AreEqual(2, directories.Count());
            Assert.IsTrue(directories.Contains(@"c:\folder1\folder2"));
            Assert.IsTrue(directories.Contains(@"c:\folder1\folder4"));

            directories = dirInfo.GetDirectories(@"*.*").ToLookup(p => p.FullName);
            //Check that it does not returns itself
            Assert.IsFalse(directories.Contains(@"c:\folder1"));

            //Check that it correctly returns all child directories
            Assert.AreEqual(2, directories.Count());
            Assert.IsTrue(directories.Contains(@"c:\folder1\folder2"));
            Assert.IsTrue(directories.Contains(@"c:\folder1\folder4"));
        }

comments

idealist1508 wrote Apr 16, 2013 at 7:57 AM

I think, maybe function Alldirectories() wrong is.
Image

idealist1508 wrote Apr 16, 2013 at 8:25 AM

No, bug is not in Alldirectories.
I found a workaround for PathSeparator:
I should create Directory with a PathSeparator at the end.
            _fs = new MockFileSystem(new Dictionary<string, MockFileData>()   {
                { @"c:\storage\test\", new MockDirectoryData() }
            });
PS: Issue with Searchpattern is still open.