public async Task PrimaryObjectsController_CreateAsync_Valid() { // This test verifies that the controller returns the correct result when IPrimaryObjectService.CreateAsync returns an object var primaryObjectsController = new PrimaryObjectsController(_primaryObjectService.Object); var sourcePrimaryObject = new ApiModels.PrimaryObject() { Description = "Description 1", Name = "Name 1", }; _primaryObjectService.Setup(_ => _.CreateAsync(It.IsAny <ApiModels.PrimaryObject>())).ReturnsAsync(new DomainModels.PrimaryObject(Guid.NewGuid())); var destinationPrimaryObject = await primaryObjectsController.CreateAsync(sourcePrimaryObject); Assert.IsNotNull(destinationPrimaryObject); }
public async Task PrimaryObjectsController_CreateAsync_NotCreated() { // This test verifies that the controller throws the correct HttpResponseException when no object is returned from IPrimaryObjectService.CreateAsync var primaryObjectsController = new PrimaryObjectsController(_primaryObjectService.Object); ApiModels.PrimaryObject sourcePrimaryObject = null; _primaryObjectService.Setup(_ => _.CreateAsync(It.IsAny <ApiModels.PrimaryObject>())).ReturnsAsync(null as DomainModels.PrimaryObject); try { await primaryObjectsController.CreateAsync(sourcePrimaryObject); Assert.Fail(); } catch (HttpResponseException ex) { Assert.IsNotNull(ex.Response); Assert.AreEqual(HttpStatusCode.BadRequest, ex.Response.StatusCode); } }