public async Task ShouldDeletePet() { // Arrange var userIdentifier = await Shared.CreateUser(Client); var petIdentifier = await Shared.CreatePet(Client, userIdentifier); var payload = new PetControllerRootDelete { PetIdentifier = petIdentifier }; // Prepare DELETE Request var deletePetRequest = new HttpRequestMessage(HttpMethod.Delete, "api/Pet") { Content = Shared.FormatContent <PetControllerRootDelete>(payload) }; // Act // Delete Pet var deletePetResponse = await Client.SendAsync(deletePetRequest); // Assert Assert.Equal(HttpStatusCode.OK, deletePetResponse.StatusCode); }
public void DeletePet(PetControllerRootDelete payload) { // Validate Payload DataValidator.ValidateGuid(payload.PetIdentifier); // Delete User var deletionResult = _storageService.DeletePet(payload.PetIdentifier); // Check Deletion Result if (deletionResult.ModifiedCount == 0) { throw new NoNullAllowedException("UserService (DeleteUser) - No deletions were performed."); } if (deletionResult.ModifiedCount > 1) { throw new InvalidOperationException("UserService (DeleteUser) - More than one user was deleted."); } }
public ActionResult Delete([FromBody] PetControllerRootDelete payload) { // Check if payload is present if (payload == null) { return(BadRequest("PetController (DELETE) - Missing payload.")); } try { _petService.DeletePet(payload); return(Ok()); } catch (InvalidCastException e) { // Return 422 if we can't parse the user identifier as GUID return(UnprocessableEntity(e.Message)); } catch (InvalidDataException e) { // Return 400 if the user identifier is ambiguous return(BadRequest(e.Message)); } catch (InvalidOperationException e) { // Return 409 if more than one deletion was performed return(Conflict(e.Message)); } catch (NoNullAllowedException e) { // Return 400 if no deletion was performed return(BadRequest(e.Message)); } catch (KeyNotFoundException e) { // Return 404 if we couldn't find the user we wanted to delete return(NotFound(e.Message)); } catch (Exception e) { // Return 500 if any other exception occurred return(Problem(e.Message, e.Source, 500, "UserController (DELETE)", e.GetType().ToString())); } }