예제 #1
0
        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);
        }
예제 #2
0
        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));
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }