public async Task AddFileTest() { // Arrange var createDocumentCommand = new CreateDocumentCommand(DateTime.UtcNow.Ticks.ToString(), "Test document"); var addFileCommand = new AddFileCommand("Test", "Test file"); // Act var documentUri = await _client.CreateDocumentAsync(createDocumentCommand); var fileUri = await _client.AddFileAsync(documentUri, addFileCommand); var file = await _client.GetAsync <File>(fileUri); var files = await _client.GetFiles(documentUri); // Assert Assert.NotNull(file); Assert.Equal(addFileCommand.FileName, file.Name); Assert.Equal(addFileCommand.FileDescription, file.Description); Assert.NotNull(files); Assert.Single(files); Assert.Equal(file.Id, files.First().Id); }
public void File_add_throws_when_owner_now_found() { // Arrange FakeFileStorage fileStorage = new FakeFileStorage(); FakeFileRepository fileRepository = new FakeFileRepository(); FakeEventPublisher eventPublisher = new FakeEventPublisher(); FakeCurrentUserSource currentUserSource = new FakeCurrentUserSource(); FakePostCommitRegistrar postCommitRegistrar = new FakePostCommitRegistrar(); currentUserSource.CurrentUser = null; var commandHandler = new AddFileCommandHandler( fileRepository, fileStorage, eventPublisher, postCommitRegistrar, currentUserSource); var contentBuffer = Encoding.UTF8.GetBytes("testContent"); using (Stream fileContent = new MemoryStream(contentBuffer)) { var command = new AddFileCommand("filename", "desc", "text/plain", fileContent); // Assert & Act Assert.Throws <NotFoundException>(() => { commandHandler.Handle(command); postCommitRegistrar.ExecuteActions(); }); } }
public async Task <IActionResult> AddFile([FromForm] IFormFile file) { await using var content = new MemoryStream(); file.CopyTo(content); var command = new AddFileCommand(file.FileName, content, Username); await Mediator.Send(command); return(CreatedAtRoute(nameof(GetFile), new { id = command.FileId }, null)); }
public async Task <IActionResult> AddFile(Guid documentId, [FromBody] AddFileCommand command) { var outcome = from doc in GetDocumentFromEvents(documentId) from u in ValidateDocumentUser(doc.UserId.Value) from result in doc.AddFile(Guid.NewGuid(), command.FileName, command.FileDescription).AsTask() from _ in SaveAndPublishEventAsync(result.Event) select result.Event; return(await outcome.Map(val => val.ToActionResult(evt => Created($"documents/{documentId}/files/{evt.FileId}", null)))); }
public static Task <int> Main(string[] args) { MSBuildLocator.RegisterDefaults(); var parser = new CommandLineBuilder() .AddCommand(AddFileCommand.Create()) .AddCommand(AddUrlCommand.Create()) .AddCommand(RefreshCommand.Create()) .AddCommand(RemoveCommand.Create()) .UseDefaults() .Build(); return(parser.InvokeAsync(args)); }
public void AddFileToDfsResponse_No_Response_Codes() { //Arrange var addFileToDfsResponse = new AddFileToDfsResponse(); var commandContext = TestCommandHelpers.GenerateCliResponseCommandContext(_testScheduler); var addFileToDfsCommand = new AddFileCommand(null, commandContext, _logger); //Act TestCommandHelpers.GenerateResponse(commandContext, addFileToDfsResponse); _testScheduler.Start(); //Assert commandContext.UserOutput.Received(1).WriteLine(AddFileCommand.ErrorNoResponseCodes); }
public async Task <IActionResult> Add([FromBody] AddFileRequest content) { var command = new AddFileCommand(content); try { await _commandProcessor.SendAsync(command); } catch (Exception exception) { return(StatusCode(StatusCodes.Status500InternalServerError, $"Failed to add the content: {exception.Message}.")); } return(Ok()); }
internal static Parser BuildParser(HttpClient client) { var root = new RootCommand(); root.AddCommand(AddFileCommand.Create(client)); root.AddCommand(AddUrlCommand.Create(client)); root.AddCommand(RefreshCommand.Create(client)); root.AddCommand(RemoveCommand.Create(client)); root.AddCommand(ListCommand.Create(client)); var parser = new CommandLineBuilder(root) .UseDefaults() .Build(); return(parser); }
private void m_addFileToolStripMenuItem_Click(object sender, EventArgs e) { Vault.Currency.Entities.Folder parent = m_model.Parent as Vault.Currency.Entities.Folder; if (parent != null) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Multiselect = true; if (openFileDialog.ShowDialog() == DialogResult.OK) { string[] filePaths = openFileDialog.FileNames; foreach (string filePath in filePaths) { AddFileCommand.Execute(filePath, parent, m_conn); } m_model.Reload(); } } }
public async Task TestAddFileReadEventsErrorBadRequestResult() { //Arrange const string error = "testError"; var documentId = Guid.NewGuid(); var command = new AddFileCommand("test", "description"); _documentFilesController = new DocumentFilesController(TestHelper.ReadEventsFuncWithError(error), TestHelper.SaveAndPublish, GetFile, GetFiles, TestHelper.GetCurrentUserId(), TestHelper.GetDocumentById()); //Act var result = await _documentFilesController.AddFile(documentId, command); //Assert var badRequestResult = result as BadRequestObjectResult; Assert.NotNull(badRequestResult); Assert.NotNull(badRequestResult.Value); }
public async Task SendDocumentForApprovalTest() { // Arrange var createDocumentCommand = new CreateDocumentCommand(DateTime.UtcNow.Ticks.ToString(), "Test document"); var addFileCommand = new AddFileCommand("Test", "Test file"); // Act var documentUri = await _client.CreateDocumentAsync(createDocumentCommand); await _client.AddFileAsync(documentUri, addFileCommand); await _client.SendDocumentForApprovalAsync(documentUri); var document = await _client.GetAsync <Document>(documentUri); // Assert Assert.NotNull(document); Assert.Equal(DocumentStatus.WaitingForApproval.ToString(), document.Status); }
public void File_add_adds_file_and_publishes_event() { // Arrange FakeFileStorage fileStorage = new FakeFileStorage(); FakeFileRepository fileRepository = new FakeFileRepository(); FakeEventPublisher eventPublisher = new FakeEventPublisher(); FakeCurrentUserSource currentUserSource = new FakeCurrentUserSource(); FakePostCommitRegistrar postCommitRegistrar = new FakePostCommitRegistrar(); currentUserSource.CurrentUser = new User("userId", "username"); var commandHandler = new AddFileCommandHandler( fileRepository, fileStorage, eventPublisher, postCommitRegistrar, currentUserSource); var contentBuffer = Encoding.UTF8.GetBytes("testContent"); using (Stream fileContent = new MemoryStream(contentBuffer)) { var command = new AddFileCommand("filename", "desc", "text/plain", fileContent); // Act commandHandler.Handle(command); postCommitRegistrar.ExecuteActions(); // Assert File addedFile = fileRepository.GetByName("filename"); Assert.IsNotNull(addedFile); Assert.AreEqual("filename", addedFile.FileName); Assert.AreEqual("desc", addedFile.Description); Assert.AreEqual("userId", addedFile.Owner.Id); Stream fileStream = fileStorage.ReadFile(addedFile).Result; Assert.IsNotNull(fileStream); using (var reader = new StreamReader(fileStream)) Assert.AreEqual("testContent", reader.ReadToEnd()); File publishedEvent = eventPublisher.VerifyPublishedOnce <File>(); Assert.AreEqual(addedFile, publishedEvent); } }
public void AddFileToDfsResponse_Finished_Can_Get_Output() { //Arrange var addFileToDfsResponse = new AddFileToDfsResponse { ResponseCode = ByteString.CopyFrom((byte)FileTransferResponseCodeTypes.Finished.Id) }; var commandContext = TestCommandHelpers.GenerateCliResponseCommandContext(_testScheduler); var addFileToDfsCommand = new AddFileCommand(null, commandContext, _logger); //Act TestCommandHelpers.GenerateResponse(commandContext, addFileToDfsResponse); _testScheduler.Start(); //Assert commandContext.UserOutput.Received(1).WriteLine("File transfer completed, Response: " + FileTransferResponseCodeTypes.Finished.Name + " Dfs Hash: " + addFileToDfsResponse.DfsHash); }
public async Task TestAddFileInvalidCommandBadRequestResult() { //Arrange var documentId = Guid.NewGuid(); var command = new AddFileCommand(string.Empty, "test"); var documentCreatedDto = new DocumentCreatedEventDto(Guid.Empty, DateTime.UtcNow, Guid.Empty, "1234", string.Empty); var readEventsFunc = TestHelper.ValidReadEventsFunc(documentCreatedDto.ToEvent()); _documentFilesController = new DocumentFilesController(readEventsFunc, TestHelper.SaveAndPublish, GetFile, GetFiles, TestHelper.GetCurrentUserId(), TestHelper.GetDocumentById()); //Act var result = await _documentFilesController.AddFile(documentId, command); //Assert var badRequestResult = result as BadRequestObjectResult; Assert.NotNull(badRequestResult); Assert.NotNull(badRequestResult.Value); }
public void AddFileCommand_AddsPackagesAndReferences() { // Arrange var currentDir = Directory.GetCurrentDirectory(); var tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); new DirectoryInfo(Path.Combine(currentDir, "TestAssets", "EmptyProject")).CopyTo(tempDir); // Act Directory.SetCurrentDirectory(tempDir); var command = new AddFileCommand(new TestConsole(), null); command.AddFile(Services.Server, Access.Internal, "ImportDir", new[] { Path.Combine("Proto", "*.proto") }); command.Project.ReevaluateIfNecessary(); // Assert var packageRefs = command.Project.GetItems(CommandBase.PackageReferenceElement); Assert.AreEqual(1, packageRefs.Count); Assert.NotNull(packageRefs.SingleOrDefault(r => r.UnevaluatedInclude == "Grpc.AspNetCore" && !r.HasMetadata(CommandBase.PrivateAssetsElement))); var protoRefs = command.Project.GetItems(CommandBase.ProtobufElement); Assert.AreEqual(2, protoRefs.Count); Assert.NotNull(protoRefs.SingleOrDefault(r => r.UnevaluatedInclude == Path.Combine("Proto", "a.proto"))); Assert.NotNull(protoRefs.SingleOrDefault(r => r.UnevaluatedInclude == Path.Combine("Proto", "b.proto"))); foreach (var protoRef in protoRefs) { Assert.AreEqual("Server", protoRef.GetMetadataValue(CommandBase.GrpcServicesElement)); Assert.AreEqual("ImportDir", protoRef.GetMetadataValue(CommandBase.AdditionalImportDirsElement)); Assert.AreEqual("Internal", protoRef.GetMetadataValue(CommandBase.AccessElement)); } // Cleanup Directory.SetCurrentDirectory(currentDir); Directory.Delete(tempDir, true); }
public void Upload(AddFileCommand command) { AssertConcern.AssertArgumentNotEmpty(command.FileName, "Nome do arquivo não pode ser nulo"); var fileAlreadyExist = FileRepository.GetFilesByQuery(command.FileName); var file = new File(command.FileName, command.ContentType) { Size = command.File.Length, CreatedAt = DateTime.UtcNow, CreateBy = command.CreateUser, UpdatedAt = DateTime.UtcNow, UpdateBy = command.CreateUser, ReferenceId = command.ReferenceId.Value }; file.GenerateNewId(); FileRepository.Save(file, command.CreateUser); AzureContainer.AddFile($"{file.Id}_{file.Name}", command.File); Uow.Commit(); }
public async Task <IActionResult> Post([FromForm] AddFileCommand command) { return(await HandleAsync(command)); }
public static async Task <Uri> AddFileAsync(this HttpClient httpClient, Uri documentUri, AddFileCommand command) { var content = GetStringContent(command); var requestUri = CombineUri(documentUri, "files"); var response = await httpClient.PostAsync(requestUri, content); response.EnsureSuccessStatusCode(); Assert.NotNull(response.Headers.Location); return(response.Headers.Location); }
protected override string BuildPackage() { var commands = new List <ICommand>(); foreach (var item in Items) { var syncItem = ItemSynchronization.BuildSyncItem(item); var contentDataItem = new ContentDataItem(string.Empty, item.Paths.ParentPath, item.Name, syncItem); var command = new AddItemCommand(contentDataItem); commands.Add(command); } var rootPath = FileUtil.MapPath("/"); foreach (var fileName in Files) { if (FileUtil.IsFolder(fileName)) { foreach (var file in Directory.GetFiles(FileUtil.MapPath(fileName), "*", SearchOption.AllDirectories)) { var fileInfo = new FileInfo(file); if ((fileInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) { continue; } if ((fileInfo.Attributes & FileAttributes.System) == FileAttributes.System) { continue; } var fileItem = new FileSystemDataItem(rootPath, Path.GetDirectoryName(file), Path.GetFileName(file)); var command = new AddFileCommand(fileItem); commands.Add(command); } } else { var fileItem = new FileSystemDataItem(rootPath, Path.GetDirectoryName(fileName), Path.GetFileName(fileName)); var command = new AddFileCommand(fileItem); commands.Add(command); } } var diff = new DiffInfo(commands) { Author = Author, PostStep = PostStep, Publisher = Publisher, Readme = Readme, Version = Version, Title = PackageName }; var directoryName = Path.GetDirectoryName(FileName) ?? string.Empty; directoryName = directoryName.Replace("\\", "/"); var folderPath = FileUtil.MapPath(directoryName); diff.Serialize(folderPath); var packageFileName = FileUtil.UnmapPath(folderPath, false) + "/" + DiffInfo.OutputFileName; PackageGenerator.GeneratePackage(diff, packageFileName); return(packageFileName); }