public async Task TestSearch(string indexId, string validSearchTerm) { Assert.ThrowsAsync <SovrenException>(async() => { await Client.Search(null, null); }); List <string> indexesToQuery = new List <string>() { indexId }; Assert.ThrowsAsync <SovrenException>(async() => { await Client.Search(indexesToQuery, null); }); FilterCriteria filterCritera = new FilterCriteria(); Assert.ThrowsAsync <SovrenException>(async() => { await Client.Search(null, filterCritera); }); Assert.ThrowsAsync <SovrenException>(async() => { await Client.Search(new List <string>() { "fake-index-id" }, filterCritera); }); Assert.ThrowsAsync <SovrenException>(async() => { await Client.Search(indexesToQuery, filterCritera); }); filterCritera.SearchExpression = validSearchTerm; Assert.DoesNotThrow(() => { SearchResponseValue response = Client.Search(indexesToQuery, filterCritera).Result.Value; Assert.AreEqual(1, response.CurrentCount); Assert.AreEqual(1, response.TotalCount); }); filterCritera.SearchExpression = "ThisIsATermThatIsntInTheDocument"; Assert.DoesNotThrow(() => { SearchResponseValue response = Client.Search(indexesToQuery, filterCritera).Result.Value; Assert.AreEqual(0, response.CurrentCount); Assert.AreEqual(0, response.TotalCount); }); await Task.CompletedTask; }
public async Task TestJobLifeCycle() { const string documentId = "1"; try { // verify can't retrieve a document that doesn't exist SovrenException sovrenException = Assert.ThrowsAsync <SovrenException>(async() => { await Client.GetJob(jobIndexId, documentId); }); Assert.AreEqual(SovrenErrorCodes.DataNotFound, sovrenException.SovrenErrorCode); // verify can't add document to an index that doesn't exist sovrenException = Assert.ThrowsAsync <SovrenException>(async() => { await Client.IndexDocument(TestParsedJob, jobIndexId, documentId); }); Assert.AreEqual(SovrenErrorCodes.DataNotFound, sovrenException.SovrenErrorCode); // create the index await Client.CreateIndex(IndexType.Job, jobIndexId); await DelayForIndexSync(); // verify document still doesn't exist sovrenException = Assert.ThrowsAsync <SovrenException>(async() => { await Client.GetJob(jobIndexId, documentId); }); Assert.AreEqual(SovrenErrorCodes.DataNotFound, sovrenException.SovrenErrorCode); // add resume to index await Client.IndexDocument(TestParsedJob, jobIndexId, documentId); await DelayForIndexSync(); // confirm you can now retrieve the resume await Client.GetJob(jobIndexId, documentId); // confirm the resume shows up in searches List <string> indexesToQuery = new List <string>() { jobIndexId }; FilterCriteria filterCriteria = new FilterCriteria() { DocumentIds = new List <string>() { documentId } }; SearchResponseValue searchResponse = Client.Search(indexesToQuery, filterCriteria).Result.Value; Assert.AreEqual(1, searchResponse.TotalCount); Assert.AreEqual(1, searchResponse.CurrentCount); Assert.AreEqual(documentId, searchResponse.Matches[0].Id); // update the resume List <string> userDefinedTags = new List <string> { "userDefinedTag1" }; await Client.UpdateJobUserDefinedTags(jobIndexId, documentId, userDefinedTags, UserDefinedTagsMethod.Overwrite); await DelayForIndexSync(); // verify those updates have taken effect filterCriteria.UserDefinedTags = userDefinedTags; searchResponse = Client.Search(indexesToQuery, filterCriteria).Result.Value; Assert.AreEqual(1, searchResponse.TotalCount); Assert.AreEqual(1, searchResponse.CurrentCount); Assert.AreEqual(documentId, searchResponse.Matches[0].Id); // confirm you can retrieve the tags ParsedJob job = Client.GetJob(jobIndexId, documentId).Result.Value; Assert.AreEqual(1, job.UserDefinedTags.Count); Assert.AreEqual(userDefinedTags[0], job.UserDefinedTags[0]); // delete the document await Client.DeleteDocument(jobIndexId, documentId); await DelayForIndexSync(); // verify can't retrieve a document that doesn't exist sovrenException = Assert.ThrowsAsync <SovrenException>(async() => { await Client.GetJob(jobIndexId, documentId); }); Assert.AreEqual(SovrenErrorCodes.DataNotFound, sovrenException.SovrenErrorCode); sovrenException = Assert.ThrowsAsync <SovrenException>(async() => { await Client.DeleteDocument(jobIndexId, documentId); }); Assert.AreEqual(SovrenErrorCodes.DataNotFound, sovrenException.SovrenErrorCode); await Client.DeleteIndex(jobIndexId); await DelayForIndexSync(); sovrenException = Assert.ThrowsAsync <SovrenException>(async() => { await Client.DeleteDocument(jobIndexId, documentId); }); Assert.AreEqual(SovrenErrorCodes.DataNotFound, sovrenException.SovrenErrorCode); } finally { await CleanUpIndex(jobIndexId); } }