public async Task <ClarifaiResponse <SearchInputsResult> > SearchByConcept(string concept) { var response = await client.SearchInputs(SearchBy.ConceptName(concept)) .Page(1) .ExecuteAsync(); return(response); }
public async Task SearchByConceptNameShouldBeSuccessful() { ClarifaiResponse <SearchInputsResult> response = await Client.SearchInputs(SearchBy.ConceptName("cat")) .ExecuteAsync(); // The search is either successful or nothing has been found. Assert.True(response.IsSuccessful || response.Status.StatusCode == 40002); }
public async Task SearchInputsByNameRequestAndResponseShouldBeCorrect() { var httpClient = new FkClarifaiHttpClient( postResponse: @" { ""status"": { ""code"": 10000, ""description"": ""Ok"" }, ""hits"": [ { ""score"": 0.99, ""input"": { ""id"": ""@inputID"", ""created_at"": ""2016-11-22T17:06:02Z"", ""data"": { ""image"": { ""url"": ""@inputURL"" } }, ""status"": { ""code"": 30000, ""description"": ""Download complete"" } } } ] } "); var client = new ClarifaiClient(httpClient); var response = await client.SearchInputs(SearchBy.ConceptName("@conceptName")) .ExecuteAsync(); var expectedRequestBody = JObject.Parse(@" { ""query"": { ""ands"": [ { ""output"": { ""data"": { ""concepts"": [ { ""name"": ""@conceptName"" } ] } } } ] } } "); Assert.True(JToken.DeepEquals(expectedRequestBody, httpClient.PostedBody)); Assert.True(response.IsSuccessful); List <SearchHit> searchHits = response.Get().SearchHits; Assert.AreEqual(1, searchHits.Count); Assert.AreEqual("@inputID", searchHits[0].Input.ID); IClarifaiInput input = searchHits[0].Input; Assert.AreEqual(InputType.Image, input.Type); Assert.AreEqual(InputForm.URL, input.Form); ClarifaiURLImage image = (ClarifaiURLImage)input; Assert.AreEqual("@inputURL", image.URL); }