public async void UpdateAddressAsync_Updates_One_Address_And_Returns_200_And_Address_Updated() { //declare a Contact Address address = _addresses.FirstOrDefault(); AddressDTO expectedDto = _mapper.Map <AddressDTO>(address); //set repo return for getting the object to update _mockRepository.Setup(repo => repo.GetOneByAsync(ad => ad.Id == address.Id)).ReturnsAsync(address); //set mockRepo return for Update action _mockRepository.Setup(repo => repo.UpdateTAsync(address)).ReturnsAsync(1); //instantiate the controller, passing the repo object var controller = new AddressesController(_mockRepository.Object, _mapper, _logger); //Call the SUT method //returns ActionResult<BillableActivity> type var actionResult = await controller.UpdateAddressAsync(address.Id, address); //Get the int result from the posted ActionResult var okObjectResult = actionResult.Result as OkObjectResult; var statusCode = okObjectResult.StatusCode; AddressDTO dto = okObjectResult.Value as AddressDTO; //Assert the result Assert.NotNull(actionResult); //Validate StatusCode Assert.Equal(200, statusCode); //Validate the actual BillableActivity dto.Should().BeEquivalentTo(expectedDto, options => options.ComparingByMembers <AddressDTO>()); }
public async void AddAddressAsync_Creates_One_Address_And_Returns_201_And_Address_Created() { //declare address Address address = _addresses.First(); AddressDTO expectedDTO = _mapper.Map <AddressDTO>(address); //set mockRepo return for Add action _mockRepository.Setup(repo => repo.AddTAsync(address)).ReturnsAsync(1); //set repo return for getting the newly created object _mockRepository.Setup(repo => repo.GetOneByAsync(ad => ad.Client_Id == address.Client_Id && ad.StreetNumber == address.StreetNumber && ad.City == address.City)).ReturnsAsync(address); //instantiate the controller, passing the repo object var controller = new AddressesController(_mockRepository.Object, _mapper, _logger); //Call the SUT method var actionResult = await controller.AddAddressAsync(address); //Get the int result from the posted ActionResult var createdResult = actionResult.Result as CreatedResult; var statusCode = createdResult.StatusCode; AddressDTO actualDto = createdResult.Value as AddressDTO; //Assert the result Assert.NotNull(actionResult); //Validate returned status code Assert.Equal(201, statusCode); //Validate the result actualDto.Should().BeEquivalentTo(expectedDTO, options => options.ComparingByMembers <AddressDTO>()); }