public async Task <IActionResult> Put(int id, UpdatePaymentCommand req) { req.Data.Attributes.id = id; var result = await _mediatr.Send(req); return(Ok(result)); }
protected override async Task SavePaymentAsync() { var updateRecurring = false; if (SelectedPayment.IsRecurring) { updateRecurring = await dialogService.ShowConfirmMessageAsync(Strings.ModifyRecurrenceTitle, Strings.ModifyRecurrenceMessage, Strings.YesLabel, Strings.NoLabel); } var command = new UpdatePaymentCommand(SelectedPayment.Id, SelectedPayment.Date, SelectedPayment.Amount, SelectedPayment.IsCleared, SelectedPayment.Type, SelectedPayment.Note, SelectedPayment.IsRecurring, SelectedPayment.Category != null ? SelectedPayment.Category.Id : 0, SelectedPayment.ChargedAccount != null ? SelectedPayment.ChargedAccount.Id : 0, SelectedPayment.TargetAccount != null ? SelectedPayment.TargetAccount.Id : 0, updateRecurring, SelectedPayment.RecurringPayment?.Recurrence, SelectedPayment.RecurringPayment?.IsEndless, SelectedPayment.RecurringPayment?.EndDate); await mediator.Send(command); }
public async Task ShouldUpdatePersistedPayment() { var userId = await RunAsDefaultUserAsync(); var paymentId = await SendAsync(new CreatePaymentCommand { Name = "Do yet another thing for update." }); var command = new UpdatePaymentCommand { Id = paymentId, Name = "This thing is also done.", IsComplete = true }; await SendAsync(command); var payment = await FindAsync <Payment>(command.Id); payment.Should().NotBeNull(); payment.Name.Should().Be(command.Name); payment.IsComplete.Should().BeTrue(); payment.LastModifiedBy.Should().NotBeNull(); payment.LastModifiedBy.Should().Be(userId); payment.LastModified.Should().NotBeNull(); payment.LastModified.Should().BeCloseTo(DateTime.Now, 1000); }
public async Task <ActionResult> Update(long id, UpdatePaymentCommand command) { if (id != command.Id) { return(BadRequest()); } await Mediator.Send(command); return(NoContent()); }
public void Handle_GivenInvalidId_ThrowsException() { var command = new UpdatePaymentCommand { Id = 99, Name = "This item doesn't exist.", IsComplete = false }; var sut = new UpdatePaymentCommandHandler(_repository); Assert.ThrowsAsync <NotFoundException>(() => sut.Handle(command, CancellationToken.None)); }
public async Task ShouldRequireValidPaymentId() { var userId = await RunAsDefaultUserAsync(); var command = new UpdatePaymentCommand { Id = 99, Name = "This item doesn't exist.", IsComplete = false }; FluentActions.Invoking(() => SendAsync(command)).Should().Throw <NotFoundException>(); }
public async Task <IActionResult> Put(int id, UpdatePaymentCommand req) { try { req.data.attributes.id = id; var result = await _mediatr.Send(req); return(Ok(result)); } catch (Exception) { return(NotFound()); } }
public async Task GivenValidUpdatePaymentCommand_ReturnsBadRequest() { var client = await _factory.GetAuthenticatedClientAsync(); var validId = await new Create(_factory).GivenValidCreatePaymentCommand_ReturnsSuccessCode(); var command = new UpdatePaymentCommand { Id = Convert.ToInt64(validId), Name = "Do this thing.", IsComplete = true }; var content = IntegrationTestHelper.GetRequestContent(command); var response = await client.PutAsync($"{_paymentBaseUri}/{command.Id}", content); response.StatusCode.Should().Be(HttpStatusCode.BadRequest); }
public async Task Handle_GivenValidId_ShouldUpdatePersistedPayment() { var command = new UpdatePaymentCommand { Id = 1, Name = "This thing is also done.", IsComplete = true }; var sut = new UpdatePaymentCommandHandler(_repository); await sut.Handle(command, CancellationToken.None); var entity = await _repository.GetByIdAsync(command.Id).ConfigureAwait(false); entity.Should().NotBeNull(); entity.Name.Should().Be(command.Name); entity.IsComplete.Should().BeTrue(); }
public async Task ShouldRequireUniqueTitle() { var paymentId = await SendAsync(new CreatePaymentCommand { Name = "New List" }); await SendAsync(new CreatePaymentCommand { Name = "This thing is also done" }); var command = new UpdatePaymentCommand { Id = paymentId, Name = "This thing is also done" }; FluentActions.Invoking(() => SendAsync(command)) .Should().Throw <ValidationException>().Where(ex => ex.Errors.ContainsKey("Name")) .And.Errors["Name"].Should().Contain("The specified name is already exists."); }
public async Task <IActionResult> UpdatePayment(int id, UpdatePaymentCommand data) { data.DataD.Attributes.Id = id; return(Ok(await _mediatr.Send(data))); }