public async Task SecondaryObjectsController_GetAllAsync_Found() { // This test verifies that the controller does not throw an error when getting all objects var secondaryObjectsController = new SecondaryObjectsController(_secondaryObjectService.Object); var source = new List <DomainModels.SecondaryObject>() { 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", }, }, new DomainModels.SecondaryObject(Guid.NewGuid()) { Description = "Description 2.1", Name = "Name 2.1", PrimaryObject = new DomainModels.PrimaryObject(Guid.NewGuid()) { Description = "Description 2", Name = "Name 2", }, }, }; foreach (var sourceSecondaryObject in source) { sourceSecondaryObject.PrimaryObject_Id = sourceSecondaryObject.PrimaryObject.Id; sourceSecondaryObject.PrimaryObject.SecondaryObjects = new List <DomainModels.SecondaryObject>() { sourceSecondaryObject }; } _secondaryObjectService.Setup(_ => _.GetAllAsync()).ReturnsAsync(source); var destination = await secondaryObjectsController.GetAllAsync(); Assert.IsNotNull(destination); foreach (var destinationSecondaryObject in destination) { var sourceSecondaryObject = source.SingleOrDefault(_ => _.Id == destinationSecondaryObject.Id); Assert.IsNotNull(source); 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_GetAllAsync_NotFound() { // This test verifies that the controller does not throw an error when getting all objects and null is returned from the service var secondaryObjectsController = new SecondaryObjectsController(_secondaryObjectService.Object); ICollection <DomainModels.SecondaryObject> source = null; _secondaryObjectService.Setup(_ => _.GetAllAsync()).ReturnsAsync(source); try { await secondaryObjectsController.GetAllAsync(); Assert.Fail(); } catch (HttpResponseException ex) { Assert.IsNotNull(ex.Response); Assert.AreEqual(HttpStatusCode.NotFound, ex.Response.StatusCode); } }