public SearchIndexClientFactoryTests() { defaultSharedConfig = new JobProfileSearchIndexConfig { SearchIndex = "SharedIndexName", AccessKey = "SharedAccessKey", SearchServiceName = "JobProfilesApiTest" }; defaultSharedConfigService = A.Fake <ISharedConfigurationService>(); A.CallTo(() => defaultSharedConfigService.GetConfigAsync <JobProfileSearchIndexConfig>(A <string> .Ignored, A <string> .Ignored, A <bool> .Ignored)).Returns(defaultSharedConfig); defaultConfigParams = new SharedConfigParameters { SharedConfigServiceName = "TestServiceName", SharedConfigKeyName = "TestKeyName" }; defaultConfigFactory = new SearchIndexClientFactory(defaultSharedConfigService, defaultConfigParams); }
public async Task GetSearchIndexClientRefreshesIndexClientFromSharedConfig() { // Arrange var staleSharedConfig = new JobProfileSearchIndexConfig { SearchIndex = "StaleIndexName", AccessKey = "SharedAccessKey", SearchServiceName = "JobProfilesApiTest" }; var sharedConfigService = A.Fake <ISharedConfigurationService>(); A.CallTo(() => sharedConfigService.GetConfigAsync <JobProfileSearchIndexConfig>(A <string> .Ignored, A <string> .Ignored, A <bool> .Ignored)).Returns(staleSharedConfig); var searchIndexClientFactory = new SearchIndexClientFactory(sharedConfigService, defaultConfigParams); // Act var staleIndex = await searchIndexClientFactory.GetSearchIndexClient().ConfigureAwait(false); A.CallTo(() => sharedConfigService.GetConfigAsync <JobProfileSearchIndexConfig>(A <string> .Ignored, A <string> .Ignored, A <bool> .Ignored)).Returns(defaultSharedConfig); var freshIndex = await searchIndexClientFactory.GetSearchIndexClient().ConfigureAwait(false); // Assert Assert.NotEqual(staleIndex.IndexName, freshIndex.IndexName); Assert.Equal(defaultSharedConfig.SearchIndex, freshIndex.IndexName); A.CallTo(() => sharedConfigService.GetConfigAsync <JobProfileSearchIndexConfig>(A <string> .Ignored, A <string> .Ignored, A <bool> .Ignored)).MustHaveHappenedTwiceExactly(); }
private void CreateSearchIndexClient(JobProfileSearchIndexConfig configItem) { indexClient = new SearchIndexClient(configItem.SearchServiceName, configItem.SearchIndex, new SearchCredentials(configItem.AccessKey)); }