public async Task <ActionResult> Add(AddPhoneModel model) { var(phone, customerUuid) = model.GetPhone(); var result = await _phoneService.SaveAsync(phone, customerUuid); if (result is not SuccessResult <Guid> successResult) { return(FailResult(result)); } if (await _unitOfWork.SaveChangesAsync()) { return(CreatedAtAction(nameof(Get), new { uuid = successResult.Result }, null)); } return(ErrorResult()); }
public async Task AddShouldAddNewPhone() { using var scope = ServiceProvider.CreateScope(); var sut = Factory.CreateClient(); var context = scope.ServiceProvider.GetRequiredService <ApplicationContext>(); var customer = await SeedDatabaseFixture.AddDummyCustomerAsync(context); var request = new AddPhoneModel { Number = "7894-5698", AreaCode = "78", CustomerUuid = customer.Uuid }; var serializedRequest = JsonSerializer.Serialize(request); var contentRequest = new StringContent(serializedRequest, Encoding.UTF8, "application/json"); var result = await sut.PostAsync("Phone/Add", contentRequest); result.EnsureSuccessStatusCode(); var savedPhone = await context.Phones.Include(x => x.Customer).FirstAsync(); Assert.Equal(request.Number, savedPhone.Number); Assert.Equal(request.AreaCode, savedPhone.AreaCode); Assert.Equal(request.CustomerUuid, savedPhone.Customer.Uuid); }