public void Update_ShouldFailWithNull_WhenWrongValues() { // Arrange int id = _rnd.Next(1, _attachedDocs.Count()); var newAttachedDocRequest = new AttachedDocUpdateRequest { Designation = "NewUpdate", }; // Act & Assert Assert.Throws <ArgumentNullException>(() => _service.Update(id, null)); Assert.Throws <ArgumentNullException>(() => _service.Update(999, newAttachedDocRequest)); _repository.Verify(mock => mock.Update(It.IsAny <AttachedDoc>()), Times.Never); }
public void Update_ShouldFailWithConflict_WhenConflictValues() { // Arrange var conflictDesignation = _attachedDocs[0].Designation; var id = _attachedDocs[3].Id; var newAttachedDocRequest = new AttachedDocUpdateRequest { Designation = conflictDesignation, Name = "NewUpdate", }; // Act & Assert Assert.Throws <ConflictException>(() => _service.Update(id, newAttachedDocRequest)); _repository.Verify(mock => mock.Update(It.IsAny <AttachedDoc>()), Times.Never); }
public async Task Update_ShouldReturnUnauthorized_WhenNoAccessToken() { // Arrange int id = 1; var attachedDocRequest = new AttachedDocUpdateRequest { Name = "NewUpdate", }; string json = JsonSerializer.Serialize(attachedDocRequest); var httpContent = new StringContent(json, Encoding.UTF8, "application/json"); var endpoint = $"/api/attached-docs/{id}"; // Act var response = await _authHttpClient.PatchAsync(endpoint, httpContent); // Assert Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); }
public void Update( int id, AttachedDocUpdateRequest attachedDoc) { if (attachedDoc == null) { throw new ArgumentNullException(nameof(attachedDoc)); } var foundAttachedDoc = _repository.GetById(id); if (foundAttachedDoc == null) { throw new ArgumentNullException(nameof(foundAttachedDoc)); } if (attachedDoc.Designation != null) { var uniqueConstraintViolationCheck = _repository.GetByUniqueKey( foundAttachedDoc.Mark.Id, attachedDoc.Designation); if (uniqueConstraintViolationCheck != null && uniqueConstraintViolationCheck.Id != id) { throw new ConflictException(uniqueConstraintViolationCheck.Id.ToString()); } foundAttachedDoc.Designation = attachedDoc.Designation; } if (attachedDoc.Name != null) { foundAttachedDoc.Name = attachedDoc.Name; } if (attachedDoc.Note != null) { foundAttachedDoc.Note = attachedDoc.Note; } _repository.Update(foundAttachedDoc); var foundMark = _markRepo.GetById(foundAttachedDoc.Mark.Id); foundMark.EditedDate = DateTime.Now; _markRepo.Update(foundMark); }
public ActionResult Update( int id, [FromBody] AttachedDocUpdateRequest attachedDocRequest) { if (!attachedDocRequest.Validate()) { return(BadRequest()); } try { _service.Update(id, attachedDocRequest); } catch (ArgumentNullException) { return(NotFound()); } catch (ConflictException) { return(Conflict()); } return(NoContent()); }
public void Update_ShouldUpdateAttachedDoc() { // Arrange int id = _rnd.Next(1, _attachedDocs.Count()); var newStringValue = "NewUpdate"; var newAttachedDocRequest = new AttachedDocUpdateRequest { Designation = newStringValue, Name = newStringValue, Note = newStringValue, }; // Act _service.Update(id, newAttachedDocRequest); // Assert _repository.Verify(mock => mock.Update(It.IsAny <AttachedDoc>()), Times.Once); var v = _attachedDocs.SingleOrDefault(v => v.Id == id); Assert.Equal(newStringValue, v.Designation); Assert.Equal(newStringValue, v.Name); Assert.Equal(newStringValue, v.Note); }