public async Task SearchProviderVersions_WhenProviderIdExists_ProviderReturned()
        {
            // Arrange
            ProviderVersionViewModel providerVersionViewModel = CreateProviderVersion();

            Provider provider = GetProvider();

            providerVersionViewModel.Providers   = providerVersionViewModel.Providers.Concat(new[] { provider });
            providerVersionViewModel.VersionType = ProviderVersionType.Custom;

            ICacheProvider cacheProvider = CreateCacheProvider();

            SearchResults <ProvidersIndex> searchResults = new SearchResults <ProvidersIndex> {
                Results = new List <Repositories.Common.Search.SearchResult <ProvidersIndex> > {
                    new Repositories.Common.Search.SearchResult <ProvidersIndex> {
                        Result = new ProvidersIndex {
                            ProviderVersionId = provider.ProviderVersionId, UKPRN = provider.UKPRN
                        }
                    }
                }
            };

            ISearchRepository <ProvidersIndex> searchRepository = CreateSearchRepository();

            searchRepository
            .Search(Arg.Any <string>(), Arg.Any <SearchParameters>())
            .Returns(searchResults);

            IProviderVersionSearchService providerService = CreateProviderVersionSearchService(cacheProvider: cacheProvider, searchRepository: searchRepository);

            // Act
            IActionResult okRequest = await providerService.SearchProviderVersions(new Models.SearchModel {
                Filters = new Dictionary <string, string[]> {
                    { "providerId", new List <string> {
                          provider.ProviderId
                      }.ToArray() }
                }
            });

            await searchRepository.Received(1)
            .Search(Arg.Any <string>(), Arg.Is <SearchParameters>(c => c.Filter.Contains(provider.ProviderId)));

            okRequest
            .Should()
            .BeOfType <OkObjectResult>();

            ((OkObjectResult)okRequest).Value
            .Should()
            .BeOfType <ProviderVersionSearchResults>();
        }
        public async Task SearchProviderVersions_WhenSearchThrowsError_InternalServerErrorThrown()
        {
            // Arrange
            ProviderVersionViewModel providerVersionViewModel = CreateProviderVersion();

            Provider provider = GetProvider();

            providerVersionViewModel.Providers   = providerVersionViewModel.Providers.Concat(new[] { provider });
            providerVersionViewModel.VersionType = ProviderVersionType.Custom;

            ICacheProvider cacheProvider = CreateCacheProvider();

            SearchResults <ProvidersIndex> searchResults = new SearchResults <ProvidersIndex> {
                Results = new List <Repositories.Common.Search.SearchResult <ProvidersIndex> > {
                    new Repositories.Common.Search.SearchResult <ProvidersIndex> {
                        Result = new ProvidersIndex {
                            ProviderVersionId = provider.ProviderVersionId, UKPRN = provider.UKPRN
                        }
                    }
                }
            };

            ISearchRepository <ProvidersIndex> searchRepository = CreateSearchRepository();

            searchRepository
            .When(s => s.Search(Arg.Any <string>(), Arg.Any <SearchParameters>()))
            .Do(x => { throw new FailedToQuerySearchException("Test Message", null); });

            IProviderVersionSearchService providerService = CreateProviderVersionSearchService(cacheProvider: cacheProvider, searchRepository: searchRepository);

            // Act
            IActionResult okRequest = await providerService.SearchProviderVersions(new Models.SearchModel {
                Filters = new Dictionary <string, string[]> {
                    { "providerId", new List <string> {
                          provider.ProviderId
                      }.ToArray() }
                }
            });

            await searchRepository.Received(1)
            .Search(Arg.Any <string>(), Arg.Is <SearchParameters>(c => c.Filter.Contains(provider.ProviderId)));

            okRequest
            .Should()
            .BeOfType <InternalServerErrorResult>();
        }
 public async Task <IActionResult> SearchProviderVersions([FromBody] SearchModel searchModel)
 {
     return(await _providerVersionSearchService.SearchProviderVersions(searchModel));
 }