public async Task TestScenarioResultsService_PerformSearch_WhenGetAllSpecificationsLookupIsNull_ThenExceptionThrown() { // Arrange IScenarioSearchService searchService = CreateScenarioSearchService(); ISpecificationsApiClient specsApiClient = CreateSpecsApiClient(); ITestEngineApiClient testEngineApiClient = CreateTestEngineApiClient(); ILogger logger = CreateLogger(); TestScenarioResultRequestViewModel resultRequestViewModel = new TestScenarioResultRequestViewModel() { SearchTerm = "", PageNumber = 1, FundingPeriodId = null, SpecificationId = null, }; TestScenarioResultsService testScenarioResultsService = CreateService(searchService, specsApiClient, testEngineApiClient, logger: logger); searchService.PerformSearch(Arg.Any <SearchRequestViewModel>()) .Returns(new ScenarioSearchResultViewModel()); List <SpecificationSummary> specifications = CreateSpecifications(); specsApiClient .GetSpecificationSummaries() .Returns((ApiResponse <IEnumerable <SpecificationSummary> >)null); // Act Func <Task> action = async() => await testScenarioResultsService.PerformSearch(resultRequestViewModel); // Assert action. Should() .ThrowExactly <InvalidOperationException>() .WithMessage("Specifications API Response was null"); logger .Received(1) .Warning(Arg.Is("Specifications API Response was null")); await specsApiClient .Received(1) .GetSpecificationSummaries(); }
private async Task ThenTheSpecificationWasDeselectedForFunding(string specificationId) { await _specificationsApiClient .Received(1) .DeselectSpecificationForFunding(specificationId); }
public async Task TestScenarioResultsService_PerformSearch_WhenTestScenariosExist_ThenResultsAreReturned() { // Arrange IScenarioSearchService searchService = CreateScenarioSearchService(); ISpecificationsApiClient specsApiClient = CreateSpecsApiClient(); ITestEngineApiClient testEngineApiClient = CreateTestEngineApiClient(); TestScenarioResultsService testScenarioResultsService = CreateService(searchService, specsApiClient, testEngineApiClient); TestScenarioResultRequestViewModel resultRequestViewModel = new TestScenarioResultRequestViewModel() { SearchTerm = "", PageNumber = 1, FundingPeriodId = null, SpecificationId = null, }; ScenarioSearchResultViewModel scenarioSearchResultViewModel = new ScenarioSearchResultViewModel() { CurrentPage = 1, TotalResults = 1, StartItemNumber = 1, EndItemNumber = 1, Scenarios = new List <ScenarioSearchResultItemViewModel>() { new ScenarioSearchResultItemViewModel() { Id = "ts1", Name = "Test Scenario 1", FundingPeriodName = "2018/2019", Status = "Passed", SpecificationName = "Specifcation 1", LastUpdatedDate = new DateTime(2018, 1, 5, 7, 8, 9), } } }; searchService.PerformSearch(Arg.Is <SearchRequestViewModel>(s => s.SearchTerm == resultRequestViewModel.SearchTerm)) .Returns(scenarioSearchResultViewModel); List <SpecificationSummary> specifications = CreateSpecifications(); specsApiClient .GetSpecificationSummaries() .Returns(new ApiResponse <IEnumerable <SpecificationSummary> >(HttpStatusCode.OK, specifications.AsEnumerable())); List <TestScenarioResultCounts> testScenarioResultCounts = new List <TestScenarioResultCounts>(); testScenarioResultCounts.Add(new TestScenarioResultCounts() { Passed = 5, Failed = 10, Ignored = 50, LastUpdatedDate = new DateTime(2018, 10, 5, 7, 8, 9), TestScenarioId = "ts1", TestScenarioName = "Test Scenario 1", }); testEngineApiClient .GetTestResultCounts(Arg.Any <TestScenarioResultCountsRequestModel>()) .Returns(new ApiResponse <IEnumerable <TestScenarioResultCounts> >(HttpStatusCode.OK, testScenarioResultCounts)); // Act TestScenarioResultViewModel resultViewModel = await testScenarioResultsService.PerformSearch(resultRequestViewModel); // Assert resultViewModel.Should().NotBeNull(); TestScenarioResultViewModel expectedResult = new TestScenarioResultViewModel() { CurrentPage = 1, EndItemNumber = 1, Facets = new List <SearchFacetViewModel>(), FundingPeriodId = null, Specifications = new List <ReferenceViewModel>() { new ReferenceViewModel("spec1", "Specification 1"), new ReferenceViewModel("spec2", "Specification 2"), new ReferenceViewModel("spec3", "Specification for 2018/2019"), }, StartItemNumber = 1, TotalResults = 1, TestResults = new List <TestScenarioResultItemViewModel>() { new TestScenarioResultItemViewModel() { Id = "ts1", Name = "Test Scenario 1", Passes = 5, Failures = 10, Ignored = 50, LastUpdatedDate = new DateTime(2018, 1, 5, 7, 8, 9), } } }; resultViewModel.Should().BeEquivalentTo(expectedResult); await specsApiClient .Received(1) .GetSpecificationSummaries(); }