public async Task ReturnHttpStatus201WhenPostingACorrectPayload() { var client = _webApplicationFactory.CreateClient(); var dto = new AccountPostV1 { OwnerId = new Guid("11111111-0000-0000-0000-000000000001") }; var response = await client.PostAsync("/accounts", dto, new JsonMediaTypeFormatter()).ConfigureAwait(false); response.StatusCode.Should().Be(HttpStatusCode.Created); }
public async Task ReturnHttpStatus422WhenPostingAnIncorrectOwner() { var client = _webApplicationFactory.CreateClient(); var incorrectOwnerId = new Guid("99999999-9999-9999-9999-999999999999"); var dto = new AccountPostV1 { OwnerId = incorrectOwnerId }; var response = await client.PostAsync("/accounts", dto, new JsonMediaTypeFormatter()).ConfigureAwait(false); response.StatusCode.Should().Be(HttpStatusCode.UnprocessableEntity); }
public async Task <ActionResult <AccountGetV1> > AddAccount([FromBody] AccountPostV1 accountPost) { if (accountPost == null) { return(BadRequest()); } var account = await _mediator.Send(new AddAccountCommand(accountPost)).ConfigureAwait(false); if (account.IsSuccess) { return(CreatedAtAction(GetAccountActionName, new { id = account.Value.Id }, account.Value)); } var modelState = new ModelStateDictionary(); modelState.AddModelError("Failure", account.Error); return(UnprocessableEntity(modelState)); }
public AddAccountCommand(AccountPostV1 accountPostModel) { AccountPostModel = EnsureArg.IsNotNull(accountPostModel, nameof(accountPostModel)); }