public ActionResult Post([FromBody] AddressCreateDto addressDto) { if (!ModelState.IsValid) { return(BadRequest()); } var addressEntity = _mapper.Map <Address>(addressDto); _addressRepository.Create(addressEntity); if (!_personRepository.Save()) { return(StatusCode(500, "An error occured while making the change")); } return(CreatedAtAction("Post", new { id = addressEntity.ID }, addressEntity)); }
public async Task Should_Be_Able_To_Create_An_Address() { var addressCreateDto = new AddressCreateDto { AddressLine = "95/2T, Testing road, Xunit, Sri Lanka", CityID = 1, CustomerID = 1, Geolocation = "6.789456:79.456123", Note = "The road to the left of the grocery store at the Xunit junction" }; var addressDto = await AddressAppService.CreateAsync(addressCreateDto); addressDto.Id.ShouldBeGreaterThan(0); addressDto.AddressLine.ShouldBe(addressCreateDto.AddressLine); addressDto.CityID.ShouldBe(1); addressDto.CustomerID.ShouldBe(1); addressDto.Geolocation.ShouldBe(addressCreateDto.Geolocation); addressDto.Note.ShouldBe(addressCreateDto.Note); }
public async void TestCreateContact() { var _provider = InitializeDatabaseProvider(); _provider.AddState(new State() { Name = "TestingState", StateId = 1 }); _provider.AddCity(new City() { Name = "TestingCity", StateId = 1, CityId = 1 }); await _provider.Save(); var address = new AddressCreateDto() { StreetInformation = "TestStreet", CityId = 1, StateId = 1, }; var contact = new ContactCreateRequestDto() { Name = "TestEntity", Company = "TestCompany", Email = "TestingEmail", BirthDate = DateTime.Now, Address = address, PersonalPhoneNumber = "1111" }; var _configuration = new Mock <IConfiguration>(); var controller = new ContactsController(_configuration.Object, _provider, InitializeMapper()); var result = await controller.CreateContact(contact); var actionResult = Assert.IsType <CreatedAtActionResult>(result); Assert.IsType <ContactSingleResponseDto>(actionResult.Value); Assert.Equal(201, actionResult.StatusCode); }
public async Task Add_Address_ReturnZero() { DbContextOptions <AddressContext> options = new DbContextOptionsBuilder <AddressContext>().UseInMemoryDatabase("Add_Address_Database").Options; var addressContext = new AddressContext(options); var createAddress = new AddressCreateDto { City = "昆明", County = "五华区", Province = "云南省" }; var stubAddressRepository = new Mock <IRepository <Domain.Address> >(); var stubProvinceRepository = new Mock <IRepository <Province> >(); var addressUnitOfWork = new AddressUnitOfWork <AddressContext>(addressContext); var stubAddressService = new AddressServiceImpl.AddressServiceImpl(stubAddressRepository.Object, stubProvinceRepository.Object, addressUnitOfWork); await stubAddressService.CreateAddressAsync(createAddress); int addressAmountActual = await addressContext.Addresses.CountAsync(); Assert.Equal(1, addressAmountActual); }
public async Task Add(AddressCreateDto createDto) { await _addressService.CreateAddressAsync(createDto); }
public async Task <AddressDto> CreateAddress([FromBody] AddressCreateDto dto) { return(await CustomerAppService.CreateAddressDto(dto)); }
public void Post(AddressCreateDto createDto) { _addressService.Create(createDto); }