public void AnnotateImagesTest_InvalidAPIKey()
        {
            ImageFeatures feature = new ImageFeatures(ImageType.LABEL_DETECTION, MAX_RESULTS, VALID_MODEL);

            imageFeaturesList.Add(feature);

            AnnotateImageRequest     imageRequest     = GenerateImageRequest(VALID_IMAGE_URL, imageFeaturesList);
            AnnotateImageRequestList imageRequestList = new AnnotateImageRequestList(new List <AnnotateImageRequest>()
            {
                imageRequest
            });

            imageIntelligence.UpdateKey(INVALID_SETUP);

            Task <Tuple <AnnotateImageResponseList, ResponseStatus> > responses = imageIntelligence.AnnotateImages(imageRequestList);

            responses.Wait();

            imageIntelligence.UpdateKey(VALID_SETUP);

            Assert.IsNull(responses.Result.Item1);
            Assert.AreSame(responses.Result.Item2, ImageAnnotationStatus.INVALID_API_KEY);

            imageRequestList.Requests.Clear();
        }
        public void AnnotateImagesTest_ValidRequestWithTextDetection()
        {
            ImageFeatures feature = new ImageFeatures(ImageType.TEXT_DETECTION, MAX_RESULTS, VALID_MODEL);

            imageFeaturesList.Add(feature);

            AnnotateImageRequest     imageRequest     = GenerateImageRequest(TEXT_DETECTION_URL_1, imageFeaturesList);
            AnnotateImageRequestList imageRequestList = new AnnotateImageRequestList(new List <AnnotateImageRequest>()
            {
                imageRequest
            });

            Task <Tuple <AnnotateImageResponseList, ResponseStatus> > response = imageIntelligence.AnnotateImages(imageRequestList);

            response.Wait();

            AnnotateImageResponseList responseList = response.Result.Item1;

            Assert.IsNotNull(responseList);
            Assert.AreSame(response.Result.Item2, ImageAnnotationStatus.OK);

            Assert.GreaterOrEqual(responseList.Responses.Count, 1);

            for (int i = 0; i < responseList.Responses.Count; i++)
            {
                Assert.IsNotNull(responseList.Responses[i].TextAnnotations);
                Assert.GreaterOrEqual(responseList.Responses[i].TextAnnotations.Count, 1);

                Assert.IsNotNull(responseList.Responses[i].FullTextAnnotations);
                Assert.IsNotNull(responseList.Responses[i].FullTextAnnotations.Text);
                Assert.GreaterOrEqual(responseList.Responses[i].FullTextAnnotations.Pages.Count, 1);
            }

            imageRequestList.Requests.Clear();
        }
        public void AnnotateImagesTest_ValidRequestWithImageProperties()
        {
            ImageFeatures feature = new ImageFeatures(ImageType.IMAGE_PROPERTIES, MAX_RESULTS, VALID_MODEL);

            imageFeaturesList.Add(feature);

            AnnotateImageRequest     imageRequest     = GenerateImageRequest(VALID_IMAGE_URL, imageFeaturesList);
            AnnotateImageRequestList imageRequestList = new AnnotateImageRequestList(new List <AnnotateImageRequest>()
            {
                imageRequest
            });

            Task <Tuple <AnnotateImageResponseList, ResponseStatus> > response = imageIntelligence.AnnotateImages(imageRequestList);

            response.Wait();

            AnnotateImageResponseList responseList = response.Result.Item1;

            Assert.IsNotNull(responseList);
            Assert.AreSame(response.Result.Item2, ImageAnnotationStatus.OK);

            Assert.GreaterOrEqual(responseList.Responses.Count, 1);

            for (int i = 0; i < responseList.Responses.Count; i++)
            {
                Assert.IsNotNull(responseList.Responses[i].ImagePropertiesAnnotation);
                Assert.IsNotNull(responseList.Responses[i].ImagePropertiesAnnotation.DominantColors);
                Assert.GreaterOrEqual(responseList.Responses[i].ImagePropertiesAnnotation.DominantColors.Colors.Count, 1);
            }

            imageRequestList.Requests.Clear();
        }
        public void AnnotateImagesTest_OneValidAndOneInvalidImageURL()
        {
            ImageFeatures feature = new ImageFeatures(ImageType.LANDMARK_DETECTION, MAX_RESULTS, VALID_MODEL);

            imageFeaturesList.Add(feature);

            AnnotateImageRequest     imageRequest1    = GenerateImageRequest(IMAGE_URL, imageFeaturesList);
            AnnotateImageRequest     imageRequest2    = GenerateImageRequest(LANDMARK_ANNOTATION_URL_1, imageFeaturesList);
            AnnotateImageRequestList imageRequestList =
                new AnnotateImageRequestList(new List <AnnotateImageRequest>()
            {
                imageRequest1, imageRequest2
            });

            Task <Tuple <AnnotateImageResponseList, ResponseStatus> > responses = imageIntelligence.AnnotateImages(imageRequestList);

            responses.Wait();

            Assert.IsNotNull(responses.Result.Item1);

            AnnotateImageResponseList responseList = responses.Result.Item1;

            Assert.AreEqual(responseList.Responses.Count, 2);

            Assert.IsNotNull(responseList.Responses[0].Error);
            Assert.IsNotNull(responseList.Responses[0].Error.Message);
            Assert.IsNotEmpty(responseList.Responses[0].Error.Message);


            Assert.IsNotNull(responseList.Responses[1].LandmarkAnnotations);
            Assert.GreaterOrEqual(responseList.Responses[1].LandmarkAnnotations.Count, 1);

            imageRequestList.Requests.Clear();
        }
        public void AnnotateImagesTest_SingleInvalidImageURL()
        {
            ImageFeatures feature = new ImageFeatures(ImageType.LABEL_DETECTION, MAX_RESULTS, VALID_MODEL);

            imageFeaturesList.Add(feature);

            AnnotateImageRequest     imageRequest     = GenerateImageRequest(IMAGE_URL, imageFeaturesList);
            AnnotateImageRequestList imageRequestList = new AnnotateImageRequestList(new List <AnnotateImageRequest>()
            {
                imageRequest
            });

            Task <Tuple <AnnotateImageResponseList, ResponseStatus> > responses = imageIntelligence.AnnotateImages(imageRequestList);

            responses.Wait();

            Assert.IsNotNull(responses.Result.Item1);
            Assert.IsNotNull(responses.Result.Item1.Responses[0].Error);
            Assert.IsNotNull(responses.Result.Item1.Responses[0].Error.Message);
            Assert.IsNotEmpty(responses.Result.Item1.Responses[0].Error.Message);

            imageRequestList.Requests.Clear();
        }
        public void AnnotateImagesTest_ValidRequestWithMultipleAnnotations()
        {
            ImageFeatures feature = new ImageFeatures(ImageType.LANDMARK_DETECTION, MAX_RESULTS, VALID_MODEL);

            imageFeaturesList.Add(feature);
            AnnotateImageRequest imageRequest1 = GenerateImageRequest(LANDMARK_ANNOTATION_URL_1, imageFeaturesList);

            AnnotateImageRequestList imageRequestList =
                new AnnotateImageRequestList(new List <AnnotateImageRequest>()
            {
                imageRequest1
            });

            feature = new ImageFeatures(ImageType.FACE_DETECTION, MAX_RESULTS, VALID_MODEL);
            imageFeaturesList.Add(feature);
            AnnotateImageRequest imageRequest2 = GenerateImageRequest(FACE_ANNOTATION_URL, imageFeaturesList);

            imageRequestList.Requests.Add(imageRequest2);

            Task <Tuple <AnnotateImageResponseList, ResponseStatus> > response = imageIntelligence.AnnotateImages(imageRequestList);

            response.Wait();

            AnnotateImageResponseList responseList = response.Result.Item1;

            Assert.IsNotNull(responseList);
            Assert.AreSame(response.Result.Item2, ImageAnnotationStatus.OK);
            Assert.AreEqual(responseList.Responses.Count, 2);

            Assert.IsNotNull(responseList.Responses[0].LandmarkAnnotations);
            Assert.GreaterOrEqual(responseList.Responses[0].LandmarkAnnotations.Count, 1);

            Assert.IsNotNull(responseList.Responses[1].FaceAnnotations);
            Assert.GreaterOrEqual(responseList.Responses[1].FaceAnnotations.Count, 1);

            imageRequestList.Requests.Clear();
        }