public async Task PrimaryObjectsController_GetAsync_Found() { // This test verifies that the controller does not throw an error when get returns an object var primaryObjectsController = new PrimaryObjectsController(_primaryObjectService.Object); var sourcePrimaryObject = new DomainModels.PrimaryObject(Guid.NewGuid()) { Description = "Description 1", Name = "Name 1", SecondaryObjects = new List <DomainModels.SecondaryObject>() { new DomainModels.SecondaryObject(Guid.NewGuid()) { Description = "Description 1.1", Name = "Name 1.1", }, new DomainModels.SecondaryObject(Guid.NewGuid()) { Description = "Description 1.2", Name = "Name 1.2", }, }, }; foreach (var sourceSecondaryObject in sourcePrimaryObject.SecondaryObjects) { sourceSecondaryObject.PrimaryObject = sourcePrimaryObject; sourceSecondaryObject.PrimaryObject_Id = sourcePrimaryObject.Id; } _primaryObjectService.Setup(_ => _.GetAsync(sourcePrimaryObject.Id)).ReturnsAsync(sourcePrimaryObject); var destinationPrimaryObject = await primaryObjectsController.GetAsync(sourcePrimaryObject.Id); Assert.IsNotNull(destinationPrimaryObject); Assert.AreEqual(sourcePrimaryObject.Description, destinationPrimaryObject.Description); Assert.AreEqual(sourcePrimaryObject.Id, destinationPrimaryObject.Id); Assert.AreEqual(sourcePrimaryObject.Name, destinationPrimaryObject.Name); Assert.IsNotNull(destinationPrimaryObject.SecondaryObjects); Assert.AreEqual(sourcePrimaryObject.SecondaryObjects.Count, destinationPrimaryObject.SecondaryObjects.Count()); foreach (var destinationSecondaryObject in destinationPrimaryObject.SecondaryObjects) { var sourceSecondaryObject = sourcePrimaryObject.SecondaryObjects.SingleOrDefault(_ => _.Id == destinationSecondaryObject.Id); Assert.IsNotNull(sourceSecondaryObject); Assert.IsNull(destinationSecondaryObject.Description); Assert.AreEqual(sourceSecondaryObject.Id, destinationSecondaryObject.Id); Assert.IsNull(destinationSecondaryObject.Name); Assert.IsNull(destinationSecondaryObject.PrimaryObject); } }
public async Task PrimaryObjectsController_GetAsync_NotFound() { // This test verifies that the controller throws the correct HttpResponseException when get does not return an object var primaryObjectsController = new PrimaryObjectsController(_primaryObjectService.Object); DomainModels.PrimaryObject sourcePrimaryObject = null; _primaryObjectService.Setup(_ => _.GetAsync(It.IsAny <Guid>())).ReturnsAsync(sourcePrimaryObject); try { await primaryObjectsController.GetAsync(Guid.NewGuid()); Assert.Fail(); } catch (HttpResponseException ex) { Assert.IsNotNull(ex.Response); Assert.AreEqual(HttpStatusCode.NotFound, ex.Response.StatusCode); } }