예제 #1
0
        public async Task PostNewSpeciesReturnsBadRequestAndCorrectContentType()
        {
            // Given
            CreateSpeciesViewModel model = ViewModelFactory.CreateInvalidCreationModel();

            // When
            HttpResponseMessage response = await Client.PostAsJsonAsync(EndPointFactory.CreateEndpoint(), model);

            // Then
            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
            response.Content.Headers.ContentType.ToString().Should().Be("application/problem+json; charset=utf-8");
        }
예제 #2
0
        public async Task <ActionResult> Post([FromBody] CreateSpeciesViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                CreateSpeciesModel createSpeciesModel = _mapper.Map <CreateSpeciesModel>(model);
                Guid speciesId = await _commands.Create(createSpeciesModel);

                return(CreatedAtRoute(nameof(GetSpecies), new { id = speciesId }, null));
            }
            catch (Exception ex) when(ex is ResourceStateException)
            {
                return(Conflict(new ErrorViewModel(ex)));
            }
        }