public async Task GetAllStandards_ReturnsAppropriateResponse() { var mediatorMock = new Mock <IMediator>(); var getAllStandardsResponse = new GetStandardsLookupResponse { Standards = new List <GetStandardResponse> { new GetStandardResponse { LarsCode = 235 } } }; var apiResponse = new ApiResponse <GetStandardsLookupResponse>(getAllStandardsResponse, HttpStatusCode.OK, ""); mediatorMock.Setup(m => m.Send(It.IsAny <GetStandardsLookupQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(apiResponse); var subject = new GetStandardsLookupController(Mock.Of <ILogger <GetStandardsLookupController> >(), mediatorMock.Object); var response = await subject.GetAllStandards(); var statusCodeResult = response as IStatusCodeActionResult; var okResult = response as OkObjectResult; var actualResponse = okResult.Value; Assert.AreSame(getAllStandardsResponse, actualResponse); Assert.AreEqual((int)HttpStatusCode.OK, statusCodeResult.StatusCode.GetValueOrDefault()); }
public async Task GetAllStandards_NonOkResponse_ReturnsErrorResponse(HttpStatusCode statusCode) { var errorMessage = "Error in retrieval"; var mediatorMock = new Mock <IMediator>(); var getAllStandardsResponse = new GetStandardsLookupResponse { Standards = null }; var apiResponse = new ApiResponse <GetStandardsLookupResponse>(getAllStandardsResponse, statusCode, errorMessage); mediatorMock.Setup(m => m.Send(It.IsAny <GetStandardsLookupQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(apiResponse); var subject = new GetStandardsLookupController(Mock.Of <ILogger <GetStandardsLookupController> >(), mediatorMock.Object); var response = await subject.GetAllStandards(); var statusCodeResult = response as IStatusCodeActionResult; Assert.AreEqual((int)statusCode, statusCodeResult.StatusCode.GetValueOrDefault()); Assert.AreEqual(errorMessage, ((ObjectResult)statusCodeResult).Value); }