public async Task <IActionResult> Text(Guid ticketId, string textId, [FromForm] DelTicketTextFile.Command command) { return(HandleResult(await Mediator.Send(new DelTicketTextFile.Command { Id = textId, TicketId = ticketId }))); }
public async Task ShouldCreateTicketWithTextFiles() { var user = await MockRegisterUser("*****@*****.**", "Pa$$w0rd"); var file1 = await Utils.GetTestFile("C:\\Users\\bigboss\\Desktop\\tickets.txt"); file1.Position = 0; var file2 = await Utils.GetTestFile("C:\\Users\\bigboss\\Desktop\\backbutton.txt"); file2.Position = 0; TestContext.Out.WriteLine($"File response: {file1}, {file2}"); var fileName1 = "tickets.txt"; var fileName2 = "backbutton.txt"; FormFile[] form = new FormFile[] { new FormFile(file1, 0, file1.Length, "File", fileName1) { Headers = new HeaderDictionary(), ContentType = "text/plain" }, new FormFile(file2, 0, file2.Length, "File", fileName2) { Headers = new HeaderDictionary(), ContentType = "text/plain" }, }; var testId = Guid.NewGuid(); Guid groupId = await SetUpUserGroup(); var command = new Create.Command { Title = "Testing multiple Text Files", Id = testId, Description = "Can you add a text files as part of the formdata", BugType = "Localization", Device = "Iphone 2", Priority = "Priority", Date = DateTime.Now, GroupId = groupId, Status = "Open", Version = "1337", File = form }; var userDB = await FindAsync <AppUser>(GetCurrentUserId()); command.File.Should().NotBeNull(); var response = await SendAsync(command); var list = await LoadRelatedTexts(testId); var files = list.SelectMany(p => p.Texts); response.Value.Should().Equals(Unit.Value); response.IsSuccess.Should().Equals(true); list.Should().NotBeNull(); foreach (var item in list) { item.Title.Should().Be(command.Title); item.GroupId.Should().Be(groupId); item.Date.Should().BeCloseTo(DateTime.Now, 10000); item.Creator.Should().Equals(userDB.UserName); } files.Should().NotBeEmpty(); files.Count().Should().Be(2); int index = 0; var fileIds = new string[2]; foreach (var item in files) { fileIds[index] = item.Id; item.Name.Should().Equals(form[index].FileName); item.Url.Should().NotBeNullOrEmpty(); index++; } // Remove files from API. for (var i = 0; i < fileIds.Length; i++) { var delFileCommand = new DelTicketTextFile.Command { TicketId = testId, Id = fileIds[i] }; var resp = await SendAsync(delFileCommand); resp.IsSuccess.Should().BeTrue(); } }