public void CreatePerson() { PersonWithoutIdentifiersViewModel model = new PersonWithoutIdentifiersViewModel { FirstName = "firstname", LastName = "lastname" }; var controller = new PersonsController(_context); var result = (ObjectResult)controller.CreatePerson(model); Assert.IsType <ApiResponse <bool> >(result.Value); var response = (ApiResponse <bool>)result.Value; Assert.Equal(((int)HttpStatusCode.OK).ToString(), response.StatusCode.ToString()); }
/// <summary> /// Create Person Without Identifiers /// </summary> /// <param name="context"></param> /// <param name="model"></param> public ApiResponse <bool> CreatePersonWithoutIdentifiers(TestProjectDbContext context, PersonWithoutIdentifiersViewModel model) { try { Person person = new Person { Id = Guid.NewGuid(), FirstName = model.FirstName, LastName = model.LastName, Deleted = false }; _repository.CreatePerson(context, person); return(ApiResponse <bool> .SuccessResult(true)); } catch (Exception ex) when(ex is FailException || ex is ValidationException || ex is ArgumentException) { return(ApiResponse <bool> .ErrorResult(message : ex.Message, statusCode : HttpStatusCode.BadRequest)); } catch (Exception ex) when(ex is ErrorException) { //LoggingManager.Error(ex.ToString()); return(ApiResponse <bool> .ErrorResult(message : ex.Message)); } catch (Exception ex) { //LoggingManager.Error(ex.ToString()); return(ApiResponse <bool> .ErrorResult(message : ex.Message)); } }
public IActionResult CreatePerson([FromBody] PersonWithoutIdentifiersViewModel model) { var response = _personFacades.CreatePersonWithoutIdentifiers(_context, model); return(new ObjectResult(response)); }