public async Task ShouldUpdatePhone() { var userId = await RunAsDefaultUserAsync(); var contactId = await SendAsync(new CreateContactCommand { Title = "Dr", FirstName = "Bat", LastName = "Man", }); var itemId = await SendAsync(new CreatePhoneCommand { ContactId = contactId, PhoneNumber = "New phone" }); var command = new UpdatePhoneCommand { Id = itemId, PhoneNumber = "Updated phone number" }; await SendAsync(command); var item = await FindAsync <Phone>(itemId); item.PhoneNumber.Should().Be(command.PhoneNumber); item.LastModifiedBy.Should().NotBeNull(); item.LastModified.Should().NotBeNull(); item.LastModified.Should().BeCloseTo(DateTime.Now, 1000); }
public void ShouldRequireValidPhone() { var command = new UpdatePhoneCommand { Id = 99, PhoneNumber = "New phone" }; FluentActions.Invoking(() => SendAsync(command)).Should().Throw <NotFoundException>(); }
public async Task <ActionResult> Update(int id, UpdatePhoneCommand command) { if (id != command.Id) { return(BadRequest()); } await Mediator.Send(command); return(NoContent()); }
public async Task <IActionResult> UpdatePhoneAsync( [FromBody] UpdatePhoneRequest model, CancellationToken token) { var command = new UpdatePhoneCommand(model.UserId, model.NewPhone); try { await _commandBus.DispatchAsync(command, token); } catch (DuplicateRowException) { return(Conflict()); } catch (NotFoundException) { return(NotFound()); } return(Ok()); }
public async Task <IActionResult> Phone([FromBody] UpdatePhoneCommand command, [FromRoute] int Id) { await _commandBus.ExecuteAsync(command); return(Ok()); }