Exemplo n.º 1
0
 public IHttpActionResult WriteFile(WriteFileDataContract writeFileDC)
 {
     try
     {
         _fileService.SaveFile(writeFileDC.Filename, writeFileDC.FileContent);
         return(Ok());
     }
     catch (Exception ex) { throw ex; }
 }
Exemplo n.º 2
0
        protected void Give_A_Content_Write_To_File()
        {
            //throw new NotImplementedException();
            //Arrange
            Mock <IFileService> MockfileSvc = new Mock <IFileService>();
            bool returnFlag = true;

            MockfileSvc.Setup(x => x.SaveFile(It.IsAny <string>(), It.IsAny <string>())).Returns(returnFlag);
            WriteFileDataContract fileDataContract = new WriteFileDataContract {
                Filename = "test.txt", FileContent = "hello world"
            };
            FileController fileController = new FileController(MockfileSvc.Object);
            //Act
            var Result = fileController.WriteFile(fileDataContract);
            //Assert
            //Assert.AreEqual(Result, returnFlag);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates or updates a given file resource in the file system.
        /// </summary>
        /// <param name="virtualFilePath">The qualified path of the file to be created.</param>
        /// <param name="input">A stream that provides the file's contents.</param>
        /// <param name="overwrite">Whether an existing file should be overwritten
        /// or not. If this parameter is false and the file already exists, a
        /// <see cref="ResourceOverwriteException"/> is thrown.</param>
        /// <param name="resourceLength">The length of the resource to be uploaded in bytes.</param>
        /// <param name="contentType">The content type of the uploaded resource.</param>
        /// <exception cref="ResourceAccessException">In case of invalid or prohibited
        /// resource access.</exception>
        /// <exception cref="ResourceOverwriteException">If a file already exists at the
        /// specified location, and the <paramref name="overwrite"/> flag was not set.</exception>
        /// <exception cref="ArgumentNullException">If any of the parameters is a null reference.</exception>
        public override VirtualFileInfo WriteFile(string virtualFilePath, Stream input, bool overwrite, long resourceLength,
                                                  string contentType)
        {
            var fileContract = SecureFunc(FileSystemTask.StreamedFileUploadRequest,
                                          () =>
            {
                WriteFileDataContract contract = new WriteFileDataContract
                {
                    Data           = input,
                    Overwrite      = overwrite,
                    FilePath       = virtualFilePath,
                    ResourceLength = resourceLength,
                    ContentType    = contentType
                };
                return(WriterService.WriteFile(contract));
            },
                                          () =>
                                          String.Format("Could not write data for file [{0}] to file system.", virtualFilePath));

            return(fileContract.FileInfo);
        }