public async void Post_InvalidModelState_ThrowsError() { _controller.ModelState.AddModelError("mock", "error"); var site = new SaveSiteResource(); Func <Task> act = async() => await _controller.Post(site); await Assert.ThrowsAsync <HttpException>(act); }
public async Task <IActionResult> Post([FromBody] SaveSiteResource resource) { if (!ModelState.IsValid) { throw new HttpException(HttpStatusCode.BadRequest, ModelState.GetErrors()); } var site = _mapper.Map <SaveSiteResource, Site>(resource); await _siteService.CreateSiteAsync(site); return(CreatedAtAction("Get", new { site.Id }, site)); }
public async void Post_PersistsMappedSite_WithSiteService() { var site = new SaveSiteResource(); var mockMappedSite = new Site(); _mockMapper.Setup(m => m.Map <SaveSiteResource, Site>(site)).Returns(mockMappedSite); await _controller.Post(site); _mockSiteService.Verify(m => m.CreateSiteAsync(mockMappedSite), Times.Once); }
public async void Post_MapsSiteResource_ToSite() { var site = new SaveSiteResource(); var mockMappedSite = new Site(); _mockMapper.Setup(m => m.Map <SaveSiteResource, Site>(site)).Returns(mockMappedSite); await _controller.Post(site); _mockMapper.Verify(m => m.Map <SaveSiteResource, Site>(site), Times.Once); }