コード例 #1
0
        public async Task SearchByMetadataShouldBeSuccessful()
        {
            string randomValue = GenerateRandomID();

            ClarifaiResponse <List <IClarifaiInput> > addInputResponse =
                await Client.AddInputs(
                    new ClarifaiURLImage(
                        CAT1,
                        positiveConcepts : new List <Concept> {
                new Concept("cat")
            },
                        allowDuplicateUrl : true,
                        metadata : new JObject(
                            new JProperty("key1", "val1"),
                            new JProperty("key2", randomValue))))
                .ExecuteAsync();

            AssertResponseSuccess(addInputResponse);

            string inputID = addInputResponse.Get()[0].ID;

            try
            {
                await WaitForSpecificInputsUpload(inputID);

                ClarifaiResponse <SearchInputsResult> response =
                    await Client.SearchInputs(new List <SearchBy>
                {
                    SearchBy.Metadata(new JObject(new JProperty("key2", randomValue)))
                })
                    .ExecuteAsync();

                Console.WriteLine(response.RawBody);

                AssertResponseSuccess(response);
                Assert.NotNull(response.Get().SearchHits);
                // Because the value we set is random, there should be exactly one hit.
                Assert.AreEqual(1, response.Get().SearchHits.Count);
            }
            finally
            {
                ClarifaiResponse <EmptyResponse> deleteInputResponse =
                    await Client.DeleteInputs(inputID).ExecuteAsync();

                AssertResponseSuccess(deleteInputResponse);
            }
        }