[TestCase("591", 8)]    // 59111-Motion picture... + 59112-Video... + 59113-Television...
        public async Task ViewingService_GetListOfSicCodeSuggestions(string searchKeyWords,
                                                                     int expectedNumberOfSuggestions)
        {
            // Arrange
            var sicCodeSearchServiceClient = new SearchServiceClient(
                ConfigHelpers.SearchOptions.AzureServiceName,
                new SearchCredentials(ConfigHelpers.SearchOptions.AzureApiAdminKey));

            var sicCodeSearchIndexClient = new AzureSicCodeSearchRepository(Mock.Of <IAuditLogger>(),
                                                                            sicCodeSearchServiceClient, ConfigHelpers.SearchOptions.SicCodeIndexName);

            var mockViewingService = new Mock <IViewingService>();

            mockViewingService.Setup(m => m.SearchBusinessLogic.EmployerSearchRepository).Returns(_azureSearchRepo);
            mockViewingService.Setup(m => m.SearchBusinessLogic.SicCodeSearchRepository)
            .Returns(sicCodeSearchIndexClient);
            var testPresenter = new ViewingPresenter(mockViewingService.Object, Mock.Of <ISharedBusinessLogic>());

            // Act
            var result = await testPresenter.GetListOfSicCodeSuggestionsAsync(searchKeyWords);

            // Assert
            var actualNumberOfSuggestions = result.Count;

            Assert.AreEqual(
                expectedNumberOfSuggestions,
                actualNumberOfSuggestions,
                $"Expected term [{searchKeyWords}] to return {expectedNumberOfSuggestions} suggestion(s).");
        }
        public void SicCodeSearchRepository_Can_Be_Created()
        {
            // Arrange
            var sicCodeSearchServiceClient = new SearchServiceClient(
                ConfigHelpers.SearchOptions.AzureServiceName,
                new SearchCredentials(ConfigHelpers.SearchOptions.AzureApiAdminKey));

            // Act
            var actualSicCodeSearchRepository = new AzureSicCodeSearchRepository(Mock.Of <IAuditLogger>(),
                                                                                 sicCodeSearchServiceClient, ConfigHelpers.SearchOptions.SicCodeIndexName);

            // Assert
            Assert.NotNull(
                actualSicCodeSearchRepository,
                "This test should have been able to create a SicCodeSearchRepository object but seems it was unable to do so");
        }
        public async Task ViewingService_Search_BySectorType_Selects_Sectors_That_Contain_All_Terms(
            string searchKeyWords,
            string csvListOfSicSectionsExpectedToBeSelected)
        {
            // Arrange
            var sicCodeSearchServiceClient = new SearchServiceClient(
                ConfigHelpers.SearchOptions.AzureServiceName,
                new SearchCredentials(ConfigHelpers.SearchOptions.AzureApiAdminKey));

            var sicCodeSearchIndexClient = new AzureSicCodeSearchRepository(Mock.Of <IAuditLogger>(),
                                                                            sicCodeSearchServiceClient, ConfigHelpers.SearchOptions.SicCodeIndexName);

            var mockDataRepo = MoqHelpers.CreateMockDataRepository();

            var mockViewingService = new Mock <IViewingService>();

            mockViewingService.Setup(m => m.SearchBusinessLogic.EmployerSearchRepository).Returns(_azureSearchRepo);
            mockViewingService.Setup(m => m.SearchBusinessLogic.SicCodeSearchRepository)
            .Returns(sicCodeSearchIndexClient);
            var testPresenter = new ViewingPresenter(mockViewingService.Object, Mock.Of <ISharedBusinessLogic>());

            #region Calculate the expected number of records

            // Convert the received csv list to a list of EmployerSearchParameters
            var listOfSicSectionDescriptionsToBeSelected = csvListOfSicSectionsExpectedToBeSelected
                                                           .SplitI(";")
                                                           .Select(
                sicSectionDescriptionFoundInList =>
            {
                var sicCodeToSearchBy = sicSectionDescriptionFoundInList.SplitI("~")[1].Trim();

                return(Mock.Of <EmployerSearchParameters>(
                           searchParam =>
                           searchParam.Keywords == sicCodeToSearchBy &&
                           searchParam.Page == 1 &&
                           searchParam.PageSize == 3000 &&
                           searchParam.SearchFields == $"{nameof(EmployerSearchModel.SicCodeIds)}" &&
                           searchParam.SearchType == SearchTypes.ByEmployerName &&
                           searchParam.SearchMode == SearchModes.All));
            });

            var listOfEmployerSearchModel = new List <EmployerSearchModel>();
            foreach (var sicSectionDescriptionSearchParameter in listOfSicSectionDescriptionsToBeSelected)
            {
                var sicSectionDescriptionSearchViewModel =
                    await testPresenter.SearchAsync(sicSectionDescriptionSearchParameter);

                Assert.GreaterOrEqual(
                    sicSectionDescriptionSearchViewModel.EmployerEndIndex,
                    1,
                    $"When searching for {sicSectionDescriptionSearchParameter.Keywords} we expect to find at least one organisation in the index.");
                listOfEmployerSearchModel.AddRange(sicSectionDescriptionSearchViewModel.Employers.Results);
            }

            var expectedListOfEmployerNames =
                listOfEmployerSearchModel.Select(x => x.Name).DistinctI().OrderBy(x => x);

            #endregion

            var mockedSearchParameters =
                Mock.Of <EmployerSearchParameters>(
                    x => x.Keywords == searchKeyWords &&
                    x.Page == 1 &&
                    x.PageSize == 3000 &&
                    x.SearchFields == $"{nameof(EmployerSearchModel.SicCodeIds)}" &&
                    x.SearchType == SearchTypes.ByEmployerName &&
                    x.SearchMode == SearchModes.All);

            // Act
            var keywordSearchResultSearchViewModel = await testPresenter.SearchAsync(mockedSearchParameters);

            // Assert
            var actualListOfEmployerNames =
                keywordSearchResultSearchViewModel.Employers.Results.Select(x => x.Name).DistinctI().OrderBy(x => x);

            var foundMoreRecordsThanThoseExpected = actualListOfEmployerNames.Except(expectedListOfEmployerNames);
            Assert.IsEmpty(foundMoreRecordsThanThoseExpected);

            var expectedMoreRecordsThanThoseFound = expectedListOfEmployerNames.Except(actualListOfEmployerNames);
            Assert.IsEmpty(expectedMoreRecordsThanThoseFound);
        }