public async Task ReturnNoErrorsForValidModel() { // arrange var model = _validModel; // act var result = await _target.ValidateAsync(model); // assert Assert.True(result.IsValid); Assert.Empty(result.Errors); }
public async Task <ActionResult <ContactResource> > Put(int id, ContactResource resource) { if (id != resource.Id) { return(BadRequest()); } var validator = new ContactValidator(); var validationResult = await validator.ValidateAsync(resource); if (!validationResult.IsValid) { return(BadRequest(validationResult.Errors)); } var emailValidator = new EditContactEmailValidator(_contactsService, resource.Id); var emailValidationResult = await emailValidator.ValidateAsync(resource); if (!emailValidationResult.IsValid) { return(BadRequest(emailValidationResult.Errors)); } var entityToUpdate = _mapper.Map <ContactResource, Contact>(resource); await _contactsService.Update(entityToUpdate); return(NoContent()); }
public async Task <ActionResult <ContactResource> > Post(ContactResource resource) { var validator = new ContactValidator(); var validationResult = await validator.ValidateAsync(resource); if (!validationResult.IsValid) { return(BadRequest(validationResult.Errors)); } var emailValidator = new NewContactEmailValidator(_contactsService); var emailValidationResult = await emailValidator.ValidateAsync(resource); if (!emailValidationResult.IsValid) { return(BadRequest(emailValidationResult.Errors)); } var entityToCreate = _mapper.Map <ContactResource, Contact>(resource); var createdEntity = await _contactsService.Create(entityToCreate); var createdResource = _mapper.Map <Contact, ContactResource>(createdEntity); return(CreatedAtAction("POST", createdResource)); }