public async Task SecondaryObjectsController_UpdateAsync_Found() { // This test verifies that the controller does not throw an error when updating a valid object var secondaryObjectsController = new SecondaryObjectsController(_secondaryObjectService.Object); var sourceSecondaryObject = new DomainModels.SecondaryObject(Guid.NewGuid()) { Description = "Description 1.1", Name = "Name 1.1", PrimaryObject = new DomainModels.PrimaryObject(Guid.NewGuid()) { Description = "Description 1", Name = "Name 1", }, }; sourceSecondaryObject.PrimaryObject_Id = sourceSecondaryObject.PrimaryObject.Id; sourceSecondaryObject.PrimaryObject.SecondaryObjects = new List <DomainModels.SecondaryObject>() { sourceSecondaryObject }; _secondaryObjectService.Setup(_ => _.UpdateAsync(sourceSecondaryObject.Id, It.IsAny <ApiModels.SecondaryObject>())).ReturnsAsync(sourceSecondaryObject); var destinationSecondaryObject = await secondaryObjectsController.UpdateAsync(sourceSecondaryObject.Id, new ApiModels.SecondaryObject()); Assert.IsNotNull(destinationSecondaryObject); Assert.AreEqual(sourceSecondaryObject.Description, destinationSecondaryObject.Description); Assert.AreEqual(sourceSecondaryObject.Id, destinationSecondaryObject.Id); Assert.AreEqual(sourceSecondaryObject.Name, destinationSecondaryObject.Name); Assert.IsNotNull(destinationSecondaryObject.PrimaryObject); Assert.IsNull(destinationSecondaryObject.PrimaryObject.Description); Assert.AreEqual(sourceSecondaryObject.PrimaryObject.Id, destinationSecondaryObject.PrimaryObject.Id); Assert.IsNull(destinationSecondaryObject.PrimaryObject.Name); Assert.IsNull(destinationSecondaryObject.PrimaryObject.SecondaryObjects); }
public async Task SecondaryObjectsController_UpdateAsync_NotFound() { // This test verifies that the controller throws the correct HttpResponseException when a non-existant object is updated var secondaryObjectsController = new SecondaryObjectsController(_secondaryObjectService.Object); DomainModels.SecondaryObject sourceSecondaryObject = null; _secondaryObjectService.Setup(_ => _.UpdateAsync(It.IsAny <Guid>(), It.IsAny <ApiModels.SecondaryObject>())).ReturnsAsync(sourceSecondaryObject); try { await secondaryObjectsController.UpdateAsync(Guid.NewGuid(), new ApiModels.SecondaryObject()); Assert.Fail(); } catch (HttpResponseException ex) { Assert.IsNotNull(ex.Response); Assert.AreEqual(HttpStatusCode.NotFound, ex.Response.StatusCode); } }