public async void Create_NewUserAddress_WithAdminRole_ReturnCreatedResponse() { //Arrange await AuthenticateAsync(UserRoleEnum.Admin); var newAddress = new NewAddressRequest { UserId = 1, Name = "Endreço da praia", Description = "Av. Orla Verde, 103", City = "Fernando de Noronha", State = "PE", Country = "Brasil", Type = AddressTypeEnum.Other, ZipCode = "53990-000" }; //Act var response = await TestClient.PostAsJsonAsync(ApiRoutes.Address.Register, newAddress); //Assert response.StatusCode.Should().Be(HttpStatusCode.Created); var returnAdress = await response.Content.ReadFromJsonAsync <NewAddressResponse>(); returnAdress.Id.Should().BeGreaterThan(0); returnAdress.UserId.Should().Be(newAddress.UserId); returnAdress.Name.Should().Be(newAddress.Name); returnAdress.Description.Should().Be(newAddress.Description); returnAdress.City.Should().Be(newAddress.City); returnAdress.State.Should().Be(newAddress.State); returnAdress.Country.Should().Be(newAddress.Country); returnAdress.ZipCode.Should().Be(newAddress.ZipCode); }
public NewAddressResponse RegisterAddress(NewAddressRequest newAddressRequest) { var newAddress = new Address { UserId = newAddressRequest.UserId, Name = newAddressRequest.Name, Type = newAddressRequest.Type, Description = newAddressRequest.Description, City = newAddressRequest.City, State = newAddressRequest.State, Country = newAddressRequest.Country, ZipCode = newAddressRequest.ZipCode }; var addedAddress = _AddressRepository.Add(newAddress); _AddressRepository.SaveChanges(); return(new NewAddressResponse { Id = addedAddress.Id, UserId = addedAddress.UserId, Name = addedAddress.Name, Type = addedAddress.Type, Description = addedAddress.Description, City = addedAddress.City, State = addedAddress.State, Country = addedAddress.Country, ZipCode = addedAddress.ZipCode }); }
public async Task <ActionResult <NewAddressResponse> > Register([FromBody] NewAddressRequest newAddressRequest) { var response = _addressService.RegisterAddress(newAddressRequest); if (response == null) { return(BadRequest(response)); } return(Created(ApiRoutes.Address.BaseRoute + "/" + response.Id, response)); }
public async void Create_NewUserAddress_WithPartnerRole_ReturnForbiden() { //Arrange await AuthenticateAsync(UserRoleEnum.Partner); var newAddress = new NewAddressRequest { UserId = 1, Name = "Endreço da praia", Description = "Av. Orla Verde, 103", City = "Fernando de Noronha", State = "PE", Country = "Brasil", Type = AddressTypeEnum.Other, ZipCode = "53990-000" }; //Act var response = await TestClient.PostAsJsonAsync(ApiRoutes.Address.Register, newAddress); //Assert response.StatusCode.Should().Be(HttpStatusCode.Forbidden); }