Ejemplo n.º 1
0
        public override IEnumerable <DirectoryItemInfo> ItemsInDirectory(string path)
        {
            MockDirectory directory = this.RootDirectory.FindDirectory(path);

            directory.ShouldNotBeNull();

            foreach (MockDirectory subDirectory in directory.Directories.Values)
            {
                yield return(new DirectoryItemInfo()
                {
                    Name = subDirectory.Name,
                    FullName = subDirectory.FullName,
                    IsDirectory = true
                });
            }

            foreach (MockFile file in directory.Files.Values)
            {
                yield return(new DirectoryItemInfo()
                {
                    FullName = file.FullName,
                    Name = file.Name,
                    IsDirectory = false,
                    Length = file.FileProperties.Length
                });
            }
        }
Ejemplo n.º 2
0
        public override void DeleteDirectory(string path, bool recursive = false)
        {
            MockDirectory directory = this.RootDirectory.FindDirectory(path);

            directory.ShouldNotBeNull();

            this.RootDirectory.DeleteDirectory(path);
        }
Ejemplo n.º 3
0
        public override IEnumerable <string> EnumerateDirectories(string path)
        {
            MockDirectory directory = this.RootDirectory.FindDirectory(path);

            directory.ShouldNotBeNull();

            if (directory != null)
            {
                foreach (MockDirectory subDirectory in directory.Directories.Values)
                {
                    yield return(subDirectory.Name);
                }
            }
        }
Ejemplo n.º 4
0
        public override string[] GetFiles(string directoryPath, string mask)
        {
            if (!mask.Equals("*"))
            {
                throw new NotImplementedException();
            }

            MockDirectory directory = this.RootDirectory.FindDirectory(directoryPath);

            directory.ShouldNotBeNull();

            List <string> files = new List <string>();

            foreach (MockFile file in directory.Files.Values)
            {
                files.Add(file.FullName);
            }

            return(files.ToArray());
        }
Ejemplo n.º 5
0
        public void MoveDirectory(string sourcePath, string targetPath)
        {
            MockDirectory sourceDirectory;
            MockDirectory sourceDirectoryParent;

            this.TryGetDirectoryAndParent(sourcePath, out sourceDirectory, out sourceDirectoryParent).ShouldEqual(true);

            int    endPathIndex        = targetPath.LastIndexOf(Path.DirectorySeparatorChar);
            string targetDirectoryPath = targetPath.Substring(0, endPathIndex);

            MockDirectory targetDirectory = this.FindDirectory(targetDirectoryPath);

            targetDirectory.ShouldNotBeNull();

            sourceDirectoryParent.RemoveDirectory(sourceDirectory);

            sourceDirectory.FullName = targetPath;

            targetDirectory.AddDirectory(sourceDirectory);
        }
Ejemplo n.º 6
0
        public MockFile CreateFile(string path, string contents, bool createDirectories = false)
        {
            string        parentPath      = path.Substring(0, path.LastIndexOf(Path.DirectorySeparatorChar));
            MockDirectory parentDirectory = this.FindDirectory(parentPath);

            if (createDirectories)
            {
                if (parentDirectory == null)
                {
                    parentDirectory = this.CreateDirectory(parentPath);
                }
            }
            else
            {
                parentDirectory.ShouldNotBeNull();
            }

            MockFile newFile = new MockFile(path, contents);

            parentDirectory.Files.Add(newFile.FullName, newFile);

            return(newFile);
        }