public async Task SaveFileAsync(ResourceForSavingModel model) { CreateDirectoryIfDoNotExists(model); string fileFullPath = model.FilePath; using (FileStream fsStream = new FileStream(fileFullPath, FileMode.Create)) { await fsStream.WriteAsync(model.ResourceContent, 0, model.ResourceContent.Length); } }
public void can_not_save_file_if_filename_is_wrong() { string fileName = "test??really??"; var model = new ResourceForSavingModel() { FileName = fileName, FolderPath = _rootFolder, ResourceContent = new byte[0] }; TestDelegate testDelegate = () => _fileSaver.SaveFileAsync(model).Wait(); Assert.That(testDelegate, Throws.TypeOf<AggregateException>()); }
public void can_save_test_file() { Guid guid = Guid.NewGuid(); string fileName = "test" + guid; var model = new ResourceForSavingModel() { FileName = fileName, FolderPath = _rootFolder, ResourceContent = new byte[0] }; Task saveTask = _fileSaver.SaveFileAsync(model); saveTask.Wait(); Assert.IsTrue(File.Exists(model.FilePath)); }
private void CreateDirectoryIfDoNotExists(ResourceForSavingModel model) { string fullFolderPath = model.FolderPath; if (!Directory.Exists(fullFolderPath)) Directory.CreateDirectory(fullFolderPath); }