public async Task PopulateIndexAsyncTest(int statusCode) { //Arrange or configure var dummyCollectionOfData = DummyJobProfileIndex.GenerateJobProfileIndexDummyCollection("test", 5); A.Dummy <IndexBatch <JobProfileIndex> >(); var azOpResponse = new AzureOperationResponse <DocumentIndexResult> { Body = new DocumentIndexResult(new List <IndexingResult> { new IndexingResult(statusCode: statusCode, succeeded: statusCode < 400) }) }; A.CallTo(() => fakeIndexClient.Documents).Returns(fakeDocuments); A.CallTo(() => fakeDocuments.IndexWithHttpMessagesAsync( A <IndexBatch <JobProfileIndex> > ._, A <SearchRequestOptions> ._, A <Dictionary <string, List <string> > > ._, A <CancellationToken> ._)) .Returns(azOpResponse); var azSearchService = new AzSearchService <JobProfileIndex>(fakeSearchClient, fakeIndexClient, fakeSuggesterBuilder, policy, fakeWeightingBuilder); await azSearchService.PopulateIndexAsync(dummyCollectionOfData); A.CallTo(() => fakeIndexClient.Documents).MustHaveHappened(); A.CallTo(() => fakeDocuments.IndexWithHttpMessagesAsync( A <IndexBatch <JobProfileIndex> > ._, A <SearchRequestOptions> ._, A <Dictionary <string, List <string> > > ._, A <CancellationToken> ._)) .MustHaveHappened(statusCode > 400 ? Repeated.Exactly.Times(strategy.Retry + 1) : Repeated.Exactly.Once); }
public async Task EnsureIndexTestAsync() { //Arrange or configure A.CallTo(() => fakeSearchClient.Indexes).Returns(fakeIndexes); var azSearchService = new AzSearchService <JobProfileIndex>(fakeSearchClient, fakeIndexClient, fakeSuggesterBuilder, policy, fakeWeightingBuilder); await azSearchService.EnsureIndexAsync("test"); A.CallTo(() => fakeSuggesterBuilder.BuildForType <JobProfileIndex>()).MustHaveHappened(); A.CallTo(() => fakeWeightingBuilder.BuildForType <JobProfileIndex>()).MustHaveHappened(); A.CallTo(() => fakeSearchClient.Indexes).MustHaveHappened(); A.CallTo(() => fakeIndexes.CreateOrUpdateWithHttpMessagesAsync(A <Index> .That.Matches(i => i.Name.Equals("test") && i.Suggesters.Count == 1 && i.Suggesters.First().Name == Constants.DefaultSuggesterName), A <bool?> ._, A <SearchRequestOptions> ._, A <AccessCondition> ._, A <Dictionary <string, List <string> > > ._, A <CancellationToken> ._)).MustHaveHappened(); }
public void IndexExistsTest() { //Arrange or configure var azOpResponse = new AzureOperationResponse <bool> { Body = true }; A.CallTo(() => fakeSearchClient.Indexes).Returns(fakeIndexes); A.CallTo(() => fakeIndexes.ExistsWithHttpMessagesAsync( A <string> ._, A <SearchRequestOptions> ._, A <Dictionary <string, List <string> > > ._, A <CancellationToken> ._)) .Returns(azOpResponse); var azSearchService = new AzSearchService <JobProfileIndex>(fakeSearchClient, fakeIndexClient, fakeSuggesterBuilder, policy, fakeWeightingBuilder); azSearchService.IndexExists("test"); A.CallTo(() => fakeSearchClient.Indexes).MustHaveHappened(); A.CallTo(() => fakeIndexes.ExistsWithHttpMessagesAsync( A <string> .That.IsEqualTo("test"), A <SearchRequestOptions> ._, A <Dictionary <string, List <string> > > ._, A <CancellationToken> ._)).MustHaveHappened(); }