public async Task <IActionResult> CreateReceiptPost(CreateReceiptModel model) { var command = new CreateReceiptCommand { DateVisited = model.ReceiptDto.DateVisited, FinancialProjectId = model.FinancialProjectId, Location = model.ReceiptDto.Location, Note = model.ReceiptDto.Note }; var receiptId = await Mediator.Send(command); foreach (var receiptItemModel in model.ReceiptDto.Items) { var createReceiptItemCommand = new CreateReceiptItemCommand { Name = "Receipt", Count = receiptItemModel.Count, ItemGroup = receiptItemModel.ItemGroup.Value, ReceiptId = receiptId, Price = receiptItemModel.Price, UserIds = receiptItemModel.Users.Select(x => x.Id).ToList() ! }; await Mediator.Send(createReceiptItemCommand); } //redirect to index return(Json(new { result = "Redirect", url = Url.Action("Index", "Project", new { id = model.FinancialProjectId }) })); }
public async Task Handle_ValidReceiptId_ShouldReturnReceiptVm() { var financialProjectId = await CreateFinancialProject(); var createCommand = new CreateReceiptCommand { FinancialProjectId = financialProjectId, Location = "Title", DateVisited = DateTime.Now, Note = "yooo a note" }; var receiptId = await SendAsync(createCommand); var receiptItemCommand = new CreateReceiptItemCommand { Name = "idk", Count = 100, Price = 1000, ItemGroup = 0, ReceiptId = receiptId, UserIds = new List <string> { User.Id, SecondUser.Id } }; var receiptItemId = await SendAsync(receiptItemCommand); var query = new GetReceiptByIdQuery { ReceiptId = receiptId }; var model = await SendAsync(query); model.Should().NotBeNull(); model.CreatedByUserId.Should().Be(User.Id); model.Location.Should().Be(createCommand.Location); model.Note.Should().Be(createCommand.Note); model.DateVisited.Should().BeCloseTo(DateTime.Now, 1000); model.CreatedByUserId.Should().Be(User.Id); model.CreatedByDto.Should().NotBeNull(); model.CreatedByDto.Id.Should().Be(User.Id); model.Deleted.Should().BeNull(); var item = model.Items.First(); item.Should().NotBeNull(); item.Id.Should().Be(receiptItemId); item.Count.Should().Be(receiptItemCommand.Count); item.Price.Should().Be(receiptItemCommand.Price); item.ItemGroup.Value.Should().Be(receiptItemCommand.ItemGroup); item.Users.Count.Should().Be(receiptItemCommand.UserIds.Count); }
public void Handle_BoughtAtEmpty_ShouldThrowValidationException() { var command = new CreateReceiptCommand { Location = "Title", FinancialProjectId = "sad" }; FluentActions.Invoking(async() => await SendAsync(command)).Should().Throw <ValidationException>(); }
protected async Task <string> CreateReceipt(string projectId) { var createCommand = new CreateReceiptCommand { FinancialProjectId = projectId, Location = "Title", DateVisited = DateTime.Now, }; return(await SendAsync(createCommand)); }
public void Handle_TitleEmpty_ShouldThrowValidationException() { var command = new CreateReceiptCommand { DateVisited = DateTime.Now, Location = "", FinancialProjectId = "asd" }; FluentActions.Invoking(async() => await SendAsync(command)).Should().Throw <ValidationException>(); }
public void Handle_TitleAboveMaxLength_ShouldThrowValidationException() { var command = new CreateReceiptCommand { DateVisited = DateTime.Now, Location = "dsfsfsdfijpsdkjfpsdkfpodskofkdsokposfkpospkofsdkpofsdkpofsdkposdfpkokfpsdkfspdopk" + "ogfddgfopkfgdkppkdgfopkogdfkpogdfkpodgfkpogdfkpogdfkpogdfkpofgdpkokpgfdopk", FinancialProjectId = "asd" }; FluentActions.Invoking(async() => await SendAsync(command)).Should().Throw <ValidationException>(); }
public async Task Handle_ValidUserId_ShouldReturnProject() { var createCommand = new CreateFinancialProjectCommand { Title = "Create", Users = new List <ApplicationUser> { User } }; var project = await SendAsync(createCommand); var createReceipt = new CreateReceiptCommand { FinancialProjectId = project.Id, Location = "Title", DateVisited = DateTime.Now }; var receiptId = await SendAsync(createReceipt); var query = new GetFinancialProjectsByUserIdQuery { UserId = User.Id }; var model = await SendAsync(query); model.Should().NotBeNull(); model.FinancialProjects.First().Users.First().Id.Should().Be(User.Id); model.FinancialProjects.First().Title.Should().Be(createCommand.Title); model.FinancialProjects.First().Receipts.First().Id.Should().Be(receiptId); model.FinancialProjects.First().Id.Should().Be(project.Id); model.FinancialProjects.First().Receipts.First().Location.Should().Be(createReceipt.Location); model.FinancialProjects.First().CreatedBy.Should().Be(User.Id); model.FinancialProjects.First().Receipts.First().DateVisited.Should().BeCloseTo(DateTime.Now, 1000); }
public async Task Handle_ValidFields_ShouldCreateEntity() { var id = await CreateFinancialProject(); var command = new CreateReceiptCommand { FinancialProjectId = id, DateVisited = DateTime.Now, Location = "Title" }; var receiptsId = await SendAsync(command); var entity = await FindAsync <Receipt>(receiptsId); entity.Should().NotBeNull(); entity.FinancialProjectId.Should().Be(command.FinancialProjectId); entity.Created.Should().BeCloseTo(DateTime.Now, 10000); entity.CreatedBy.Should().Be(User.Id); entity.Location.Should().Be(command.Location); entity.DateVisited.Should().BeCloseTo(DateTime.Now, 1000); }
public async Task Handle_ValidProjectId_ShouldReturnProject() { var createCommand = new CreateFinancialProjectCommand { Title = "test", Users = new List <ApplicationUser> { User, SecondUser } }; var project = await SendAsync(createCommand); var receiptId = await CreateReceipt(project.Id); var createReceipt = new CreateReceiptCommand { FinancialProjectId = project.Id, Location = "Title", DateVisited = DateTime.Today.AddDays(-5), }; await SendAsync(createReceipt); var receiptItemCommand = new CreateReceiptItemCommand { Count = 5, Price = 2, Name = "test", ItemGroup = (int)ItemGroup.Essentials, ReceiptId = receiptId, UserIds = new List <string> { SecondUser.Id } }; var receiptItemId = await SendAsync(receiptItemCommand); var query = new GetFinancialProjectByIdQuery { ProjectId = project.Id }; var model = await SendAsync(query); model.Should().NotBeNull(); model.Receipts.First().Id.Should().Be(receiptId); model.Receipts.Count.Should().Be(2); model.Receipts.First().Location.Should().Be("Title"); model.Receipts.First().DateVisited.Should().BeCloseTo(DateTime.Now, 10000); model.Receipts.First().Items.First().Id.Should().Be(receiptItemId); model.Receipts.First().Items.First().Users.FirstOrDefault(x => x.Id == SecondUser.Id).Should().NotBeNull(); model.Receipts.First().Items.First().ItemGroup.Value.Should().Be(receiptItemCommand.ItemGroup); model.Users.FirstOrDefault(x => x.Id == SecondUser.Id).Owed.Should().Be(-10); model.Id.Should().Be(project.Id); model.Created.Should().BeCloseTo(DateTime.Now, 1000); model.Users.FirstOrDefault(x => x.Id == User.Id).Should().NotBeNull(); model.Title.Should().Be(project.Title); model.LastModified.Should().Be(null); }