public void TestGetCompanionPostById() { var contextMock = new Mock <HttpContext>(); contextMock.Setup(x => x.User).Returns(new ClaimsPrincipal(claims)); _mockCompanionPostService.Setup(x => x.GetById(It.IsAny <string>(), It.IsAny <string>())).Returns(companionPost); var _companionController = new CompanionController(_mockCompanionPostService.Object, _mockPostService.Object); _companionController.ControllerContext.HttpContext = contextMock.Object; var resultActual = _companionController.GetCompanionPostById("5d0b2b0b1c9d440000d8e9a1"); var type = resultActual.GetType(); Assert.AreEqual(type.Name, "OkObjectResult"); }