Exemplo n.º 1
0
        public async void ImageTagManipulation()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                HttpMockServer.Initialize(this.GetType(), "ImageTagManipulation", RecorderMode);

                using (var project = CreateTrainedImageClassificationProject())
                {
                    ICustomVisionTrainingClient client = BaseTests.GetTrainingClient();

                    var untaggedImages = client.GetUntaggedImagesAsync(project.ProjectId).Result;
                    Assert.Equal(0, untaggedImages.Count);

                    var taggedImages = client.GetTaggedImagesAsync(project.ProjectId).Result;
                    Assert.Equal(10, taggedImages.Count);

                    var imageToBeModified = taggedImages[0].Id;
                    var tagToBeModified   = taggedImages[0].Tags[0].TagId;

                    await client.DeleteImageTagsAsync(project.ProjectId, new Guid[] { imageToBeModified }, new Guid[] { tagToBeModified });

                    untaggedImages = client.GetUntaggedImagesAsync(project.ProjectId).Result;
                    Assert.Equal(1, untaggedImages.Count);

                    var imageTags = new ImageTagCreateEntry(imageToBeModified, tagToBeModified);
                    var result    = client.CreateImageTagsAsync(project.ProjectId, new ImageTagCreateBatch(new ImageTagCreateEntry[] { imageTags })).Result;

                    Assert.Equal(1, result.Created.Count);
                    Assert.Equal(imageToBeModified, result.Created[0].ImageId);
                    Assert.Equal(tagToBeModified, result.Created[0].TagId);
                }
            }
        }