public void DiskDirectoryCanBeCopied()
        {
            string expected = "test";
            var dir = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);
            var subDir = dir.CreateSubdirectory(expected);
            using (var writer = File.CreateText(Path.Combine(subDir.FullName, "test.html")))
            {
                writer.Write(expected);
            }
            var subSubDir = subDir.CreateSubdirectory(expected);
            using (var writer = File.CreateText(Path.Combine(subSubDir.FullName, "test.html")))
            {
                writer.Write(expected);
            }

            var root = new MemoryDirectory("root", null);
            root.CopyFromDisk(subDir);

            Assert.True(root.DirectoryExists(expected));

            var file = root.FindFile("test.html");
            Assert.Equal(expected, file.ReadAsString());

            file = root.FindDirectory(expected).FindFile("test.html");
            Assert.Equal(expected, file.ReadAsString());

            subDir.Delete(true);
        }
        private IDirectory GetDiskSourceDirectory(WebHostContext context)
        {
            var descriptor = context.Deployment;
            if (string.IsNullOrEmpty(descriptor.ScopePath))
            {
                throw new InvalidOperationException("Path can't be null or empty for directory deployment");
            }

            var solutionRootPath = GetSolutionDir();
            if (string.IsNullOrEmpty(solutionRootPath))
            {
                throw new InvalidOperationException(
                    string.Format(
                        "Configuration Setting:{0} can't be null or empty for directory deployment",
                        SolutionDirAppSettingName));
            }

            var sourceDirInfo = new DirectoryInfo(Path.Combine(solutionRootPath, descriptor.ScopePath));
            if (!sourceDirInfo.Exists)
            {
                throw new InvalidOperationException(
                    string.Format(
                        "Web app path:'{0}' doesn't exist",
                        sourceDirInfo.FullName));
            }

            var directory = new MemoryDirectory("root", null);
            directory.CopyFromDisk(sourceDirInfo);

            return directory;
        }
Exemple #3
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);
        }