public void UpdateFileContent_EmptyFileExists(string vPath)
        {
            Assert.NotNull(controller);

            var          currentFolder   = SetupFoldersHierarchy(vPath);
            const string filename        = "some-file.txt";
            var          expectedContent = new String('0', 1024 * 1024);
            var          targetPath      = FilePath.Combine(vPath, filename);
            var          fsEntry         = new FileSystemInfoDto()
            {
                Name    = filename,
                Path    = targetPath,
                Content = expectedContent
            };

            currentFolder.CreateFile(filename);
            Assert.That(currentFolder.FileExists(filename));

            var task = controller.UpdateFileContent(targetPath, fsEntry);

            task.Wait();
            Assert.IsAssignableFrom <NoContentResult>(task.Result);
            var typedResult = task.Result;

            Assert.That(currentFolder.FileExists(filename));
            Assert.That(expectedContent, Is.EqualTo(currentFolder.ReadFile(filename)));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> UpdateFileContent([FromRoute] string targetPath, [FromBody] FileSystemInfoDto fsEntry)
        {
            ValidateRequired(targetPath, nameof(targetPath));
            if (!ModelState.IsValid)
            {
                return(new BadRequestObjectResult(ModelState));
            }

            targetPath = NormalizeTargetPath(targetPath);
            ValidateTargetPath(targetPath);
            ValidateRequired(fsEntry, nameof(fsEntry));
            if (!ModelState.IsValid)
            {
                return(new BadRequestObjectResult(ModelState));
            }

            var filePath = _pathMap.ToLocalPath(targetPath);

            if (!System.IO.File.Exists(filePath))
            {
                return(new NotFoundResult());
            }

            //Handle only content update now;
            using (StreamWriter writer = new StreamWriter(System.IO.File.OpenWrite(filePath)))
                await writer.WriteAsync(fsEntry.Content);

            return(new NoContentResult());
        }