Beispiel #1
0
        public async Task FetchCoreProviderData_WhenInCache_ThenReturnsCacheValue()
        {
            // Arrange
            IResultsApiClientProxy resultsApiClient = CreateResultsApiClient();

            resultsApiClient
            .PostAsync <ProviderSearchResults, SearchModel>(Arg.Is("results/providers-search"), Arg.Any <SearchModel>())
            .Returns(new ProviderSearchResults {
                TotalCount = 3
            });

            List <ProviderSummary> cachedProviderSummaries = new List <ProviderSummary>
            {
                new ProviderSummary {
                    Id = "one"
                },
                new ProviderSummary {
                    Id = "two"
                },
                new ProviderSummary {
                    Id = "three"
                }
            };

            ICacheProvider cacheProvider = CreateCacheProvider();

            cacheProvider
            .GetAsync <string>(Arg.Is(CacheKeys.AllProviderSummaryCount))
            .Returns("3");

            cacheProvider
            .ListRangeAsync <ProviderSummary>(Arg.Is(CacheKeys.AllProviderSummaries), Arg.Is(0), Arg.Is(3))
            .Returns(cachedProviderSummaries);

            cacheProvider
            .ListLengthAsync <ProviderSummary>(Arg.Is(CacheKeys.AllProviderSummaries))
            .Returns(3);

            IProviderService providerService = CreateProviderService(cacheProvider: cacheProvider, resultsApiClient: resultsApiClient);

            // Act
            IEnumerable <ProviderSummary> results = await providerService.FetchCoreProviderData();

            // Assert
            results.Should().Contain(cachedProviderSummaries);
        }
Beispiel #2
0
        public async Task FetchCoreProviderData_WhenNotInCache_ThenReturnsSearchValue()
        {
            // Arrange
            IResultsApiClientProxy resultsApiClient = CreateResultsApiClient();

            resultsApiClient
            .PostAsync <ProviderSearchResults, SearchModel>(Arg.Is("results/providers-search"), Arg.Any <SearchModel>())
            .Returns(new ProviderSearchResults
            {
                TotalCount = 3,
                Results    = new List <ProviderSearchResult>
                {
                    new ProviderSearchResult {
                        ProviderId = "one"
                    },
                    new ProviderSearchResult {
                        ProviderId = "two"
                    },
                    new ProviderSearchResult {
                        ProviderId = "three"
                    }
                }
            });

            ICacheProvider cacheProvider = CreateCacheProvider();

            cacheProvider
            .GetAsync <string>(Arg.Is(CacheKeys.AllProviderSummaryCount))
            .Returns("0");

            IProviderService providerService = CreateProviderService(cacheProvider: cacheProvider, resultsApiClient: resultsApiClient);

            // Act
            IEnumerable <ProviderSummary> results = await providerService.FetchCoreProviderData();

            // Assert
            results
            .Should()
            .HaveCount(3);

            results.Should().Contain(r => r.Id == "one");
            results.Should().Contain(r => r.Id == "two");
            results.Should().Contain(r => r.Id == "three");
        }
Beispiel #3
0
        public async Task FetchCoreProviderData_WhenNotInCache_ThenAddsToCache()
        {
            // Arrange
            IResultsApiClientProxy resultsApiClient = CreateResultsApiClient();

            resultsApiClient
            .PostAsync <ProviderSearchResults, SearchModel>(Arg.Is("results/providers-search"), Arg.Any <SearchModel>())
            .Returns(new ProviderSearchResults
            {
                TotalCount = 3,
                Results    = new List <ProviderSearchResult>
                {
                    new ProviderSearchResult {
                        ProviderId = "one"
                    },
                    new ProviderSearchResult {
                        ProviderId = "two"
                    },
                    new ProviderSearchResult {
                        ProviderId = "three"
                    }
                }
            });

            ICacheProvider cacheProvider = CreateCacheProvider();

            cacheProvider
            .GetAsync <string>(Arg.Is(CacheKeys.AllProviderSummaryCount))
            .Returns("0");

            IProviderService providerService = CreateProviderService(cacheProvider: cacheProvider, resultsApiClient: resultsApiClient);

            // Act
            IEnumerable <ProviderSummary> results = await providerService.FetchCoreProviderData();

            // Assert
            await cacheProvider
            .Received(1)
            .KeyDeleteAsync <ProviderSummary>(Arg.Is(CacheKeys.AllProviderSummaries));

            await cacheProvider
            .Received(1)
            .CreateListAsync(Arg.Is <List <ProviderSummary> >(l => l.Count == 3), Arg.Is(CacheKeys.AllProviderSummaries));
        }
Beispiel #4
0
 public Task <ProviderSearchResults> SearchProviders(SearchModel searchModel)
 {
     return(_resultsApiClient.PostAsync <ProviderSearchResults, SearchModel>(GetProvidersFromSearchUri, searchModel));
 }
 public Task <HttpStatusCode> UpdateProviderResults(IEnumerable <ProviderResult> providerResults, UserProfile userProfile)
 {
     return(_apiClient.PostAsync(updateProviderResultsUrl, providerResults, userProfile));
 }