Exemplo n.º 1
0
        public async void When_SendingGetWithPathContainingInvalidCharacters_Should_Return400AndValidationMessage()
        {
            using (var fs = new FsInitializer())
            {
                fs.CreateItems(new FileItem("1.txt"));
                var filepath = $"{fs.TempPath}/<1>.txt";
                var result = await _restApiClient.Get($"/api/fs/get?path={filepath}");
                var jcontent = JParser.ParseContent(result.Content);

                Assert.Equal(HttpStatusCode.BadRequest, result.Response.StatusCode);
                Assert.NotNull(jcontent["ModelState"]["Path"]);
            }
        }
Exemplo n.º 2
0
        public async void When_GettingExistingRootedFile_Should_ReturnFileContent()
        {
            using (var fs = new FsInitializer())
            {
                fs.CreateItems(
                    new DirItem("dir",
                        new FileItem("1.txt", "TEST CONTENT")));
                var filepath = Path.Combine(fs.TempPath, "dir/1.txt");
                var result = await _restApiClient.Get($"/api/fs/get?path={filepath}");

                Assert.Equal(HttpStatusCode.OK, result.Response.StatusCode);
                Assert.IsType(typeof(StreamContent), result.Response.Content);
                Assert.Equal("TEST CONTENT", result.Content);
            }
        }
Exemplo n.º 3
0
        public async void When_PostingCopyActionWithoutDestPath_Should_Return400AndValidationMessage()
        {
            using (var fs = new FsInitializer())
            {
                fs.CreateItems(
                    new DirItem("dir",
                        new FileItem("1.txt")));
                var values = new KeyValueList<string, string>
                {
                    {"action", "COPY"},
                    {"sourcePath", Path.Combine(fs.TempPath, "dir/1.txt")}
                };
                var result = await _restApiClient.Post("/api/fs", values);
                var jcontent = JParser.ParseContent(result.Content);

                Assert.Equal(HttpStatusCode.BadRequest, result.Response.StatusCode);
                Assert.NotNull(jcontent["ModelState"]["DestPath"]);
            }
        }
Exemplo n.º 4
0
        public async void When_GettingFileWithoutDownloadParameter_Should_SetMediaTypeByFileExtension()
        {
            using (var fs = new FsInitializer())
            {
                fs.CreateItems(
                    new DirItem("dir",
                        new FileItem("1.txt"),
                        new FileItem("1.xml")));
                var filepath1 = Path.Combine(fs.TempPath, "dir/1.txt");
                var filepath2 = Path.Combine(fs.TempPath, "dir/1.xml");

                var result1 = await _restApiClient.Get($"/api/fs/get?path={filepath1}");
                var result2 = await _restApiClient.Get($"/api/fs/get?path={filepath2}");

                Assert.Equal("text/plain", result1.Response.Content.Headers.ContentType.MediaType);
                Assert.Equal("text/xml", result2.Response.Content.Headers.ContentType.MediaType);
            }
        }
Exemplo n.º 5
0
 public async void When_GettingFileWithDownloadParameter_Should_SetContentDispositionAttachment()
 {
     using (var fs = new FsInitializer())
     {
         fs.CreateItems(
             new DirItem("dir",
                 new FileItem("1.txt")));
         var filepath = Path.Combine(fs.TempPath, "dir/1.txt");
         var result = await _restApiClient.Get($"/api/fs/get?path={filepath}&download=1");
         Assert.Equal("attachment", result.Response.Content.Headers.ContentDisposition.DispositionType);
     }
 }
Exemplo n.º 6
0
        public async void When_GettingFileWithDownloadParameter_Should_SetBinaryMediaType()
        {
            using (var fs = new FsInitializer())
            {
                fs.CreateItems(
                    new DirItem("dir",
                        new FileItem("1.txt"),
                        new FileItem("1.xml")));
                var filepath1 = Path.Combine(fs.TempPath, "dir/1.txt");
                var filepath2 = Path.Combine(fs.TempPath, "dir/1.xml");

                var result1 = await _restApiClient.Get($"/api/fs/get?path={filepath1}&download=1");
                var result2 = await _restApiClient.Get($"/api/fs/get?path={filepath2}&download=1");

                Assert.Equal("application/octet-stream", result1.Response.Content.Headers.ContentType.MediaType);
                Assert.Equal("application/octet-stream", result2.Response.Content.Headers.ContentType.MediaType);
            }
        }
Exemplo n.º 7
0
        public async void When_CopyingExistingFile_Should_CopyIt()
        {
            using (var fs = new FsInitializer())
            {
                fs.CreateItems(
                    new DirItem("dir",
                        new FileItem("1.txt", "Hello Test")));

                var sourcePath = Path.Combine(fs.TempPath, "dir/1.txt");
                var destPath = Path.Combine(fs.TempPath, "dir/2.txt");
                var values = new KeyValueList<string, string>
                {
                    {"action", "COPY"},
                    {"sourcePath", sourcePath},
                    {"destPath", destPath}
                };

                Assert.False(File.Exists(destPath));

                var result = await _restApiClient.Post("/api/fs", values);

                Assert.Equal(HttpStatusCode.OK, result.Response.StatusCode);
                Assert.True(File.Exists(sourcePath));
                Assert.True(File.Exists(destPath));
                Assert.Equal(File.ReadAllText(destPath), "Hello Test");
            }
        }
Exemplo n.º 8
0
        public async void When_CopyingDirectoryByUNCPath_Should_CopyEntireDirectory()
        {
            using (var fs = new FsInitializer())
            {
                fs.CreateItems(
                    new DirItem("dir",
                        new DirItem("subdir",
                            new FileItem("2.txt")),
                        new FileItem("1.txt")));

                var uncTempPath = fs.TempPath.Replace(@"C:\", @"\\localhost\C$\");
                var sourcePath = Path.Combine(uncTempPath, "dir");
                var destPath = Path.Combine(uncTempPath, "dir2");
                var values = new KeyValueList<string, string>
                {
                    {"action", "COPY"},
                    {"sourcePath", sourcePath},
                    {"destPath", destPath}
                };

                Assert.False(Directory.Exists(Path.Combine(fs.TempPath, "dir2")));

                var result = await _restApiClient.Post("/api/fs", values);

                Assert.Equal(HttpStatusCode.OK, result.Response.StatusCode);

                // verify source
                Assert.True(Directory.Exists(Path.Combine(fs.TempPath, "dir")));
                Assert.True(Directory.Exists(Path.Combine(fs.TempPath, "dir\\subdir")));
                Assert.True(File.Exists(Path.Combine(fs.TempPath, "dir\\subdir\\2.txt")));
                Assert.True(File.Exists(Path.Combine(fs.TempPath, "dir\\1.txt")));

                // verify destination
                Assert.True(Directory.Exists(Path.Combine(fs.TempPath, "dir2")));
                Assert.True(Directory.Exists(Path.Combine(fs.TempPath, "dir2\\subdir")));
                Assert.True(File.Exists(Path.Combine(fs.TempPath, "dir2\\subdir\\2.txt")));
                Assert.True(File.Exists(Path.Combine(fs.TempPath, "dir2\\1.txt")));
            }
        }
Exemplo n.º 9
0
        public async void When_CopyingAlreadyExistingDirectoryWithOverwriteSetToTrue_Should_CopyEntireDirectory()
        {
            using (var fs = new FsInitializer())
            {
                fs.CreateItems(
                    new DirItem("dir1",
                        new DirItem("subdir"),
                        new FileItem("1.txt", "source_content")),
                    new DirItem("dir2",
                        new DirItem("subdir"),
                        new DirItem("subdir2"),
                        new FileItem("1.txt", "dest_content")));

                var values = new KeyValueList<string, string>
                {
                    {"action", "COPY"},
                    {"sourcePath", Path.Combine(fs.TempPath, "dir1")},
                    {"destPath", Path.Combine(fs.TempPath, "dir2")},
                    {"overwrite", "true"}
                };

                var result = await _restApiClient.Post("/api/fs", values);

                Assert.Equal(HttpStatusCode.OK, result.Response.StatusCode);
                Assert.True(Directory.Exists(Path.Combine(fs.TempPath, "dir2")));
                Assert.True(Directory.Exists(Path.Combine(fs.TempPath, "dir2\\subdir")));
                Assert.False(Directory.Exists(Path.Combine(fs.TempPath, "dir2\\subdir2")));
                Assert.True(File.Exists(Path.Combine(fs.TempPath, "dir2\\1.txt")));
                Assert.Equal("source_content", File.ReadAllText(Path.Combine(fs.TempPath, "dir2\\1.txt")));
            }
        }
Exemplo n.º 10
0
        public async void When_CopyingAlreadyExistingDirectoryWithoutOverwrite_Should_Return500AndNotChangeDestination()
        {
            using (var fs = new FsInitializer())
            {
                fs.CreateItems(
                    new DirItem("dir1",
                        new DirItem("subdir"),
                        new FileItem("1.txt", "source_content")),
                    new DirItem("dir2",
                        new DirItem("subdir"),
                        new FileItem("1.txt", "dest_content")));

                var values = new KeyValueList<string, string>
                {
                    {"action", "COPY"},
                    {"sourcePath", Path.Combine(fs.TempPath, "dir1")},
                    {"destPath", Path.Combine(fs.TempPath, "dir2")}
                };

                var result = await _restApiClient.Post("/api/fs", values);
                var jcontent = JParser.ParseContent(result.Content);

                Assert.Equal(HttpStatusCode.InternalServerError, result.Response.StatusCode);
                Assert.Equal("System.IO.IOException", jcontent["ExceptionType"]);
                Assert.NotNull(jcontent["ExceptionMessage"]);
                Assert.True(Directory.Exists(Path.Combine(fs.TempPath, "dir2")));
                Assert.True(Directory.Exists(Path.Combine(fs.TempPath, "dir2\\subdir")));
                Assert.True(File.Exists(Path.Combine(fs.TempPath, "dir2\\1.txt")));
                Assert.Equal("dest_content", File.ReadAllText(Path.Combine(fs.TempPath, "dir2\\1.txt")));
            }
        }
Exemplo n.º 11
0
        public async void When_CopyingEmptyDirectory_Should_CopyIt()
        {
            using (var fs = new FsInitializer())
            {
                fs.CreateItems(new DirItem("dir"));
                var values = new KeyValueList<string, string>
                {
                    {"action", "COPY"},
                    {"sourcePath", Path.Combine(fs.TempPath, "dir")},
                    {"destPath", Path.Combine(fs.TempPath, "dir2")}
                };

                Assert.False(Directory.Exists(Path.Combine(fs.TempPath, "dir2")));

                var result = await _restApiClient.Post("/api/fs", values);

                Assert.Equal(HttpStatusCode.OK, result.Response.StatusCode);
                Assert.True(Directory.Exists(Path.Combine(fs.TempPath, "dir2")));
            }
        }
Exemplo n.º 12
0
        public async void When_CopyingFileToAlreadyExistingPathWithoutOverwrite_Should_Return500AndExceptionMessage()
        {
            using (var fs = new FsInitializer())
            {
                fs.CreateItems(
                    new DirItem("dir",
                        new FileItem("1.txt"),
                        new FileItem("2.txt")));

                var sourcePath = Path.Combine(fs.TempPath, "dir/1.txt");
                var destPath = Path.Combine(fs.TempPath, "dir/2.txt");
                var values = new KeyValueList<string, string>
                {
                    {"action", "COPY"},
                    {"sourcePath", sourcePath},
                    {"destPath", destPath}
                };

                var result = await _restApiClient.Post("/api/fs", values);
                var jcontent = JParser.ParseContent(result.Content);

                Assert.Equal(HttpStatusCode.InternalServerError, result.Response.StatusCode);
                Assert.True(File.Exists(destPath));
                Assert.Equal("System.IO.IOException", jcontent["ExceptionType"]);
                Assert.NotNull(jcontent["ExceptionMessage"]);
            }
        }