public void TestScenarioResultsService_PerformSearch_WhenRowCountsApiCallContentIsNull_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() { Scenarios = new List <ScenarioSearchResultItemViewModel>() { new ScenarioSearchResultItemViewModel() { Id = "s1", Name = "S1", }, new ScenarioSearchResultItemViewModel() { Id = "s2", Name = "S2", }, } }); List <SpecificationSummary> specifications = CreateSpecifications(); specsApiClient .GetSpecificationSummaries() .Returns(new ApiResponse <IEnumerable <SpecificationSummary> >(HttpStatusCode.OK, specifications)); testEngineApiClient .GetTestResultCounts(Arg.Any <TestScenarioResultCountsRequestModel>()) .Returns(new ApiResponse <IEnumerable <TestScenarioResultCounts> >(HttpStatusCode.OK, null)); // Act Func <Task> action = async() => await testScenarioResultsService.PerformSearch(resultRequestViewModel); // Assert action. Should() .ThrowExactly <InvalidOperationException>() .WithMessage("Row counts api request failed with null content"); logger .Received(1) .Warning(Arg.Is("Row counts api request failed with null content")); }
public void TestScenarioResultsService_PerformSearch_WhenTestScenariosSearchResultsIsNull_ThenExceptionThrown() { // Arrange IScenarioSearchService searchService = CreateScenarioSearchService(); ISpecificationsApiClient specsApiClient = CreateSpecsApiClient(); ITestEngineApiClient testEngineApiClient = CreateTestEngineApiClient(); ILogger logger = CreateLogger(); string specificationId = "spec1"; TestScenarioResultsService testScenarioResultsService = CreateService(searchService, specsApiClient, testEngineApiClient, logger: logger); TestScenarioResultRequestViewModel resultRequestViewModel = new TestScenarioResultRequestViewModel() { SearchTerm = "", PageNumber = 1, FundingPeriodId = null, SpecificationId = specificationId, }; ScenarioSearchResultViewModel scenarioSearchResultViewModel = null; 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())); // Act Func <Task> action = async() => await testScenarioResultsService.PerformSearch(resultRequestViewModel); // Assert action. Should() .ThrowExactly <InvalidOperationException>() .WithMessage("Scenario Search Results response was null"); logger .Received(1) .Warning(Arg.Is <string>("Scenario Search Results response was null")); }
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(); }
public void TestScenarioResultsService_PerformSearch_WhenGetAllSpecificationsLookupResponseIsNotOk_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()); specsApiClient .GetSpecificationSummaries() .Returns(new ApiResponse <IEnumerable <SpecificationSummary> >(HttpStatusCode.InternalServerError, null)); // Act Func <Task> action = async() => await testScenarioResultsService.PerformSearch(resultRequestViewModel); // Assert action. Should() .ThrowExactly <InvalidOperationException>() .WithMessage("Specifications API Response content did not return OK, but instead 'InternalServerError'"); logger .Received(1) .Warning(Arg.Is("Specifications API Response content did not return OK, but instead {specificationsApiResponse.StatusCode}"), Arg.Is(HttpStatusCode.InternalServerError)); }
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(); }