public async Task SecondaryObjectsController_CreateAsync_Valid() { // This test verifies that the controller returns the correct result when ISecondaryObjectService.CreateAsync returns an object var secondaryObjectsController = new SecondaryObjectsController(_secondaryObjectService.Object); var sourceSecondaryObject = new ApiModels.SecondaryObject() { Description = "Description 1", Name = "Name 1", }; _secondaryObjectService.Setup(_ => _.CreateAsync(It.IsAny <Guid>(), It.IsAny <ApiModels.SecondaryObject>())).ReturnsAsync(new DomainModels.SecondaryObject(Guid.NewGuid())); var destinationSecondaryObject = await secondaryObjectsController.CreateAsync(Guid.NewGuid(), sourceSecondaryObject); Assert.IsNotNull(destinationSecondaryObject); }
public async Task SecondaryObjectsController_CreateAsync_NotCreated() { // This test verifies that the controller throws the correct HttpResponseException when no object is returned from ISecondaryObjectService.CreateAsync var secondaryObjectsController = new SecondaryObjectsController(_secondaryObjectService.Object); ApiModels.SecondaryObject sourceSecondaryObject = null; _secondaryObjectService.Setup(_ => _.CreateAsync(It.IsAny <Guid>(), It.IsAny <ApiModels.SecondaryObject>())).ReturnsAsync(null as DomainModels.SecondaryObject); try { await secondaryObjectsController.CreateAsync(Guid.NewGuid(), sourceSecondaryObject); Assert.Fail(); } catch (HttpResponseException ex) { Assert.IsNotNull(ex.Response); Assert.AreEqual(HttpStatusCode.BadRequest, ex.Response.StatusCode); } }