public async Task TestCreate() { var contact = new Contact() { Firstname = "John", Lastname = "Dennis" }; var resultingContact = new Contact() { Firstname = contact.Firstname, Lastname = contact.Lastname, Id = ContactIdTest }; contactService.Setup(entity => entity.CreateAsync(contact)).Returns(Task.FromResult(resultingContact)); httpContextAccessor.Setup(acc => acc.HttpContext.User.Identity.Name).Returns(UserIdStr); var contactController = new ContactController(contactService.Object, contactValidation, logger.Object, httpContextAccessor.Object); var result = await contactController.CreateAsync(contact); Assert.IsTrue(result is OkObjectResult); Assert.IsTrue(((Contact)((OkObjectResult)result).Value).Id == ContactIdTest); }