Ejemplo n.º 1
0
        public void DirectoryPathCanBeParsed()
        {
            var path = "a/b/c";
            var root = new MemoryDirectory("root", null);
            var dir = root.CreateDirectory(path);

            Assert.Equal("c", dir.Name);
            Assert.Equal("b", dir.Parent.Name);
            Assert.Equal("a", dir.Parent.Parent.Name);
            Assert.Equal(root, dir.Parent.Parent.Parent);
        }
Ejemplo n.º 2
0
        // TODO: convert this class to extension methods for IDirectory
        /// <summary>
        /// This method is used to convert legacy code to IDirectory source.
        /// </summary>
        /// <returns></returns>
        public IDirectory ToDirectory()
        {
            var root = new MemoryDirectory("root", null);
            var bin = root.CreateDirectory("bin");

            // generated all text based files. they are mostly configuration files.                
            if (TextFiles != null)
            {
                foreach (var textFileName in TextFiles.Keys)
                {
                    root.CreateFileFromText(textFileName, TextFiles[textFileName]);
                }
            }

            var currentAssemblyLocation = Assembly.GetExecutingAssembly().Location;
            if (!BinaryFiles.Contains(currentAssemblyLocation))
            {
                BinaryFiles.Add(currentAssemblyLocation);
            }

            // copy all required binary files
            if (BinaryFiles != null)
            {
                foreach (var file in BinaryFiles)
                {
                    var fileInfo = new FileInfo(file);
                    if (fileInfo.Exists)
                    {
                        bin.CreateFileFromDisk(fileInfo.Name, fileInfo);
                    }
                }
            }

            return root;
        }
Ejemplo n.º 3
0
        public void DirectoryCanBeCopiedToDisk()
        {
            string expected = "test";
            string expectedFileName = "test.html";
            var root = new MemoryDirectory("root", null);
            root.CreateFileFromText(expectedFileName, expected);
            var dir = root.CreateDirectory(expected);
            dir.CreateFileFromText(expectedFileName, expected);

            var diskDir = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "root"));
            root.CopyToDisk(diskDir);

            Assert.True(Directory.Exists(Path.Combine(diskDir.FullName, expected)));
            Assert.True(File.Exists(Path.Combine(diskDir.FullName, expectedFileName)));
            Assert.True(File.Exists(Path.Combine(diskDir.FullName, expected, expectedFileName)));

            string content;
            using (var reader = new StreamReader(Path.Combine(diskDir.FullName, expectedFileName)))
            {
                content = reader.ReadToEnd();
            }
            Assert.Equal(expected, content);

            using (var reader = new StreamReader(Path.Combine(diskDir.FullName, expected, expectedFileName)))
            {
                content = reader.ReadToEnd();
            }
            Assert.Equal(expected, content);
            diskDir.Delete(true);
        }
Ejemplo n.º 4
0
        public async Task UploadMemoryDirectoryRecursivelyShouldWork()
        {
            var dir = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);
            var subDir = dir.CreateSubdirectory("test");
            using (var writer = File.CreateText(Path.Combine(subDir.FullName, "test.html")))
            {
                writer.Write("Test");
            }
            var subSubDir = subDir.CreateSubdirectory("test");
            using (var writer = File.CreateText(Path.Combine(subSubDir.FullName, "test.html")))
            {
                writer.Write("Test");
            }

            var directory = new MemoryDirectory("root", null);
            directory.CopyFromDisk(subDir);
            directory.CreateDirectory("memory").CreateFileFromText("memory.txt", "memory");

            var ftp = CreateFtp();
            var path = "site/wwwroot/";
            var folderName = "test/";
            ftp.ChangeDirectory(path);
            await ftp.MakeDirectoryAsync(folderName);
            Assert.True(await ftp.DirectoryExistsAsync(folderName));
            await ftp.UploadDirectoryRecursivelyAsync(folderName, directory);
            Assert.True(await ftp.FileExistsAsync("test/test/test.html"));
            Assert.True(await ftp.FileExistsAsync("test/memory/memory.txt"));
            await ftp.RemoveDirectoryRecursivelyAsync(folderName);
            Assert.False(await ftp.DirectoryExistsAsync(folderName));

            subDir.Delete(true);
        }