public async Task HasAllTemplateCalculationsBeenApproved_GivenResponseIsSuccess_ReturnsValue(bool expectedValue) { //Arrange BooleanResponseModel booleanResponseModel = new BooleanResponseModel { Value = expectedValue }; ApiResponse <BooleanResponseModel> apiResponse = new ApiResponse <BooleanResponseModel>(HttpStatusCode.OK, booleanResponseModel); ICalculationsApiClient calculationsApiClient = CreateCalculationsApiClient(); calculationsApiClient .CheckHasAllApprovedTemplateCalculationsForSpecificationId(Arg.Is(specificationId)) .Returns(apiResponse); CalculationsService calculationsService = CreateCalculationsService(calculationsApiClient); //Act bool responseValue = await calculationsService.HaveAllTemplateCalculationsBeenApproved(specificationId); //Assert responseValue .Should() .Be(expectedValue); }
public void HasAllTemplateCalculationsBeenApproved_GivenFailedResponseCheckingForApprovedTemplateCalcs_ThrowsRetriableException() { //Arrange ApiResponse <BooleanResponseModel> apiResponse = new ApiResponse <BooleanResponseModel>(HttpStatusCode.NotFound); ICalculationsApiClient calculationsApiClient = CreateCalculationsApiClient(); calculationsApiClient .CheckHasAllApprovedTemplateCalculationsForSpecificationId(Arg.Is(specificationId)) .Returns(apiResponse); ILogger logger = CreateLogger(); string errorMessage = $"Failed to check spoecification with id '{specificationId}' " + $"for all approved template calculations with status code '{HttpStatusCode.NotFound}'"; CalculationsService calculationsService = CreateCalculationsService(calculationsApiClient, logger); //Act Func <Task> test = async() => await calculationsService.HaveAllTemplateCalculationsBeenApproved(specificationId); //Assert test .Should() .ThrowExactly <RetriableException>() .Which .Message .Should() .Be(errorMessage); logger .Received(1) .Error(Arg.Is(errorMessage)); }