public async Task OnPostAsync_GivenResultsIsNull_ReturnsStatusCodeResult500() { //Arrange ApiResponse <TestScenario> scenario = new ApiResponse <TestScenario>(HttpStatusCode.OK, new TestScenario()); IScenariosApiClient apiClient = CreateScenariosClient(); apiClient .GetCurrentTestScenarioById(Arg.Is(Scenarioid)) .Returns(scenario); TestScenarioViewModel scenarioViewModel = new TestScenarioViewModel(); ITestResultsSearchService resultsService = CreateResultsService(); resultsService .PerformProviderTestResultsSearch(Arg.Any <SearchRequestViewModel>()) .Returns((ProviderTestsSearchResultViewModel)null); ViewProviderTestResultsPageModel pageModel = CreatePageModel(scenariosApiClient: apiClient); //Act IActionResult result = await pageModel.OnPostAsync(Scenarioid, null, ""); //Assert result .Should() .BeOfType <InternalServerErrorResult>() .Which .Value .Should() .Be("Provider Results returned null"); }
public async Task OnPostAsync_GivenResultsReturned_ReturnsPage() { //Arrange ApiResponse <TestScenario> scenario = new ApiResponse <TestScenario>(HttpStatusCode.OK, new TestScenario()); IScenariosApiClient scenariosClient = CreateScenariosClient(); scenariosClient .GetCurrentTestScenarioById(Arg.Is(Scenarioid)) .Returns(scenario); TestScenarioViewModel scenarioViewModel = new TestScenarioViewModel(); ProviderTestsSearchResultViewModel viewModel = new ProviderTestsSearchResultViewModel(); ITestResultsSearchService resultsService = CreateResultsService(); resultsService .PerformProviderTestResultsSearch(Arg.Any <SearchRequestViewModel>()) .Returns(viewModel); ITestEngineApiClient testEngineClient = CreateTestEngineClient(); List <TestScenarioResultCounts> countResults = new List <TestScenarioResultCounts>(); testEngineClient .GetTestResultCounts(Arg.Is <TestScenarioResultCountsRequestModel>(c => c.TestScenarioIds.Count() == 1 && c.TestScenarioIds.First() == Scenarioid)) .Returns(new ApiResponse <IEnumerable <TestScenarioResultCounts> >(HttpStatusCode.OK, countResults)); ISpecsApiClient specsApiClient = CreateSpecsClient(); specsApiClient .GetSpecificationSummary(Arg.Any <string>()) .Returns(new ApiResponse <Clients.SpecsClient.Models.SpecificationSummary>(HttpStatusCode.OK, new Clients.SpecsClient.Models.SpecificationSummary())); ViewProviderTestResultsPageModel pageModel = CreatePageModel(resultsService, testEngineClient, scenariosClient, specsApiClient); //Act IActionResult result = await pageModel.OnPostAsync(Scenarioid, null, ""); //Assert result .Should() .BeAssignableTo <PageResult>(); }
public async Task OnPostAsync_GivenCountTaskIsNull_ThenErrorIsReturned() { //Arrange ApiResponse <TestScenario> scenario = new ApiResponse <TestScenario>(HttpStatusCode.OK, new TestScenario()); IScenariosApiClient apiClient = CreateScenariosClient(); apiClient .GetCurrentTestScenarioById(Arg.Is(Scenarioid)) .Returns(scenario); ProviderTestsSearchResultViewModel viewModel = new ProviderTestsSearchResultViewModel(); ITestResultsSearchService resultsService = CreateResultsService(); resultsService .PerformProviderTestResultsSearch(Arg.Any <SearchRequestViewModel>()) .Returns(viewModel); ITestEngineApiClient testEngineApiClient = CreateTestEngineClient(); testEngineApiClient .GetTestResultCounts(Arg.Any <TestScenarioResultCountsRequestModel>()) .Returns((ApiResponse <IEnumerable <TestScenarioResultCounts> >)null); ViewProviderTestResultsPageModel pageModel = CreatePageModel(resultsService, testEngineApiClient, scenariosApiClient: apiClient); //Act IActionResult result = await pageModel.OnPostAsync(Scenarioid, null, ""); //Assert result .Should() .BeOfType <InternalServerErrorResult>() .Which .Value .Should() .Be("Count Task result was null"); await testEngineApiClient .Received(1) .GetTestResultCounts(Arg.Any <TestScenarioResultCountsRequestModel>()); }
public async Task OnPostAsync_GivenScenarioNotReturned_ReturnsNotFoundResult() { //Arrange ApiResponse <TestScenario> scenario = new ApiResponse <TestScenario>(HttpStatusCode.NotFound); IScenariosApiClient apiClient = CreateScenariosClient(); apiClient .GetCurrentTestScenarioById(Arg.Is(Scenarioid)) .Returns(scenario); ViewProviderTestResultsPageModel pageModel = CreatePageModel(scenariosApiClient: apiClient); //Act IActionResult result = await pageModel.OnPostAsync(Scenarioid, null, ""); //Assert result .Should() .BeAssignableTo <NotFoundResult>(); }