public async void RegionManipulation() { using (MockContext context = MockContext.Start(this.GetType())) { HttpMockServer.Initialize(this.GetType(), "RegionManipulation", RecorderMode); using (var project = CreateTrainedObjDetectionProject()) using (ICustomVisionTrainingClient client = BaseTests.GetTrainingClient()) { var existingImage = (await client.GetTaggedImagesAsync(project.ProjectId)).First(); Assert.NotNull(existingImage); var testTag = await client.CreateTagAsync(project.ProjectId, tagName); var proposal = await client.GetImageRegionProposalsAsync(project.ProjectId, existingImage.Id); Assert.True(proposal.Proposals.Count > 0); Assert.Equal(project.ProjectId, proposal.ProjectId); Assert.Equal(existingImage.Id, proposal.ImageId); Assert.InRange(proposal.Proposals[0].Confidence, 0, 1); var bbox = proposal.Proposals[0].BoundingBox; List <ImageRegionCreateEntry> newRegions = new List <ImageRegionCreateEntry>(); newRegions.Add(new ImageRegionCreateEntry(existingImage.Id, testTag.Id, bbox.Left, bbox.Top, bbox.Width, bbox.Height)); var regions = await client.CreateImageRegionsAsync(project.ProjectId, new ImageRegionCreateBatch(newRegions)); Assert.Equal(1, regions.Created.Count); Assert.Equal(0, regions.Duplicated.Count); Assert.Equal(0, regions.Exceeded.Count); Assert.Equal(bbox.Top, regions.Created[0].Top); Assert.Equal(bbox.Left, regions.Created[0].Left); Assert.Equal(bbox.Width, regions.Created[0].Width); Assert.Equal(bbox.Height, regions.Created[0].Height); Assert.Equal(existingImage.Id, regions.Created[0].ImageId); Assert.Equal(testTag.Id, regions.Created[0].TagId); Assert.NotEqual(Guid.Empty, regions.Created[0].RegionId); var image = await client.GetImagesByIdsAsync(project.ProjectId, new List <Guid>(new Guid[] { existingImage.Id })); Assert.Equal(1, image.Count); Assert.Equal(2, image[0].Regions.Count); await client.DeleteImageRegionsAsync(project.ProjectId, new List <Guid>(new Guid[] { regions.Created[0].RegionId })); image = await client.GetImagesByIdsAsync(project.ProjectId, new List <Guid>(new Guid[] { existingImage.Id })); Assert.Equal(1, image.Count); Assert.Equal(1, image[0].Regions.Count); await client.DeleteTagAsync(project.ProjectId, testTag.Id); } } }
public async void CreateUpdateDeleteTag() { var updatedName = "New Tag Name"; var updatedDescription = "Updated Description"; using (MockContext context = MockContext.Start(this.GetType())) { HttpMockServer.Initialize(this.GetType(), "CreateUpdateDeleteTag", RecorderMode); using (ICustomVisionTrainingClient client = GetTrainingClient()) { var projectId = (await client.CreateProjectAsync(projName)).Id; var tag = await client.CreateTagAsync(projectId, tagName, tagDescription); Assert.Equal(tagName, tag.Name); Assert.Equal(tagDescription, tag.Description); Assert.Equal(0, tag.ImageCount); Assert.NotEqual(Guid.Empty, tag.Id); var updatedTag = await client.UpdateTagAsync(projectId, tag.Id, new Tag() { Name = updatedName, Description = updatedDescription }); Assert.Equal(updatedName, updatedTag.Name); Assert.Equal(updatedDescription, updatedTag.Description); Assert.Equal(tag.ImageCount, updatedTag.ImageCount); Assert.Equal(tag.Id, updatedTag.Id); await client.DeleteTagAsync(projectId, tag.Id); await client.DeleteProjectAsync(projectId); } } }