public async void CreateImageFromUrl() { string imageUrl = "https://raw.githubusercontent.com/Microsoft/Cognitive-CustomVision-Windows/master/Samples/Images/Hemlock/hemlock_1.jpg"; using (MockContext context = MockContext.Start(this.GetType())) { HttpMockServer.Initialize(this.GetType(), "CreateImageFromUrl", RecorderMode); using (ICustomVisionTrainingClient client = GetTrainingClient()) { var newProject = client.CreateProjectAsync(projName, projDescription, ProjectBuilderHelper.FoodDomain).Result; var tag = client.CreateTagAsync(newProject.Id, tagName).Result; var urlImages = new ImageUrlCreateEntry[] { new ImageUrlCreateEntry(imageUrl) }; var tags = new Guid[] { tag.Id }; var imageCreatedFromUrl = client.CreateImagesFromUrlsAsync(newProject.Id, new ImageUrlCreateBatch(urlImages, tags)).Result; Assert.True(imageCreatedFromUrl.IsBatchSuccessful); Assert.Equal(1, imageCreatedFromUrl.Images.Count); Assert.Equal(imageUrl, imageCreatedFromUrl.Images[0].SourceUrl); Assert.Equal("OK", imageCreatedFromUrl.Images[0].Status); Assert.NotEqual(Guid.Empty, imageCreatedFromUrl.Images[0].Image.Id); Assert.NotEqual(0, imageCreatedFromUrl.Images[0].Image.Width); Assert.NotEqual(0, imageCreatedFromUrl.Images[0].Image.Height); Assert.NotEmpty(imageCreatedFromUrl.Images[0].Image.OriginalImageUri); Assert.NotEmpty(imageCreatedFromUrl.Images[0].Image.ResizedImageUri); Assert.NotEmpty(imageCreatedFromUrl.Images[0].Image.ThumbnailUri); await client.DeleteProjectAsync(newProject.Id); } } }
public async void ProjectRetrieval() { using (MockContext context = MockContext.Start(this.GetType())) { HttpMockServer.Initialize(this.GetType(), "ProjectRetrieval", RecorderMode); using (ICustomVisionTrainingClient client = GetTrainingClient()) { var newProject = await client.CreateProjectAsync(projName, projDescription, ProjectBuilderHelper.FoodDomain); var projects = await client.GetProjectsAsync(); Assert.True(projects.Count > 0); Assert.Contains(projects, p => p.Id == newProject.Id); var firstProject = await client.GetProjectAsync(projects[0].Id); Assert.Equal(projects[0].Id, firstProject.Id); Assert.Equal(projects[0].Name, firstProject.Name); Assert.Equal(projects[0].Description, firstProject.Description); Assert.Equal(projects[0].Settings.DomainId, firstProject.Settings.DomainId); Assert.Equal(projects[0].Settings.TargetExportPlatforms.Count, firstProject.Settings.TargetExportPlatforms.Count); Assert.Equal(projects[0].DrModeEnabled, firstProject.DrModeEnabled); await client.DeleteProjectAsync(newProject.Id); } } }
public async void TagRetrieval() { using (MockContext context = MockContext.Start(this.GetType())) { HttpMockServer.Initialize(this.GetType(), "TagRetrieval", RecorderMode); using (ICustomVisionTrainingClient client = GetTrainingClient()) { var newProject = await client.CreateProjectAsync("TagRetrievalTest", projDescription, ProjectBuilderHelper.GeneralDomain); var numTags = 4; for (var i = 0; i < numTags; i++) { await client.CreateTagAsync(newProject.Id, "Tag #" + i.ToString(), string.Empty); } var tagList = await client.GetTagsAsync(newProject.Id); Assert.Equal(numTags, tagList.Count); foreach (var tag in tagList) { Assert.NotEqual(Guid.Empty, tag.Id); Assert.Contains("Tag #", tag.Name); Assert.Null(tag.Description); Assert.Equal(0, tag.ImageCount); } await client.DeleteProjectAsync(newProject.Id); } } }
public async void CreateImagesFromData() { var dataFileName = "hemlock_1.jpg"; using (MockContext context = MockContext.Start(this.GetType())) { HttpMockServer.Initialize(this.GetType(), "CreateImagesFromData", RecorderMode); using (ICustomVisionTrainingClient client = GetTrainingClient()) { var newProject = client.CreateProjectAsync(projName, projDescription, ProjectBuilderHelper.FoodDomain).Result; var tag = client.CreateTagAsync(newProject.Id, tagName).Result; using (FileStream stream = new FileStream(Path.Combine("TestImages", "tag1", dataFileName), FileMode.Open)) { var imageCreatedFromData = client.CreateImagesFromDataAsync(newProject.Id, stream, new Guid[] { tag.Id }).Result; Assert.True(imageCreatedFromData.IsBatchSuccessful); Assert.Equal(1, imageCreatedFromData.Images.Count); Assert.Contains(dataFileName, imageCreatedFromData.Images[0].SourceUrl); Assert.Equal("OK", imageCreatedFromData.Images[0].Status); Assert.NotEqual(Guid.Empty, imageCreatedFromData.Images[0].Image.Id); Assert.NotEqual(0, imageCreatedFromData.Images[0].Image.Width); Assert.NotEqual(0, imageCreatedFromData.Images[0].Image.Height); Assert.NotEmpty(imageCreatedFromData.Images[0].Image.OriginalImageUri); Assert.NotEmpty(imageCreatedFromData.Images[0].Image.ResizedImageUri); Assert.NotEmpty(imageCreatedFromData.Images[0].Image.ThumbnailUri); } await client.DeleteProjectAsync(newProject.Id); } } }
public async void CreateUpdateDeleteProject() { var updatedProjName = "Another Name"; var updatedProjDescription = "Updated Project Description"; using (MockContext context = MockContext.Start(this.GetType())) { HttpMockServer.Initialize(this.GetType(), "CreateUpdateDeleteProject", RecorderMode); using (ICustomVisionTrainingClient client = GetTrainingClient()) { var newProject = client.CreateProjectAsync(projName, projDescription).Result; Assert.Contains(projName, newProject.Name); Assert.Equal(projDescription, newProject.Description); Assert.NotEqual(Guid.Empty, newProject.Id); var updatedProject = client.UpdateProjectAsync(newProject.Id, new Project() { Name = updatedProjName, Description = updatedProjDescription, }).Result; Assert.Equal(updatedProjName, updatedProject.Name); Assert.Equal(updatedProjDescription, updatedProject.Description); Assert.Equal(newProject.Id, updatedProject.Id); Assert.Equal(newProject.Settings.DomainId, updatedProject.Settings.DomainId); await client.DeleteProjectAsync(newProject.Id); } } }
public async void CreateImagesFromFiles() { var dataFileName = "hemlock_1.jpg"; using (MockContext context = MockContext.Start(this.GetType().Name)) { HttpMockServer.Initialize(this.GetType().Name, "CreateImagesFromFiles", RecorderMode); ICustomVisionTrainingClient client = GetTrainingClient(); var newProject = client.CreateProjectAsync(projName, projDescription, FoodDomain).Result; var tag = client.CreateTagAsync(newProject.Id, tagName).Result; var fileName = Path.Combine("TestImages", "tag1", dataFileName); var fileImages = new ImageFileCreateEntry[] { new ImageFileCreateEntry(dataFileName, File.ReadAllBytes(fileName)) }; var tags = new Guid[] { tag.Id }; var imageCreatedFromFile = client.CreateImagesFromFilesAsync(newProject.Id, new ImageFileCreateBatch(fileImages, tags)).Result; Assert.True(imageCreatedFromFile.IsBatchSuccessful); Assert.Equal(1, imageCreatedFromFile.Images.Count); Assert.Contains(dataFileName, imageCreatedFromFile.Images[0].SourceUrl); Assert.Equal("OK", imageCreatedFromFile.Images[0].Status); Assert.NotEqual(Guid.Empty, imageCreatedFromFile.Images[0].Image.Id); Assert.NotEqual(0, imageCreatedFromFile.Images[0].Image.Width); Assert.NotEqual(0, imageCreatedFromFile.Images[0].Image.Height); Assert.NotEmpty(imageCreatedFromFile.Images[0].Image.OriginalImageUri); Assert.NotEmpty(imageCreatedFromFile.Images[0].Image.ResizedImageUri); Assert.NotEmpty(imageCreatedFromFile.Images[0].Image.ThumbnailUri); await client.DeleteProjectAsync(newProject.Id); } }
public async void CreateDeleteProjectWithDomain() { using (MockContext context = MockContext.Start(this.GetType().Name)) { HttpMockServer.Initialize(this.GetType().Name, "CreateDeleteProjectWithDomain", RecorderMode); ICustomVisionTrainingClient client = GetTrainingClient(); var newProject = await client.CreateProjectAsync(projName, projDescription, FoodDomain); Assert.Contains(projName, newProject.Name); Assert.Equal(projDescription, newProject.Description); Assert.Equal(FoodDomain, newProject.Settings.DomainId); Assert.NotEqual(Guid.Empty, newProject.Id); await client.DeleteProjectAsync(newProject.Id); } }
public async void DeleteImages() { using (MockContext context = MockContext.Start(this.GetType().Name)) { HttpMockServer.Initialize(this.GetType().Name, "DeleteImages", RecorderMode); ICustomVisionTrainingClient client = GetTrainingClient(); var projectId = (await client.CreateProjectAsync(projName)).Id; string imageUrl = "https://raw.githubusercontent.com/Microsoft/Cognitive-CustomVision-Windows/master/Samples/Images/Test/test_image.jpg"; var urlImages = new ImageUrlCreateEntry[] { new ImageUrlCreateEntry(imageUrl) }; var result = client.CreateImagesFromUrlsAsync(projectId, new ImageUrlCreateBatch(urlImages)).Result; Assert.True(result.IsBatchSuccessful); Assert.Equal(1, result.Images.Count); await client.DeleteImagesAsync(projectId, new string[] { result.Images[0].Image.Id.ToString() }); await client.DeleteProjectAsync(projectId); } }
public async void CreateUpdateDeleteProject() { var updatedProjName = "Another Name"; var updatedProjDescription = "Updated Project Description"; using (MockContext context = MockContext.Start(this.GetType())) { HttpMockServer.Initialize(this.GetType(), "CreateUpdateDeleteProject", RecorderMode); using (ICustomVisionTrainingClient client = GetTrainingClient()) { var newProject = client.CreateProjectAsync(projName, projDescription).Result; Assert.Contains(projName, newProject.Name); Assert.Equal(projDescription, newProject.Description); Assert.NotEqual(Guid.Empty, newProject.Id); Assert.False(newProject.DrModeEnabled); Assert.NotNull(newProject.Settings); Assert.True(newProject.Settings.UseNegativeSet); Assert.Null(newProject.Settings.DetectionParameters); Assert.NotEqual(Guid.Empty, newProject.Settings.DomainId); Assert.NotNull(newProject.Settings.ImageProcessingSettings); Assert.Equal(Classifier.Multilabel, newProject.Settings.ClassificationType); var updatedProject = client.UpdateProjectAsync(newProject.Id, new Project() { Name = updatedProjName, Description = updatedProjDescription, }).Result; Assert.Equal(updatedProjName, updatedProject.Name); Assert.Equal(updatedProjDescription, updatedProject.Description); Assert.Equal(newProject.Id, updatedProject.Id); Assert.Equal(newProject.Settings.DomainId, updatedProject.Settings.DomainId); await client.DeleteProjectAsync(newProject.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); } } }