@@ -34,19 +34,15 @@ public class VisualRecognitionServiceIntegrationTests
3434 private string _imageUrl = "https://upload.wikimedia.org/wikipedia/commons/thumb/b/bb/Kittyply_edit1.jpg/1200px-Kittyply_edit1.jpg" ;
3535 private string _faceUrl = "https://upload.wikimedia.org/wikipedia/commons/thumb/8/8d/President_Barack_Obama.jpg/220px-President_Barack_Obama.jpg" ;
3636 private string _localGiraffeFilePath = @"VisualRecognitionTestData\giraffe_to_classify.jpg" ;
37- //private string _localImageMetadataPath = @"VisualRecognitionTestData\imageMetadata.json";
3837 private string _localFaceFilePath = @"VisualRecognitionTestData\obama.jpg" ;
39- // private string _localTurtleFilePath = @"VisualRecognitionTestData\turtle_to_classify.jpg";
38+ private string _localTurtleFilePath = @"VisualRecognitionTestData\turtle_to_classify.jpg" ;
4039 private string _localGiraffePositiveExamplesFilePath = @"VisualRecognitionTestData\giraffe_positive_examples.zip" ;
4140 private string _giraffeClassname = "giraffe" ;
4241 private string _localTurtlePositiveExamplesFilePath = @"VisualRecognitionTestData\turtle_positive_examples.zip" ;
4342 private string _turtleClassname = "turtle" ;
4443 private string _localNegativeExamplesFilePath = @"VisualRecognitionTestData\negative_examples.zip" ;
4544 private string _createdClassifierName = "dotnet-standard-test-classifier" ;
4645 private static string _createdClassifierId = "" ;
47- //private string _collectionNameToCreate = "dotnet-standard-test-collection";
48- //private static string _createdCollectionId = "";
49- //private static string _addedImageId = "";
5046 AutoResetEvent autoEvent = new AutoResetEvent ( false ) ;
5147
5248 [ TestInitialize ]
@@ -192,197 +188,46 @@ public void t08_UpdateClassifier_Success()
192188 }
193189 }
194190
195- //[TestMethod]
196- //public void t09_GetCollections_Success()
197- //{
198- // VisualRecognitionService service = new VisualRecognitionService();
199- // service.SetCredential(apikey);
200-
201- // var result = service.GetCollections();
202-
203- // Assert.IsNotNull(result);
204- //}
205-
206- //[TestMethod]
207- //public void t10_CreateCollection_Success()
208- //{
209- // DeleteDotnetCollections();
210-
211- // VisualRecognitionService service = new VisualRecognitionService();
212- // service.SetCredential(apikey);
213-
214- // var result = service.CreateCollection(_collectionNameToCreate);
215-
216- // _createdCollectionId = result.CollectionId;
217- // Console.WriteLine(string.Format("Created collection {0}", _createdCollectionId));
218-
219- // Assert.IsNotNull(result);
220- // Assert.IsTrue(!string.IsNullOrEmpty(_createdCollectionId));
221- //}
222-
223- //[TestMethod]
224- //public void t11_GetCollection_Success()
225- //{
226- // if (string.IsNullOrEmpty(_createdCollectionId))
227- // Assert.Fail("Created collection ID is null or empty.");
228-
229- // VisualRecognitionService service = new VisualRecognitionService();
230- // service.SetCredential(apikey);
231-
232- // var result = service.GetCollection(_createdCollectionId);
233-
234- // Assert.IsNotNull(result);
235- // Assert.IsTrue(result.CollectionId == _createdCollectionId);
236- //}
237-
238- //[TestMethod]
239- //public void t12_GetCollectionImages_Success()
240- //{
241- // if (string.IsNullOrEmpty(_createdCollectionId))
242- // Assert.Fail("Created collection ID is null or empty.");
243-
244- // VisualRecognitionService service = new VisualRecognitionService();
245- // service.SetCredential(apikey);
246-
247- // var result = service.GetCollectionImages(_createdCollectionId);
248-
249- // Assert.IsNotNull(result);
250- //}
251-
252- //[TestMethod]
253- //public void t13_AddCollectionImages_Success()
254- //{
255- // VisualRecognitionService service = new VisualRecognitionService();
256- // service.SetCredential(apikey);
257-
258- // using (FileStream imageStream = File.OpenRead(_localGiraffeFilePath), metadataStream = File.OpenRead(_localImageMetadataPath))
259- // {
260- // var result = service.AddImage(_createdCollectionId, imageStream.ReadAllBytes(), Path.GetFileName(_localGiraffeFilePath), metadataStream.ReadAllBytes());
261-
262- // _addedImageId = result.Images[0].ImageId;
263- // Console.WriteLine(string.Format("Added image {0}", _addedImageId));
264-
265- // Assert.IsNotNull(result);
266- // Assert.IsTrue(result.ImagesProcessed > 0);
267- // Assert.IsTrue(!string.IsNullOrEmpty(_addedImageId));
268- // }
269- //}
270-
271- //[TestMethod]
272- //public void t14_GetCollectionImage_Success()
273- //{
274- // if (string.IsNullOrEmpty(_createdCollectionId))
275- // Assert.Fail("Created collection ID is null or empty.");
276-
277- // if (string.IsNullOrEmpty(_addedImageId))
278- // Assert.Fail("Added image ID is null or empty.");
279-
280- // VisualRecognitionService service = new VisualRecognitionService();
281- // service.SetCredential(apikey);
282-
283- // var result = service.GetImage(_createdCollectionId, _addedImageId);
284-
285- // Assert.IsNotNull(result);
286- // Assert.IsTrue(result.ImageId == _addedImageId);
287- //}
288-
289- //[TestMethod]
290- //public void t15_GetCollectionImageMetadata_Success()
291- //{
292- // if (string.IsNullOrEmpty(_createdCollectionId))
293- // Assert.Fail("Created collection ID is null or empty.");
294-
295- // if (string.IsNullOrEmpty(_addedImageId))
296- // Assert.Fail("Added image ID is null or empty.");
297-
298- // VisualRecognitionService service = new VisualRecognitionService();
299- // service.SetCredential(apikey);
300-
301- // var result = service.GetMetadata(_createdCollectionId, _addedImageId);
302-
303- // Assert.IsNotNull(result);
304- //}
305-
306- //[TestMethod]
307- //public void t16_AddCollectionImageMetadata_Success()
308- //{
309- // if (string.IsNullOrEmpty(_createdCollectionId))
310- // Assert.Fail("Created collection ID is null or empty.");
311-
312- // if (string.IsNullOrEmpty(_addedImageId))
313- // Assert.Fail("Added image ID is null or empty.");
314-
315- // VisualRecognitionService service = new VisualRecognitionService();
316- // service.SetCredential(apikey);
317-
318- // using (FileStream metadataStream = File.OpenRead(_localImageMetadataPath))
319- // {
320- // var result = service.AddImageMetadata(_createdCollectionId, _addedImageId, metadataStream.ReadAllBytes());
321-
322- // Assert.IsNotNull(result);
323- // Assert.IsTrue(result.Count > 0);
324- // }
325- //}
326-
327- //[TestMethod]
328- //public void t17_DeleteCollectionImageMetadata_Success()
329- //{
330- // VisualRecognitionService service = new VisualRecognitionService();
331- // service.SetCredential(apikey);
332-
333- // var result = service.DeleteImageMetadata(_createdCollectionId, _addedImageId);
334-
335- // Assert.IsNotNull(result);
336- //}
337-
338- //[TestMethod]
339- //public void t18_FindSimilar_Success()
340- //{
341- // VisualRecognitionService service = new VisualRecognitionService();
342- // service.SetCredential(apikey);
343-
344- // using (FileStream imageStream = File.OpenRead(_localTurtleFilePath))
345- // {
346- // var result = service.FindSimilar(_createdCollectionId, imageStream.ReadAllBytes(), Path.GetFileName(_localGiraffeFilePath));
347-
348- // Assert.IsNotNull(result);
349- // Assert.IsTrue(result.ImagesProcessed > 0);
350- // }
351- //}
352-
353- //[TestMethod]
354- //public void t19_DeleteCollectionImage_Success()
355- //{
356- // if (string.IsNullOrEmpty(_createdCollectionId))
357- // Assert.Fail("Created collection ID is null or empty.");
358-
359- // if (string.IsNullOrEmpty(_addedImageId))
360- // Assert.Fail("Added image ID is null or empty.");
361-
362- // VisualRecognitionService service = new VisualRecognitionService();
363- // service.SetCredential(apikey);
364-
365- // var result = service.DeleteImage(_createdCollectionId, _addedImageId);
366-
367- // Assert.IsNotNull(result);
368- //}
191+ [ TestMethod ]
192+ public void t09_WaitForClassifier ( )
193+ {
194+ IsClassifierReady ( _createdClassifierId ) ;
195+ autoEvent . WaitOne ( ) ;
369196
370- //[TestMethod]
371- //public void t20_DeleteCollection_Success()
372- //{
373- // if (string.IsNullOrEmpty(_createdCollectionId))
374- // Assert.Fail("Created collection ID is null or empty.");
197+ Assert . IsTrue ( true ) ;
198+ }
375199
376- // VisualRecognitionService service = new VisualRecognitionService();
377- // service.SetCredential(apikey);
200+ [ TestMethod ]
201+ public void t10_ClassifyPost_Success ( )
202+ {
203+ VisualRecognitionService service = new VisualRecognitionService ( ) ;
204+ service . SetCredential ( apikey ) ;
205+ string [ ] classifierIDs = { _createdClassifierId } ;
378206
379- // var result = service.DeleteCollection(_createdCollectionId);
207+ using ( FileStream fs = File . OpenRead ( _localTurtleFilePath ) )
208+ {
209+ var result = service . Classify ( ( fs as Stream ) . ReadAllBytes ( ) , Path . GetFileName ( _localTurtleFilePath ) , "image/jpeg" , classifierIDs : classifierIDs ) ;
380210
381- // Assert.IsNotNull(result);
382- //}
211+ Assert . IsNotNull ( result ) ;
212+ Assert . IsNotNull ( result . Images ) ;
213+ Assert . IsTrue ( result . CustomClasses > 0 ) ;
214+ float giraffeScore = 0 ;
215+ float turtleScore = 0 ;
216+ List < ClassResult > classResults = result . Images [ 0 ] ? . _Classifiers [ 0 ] ? . Classes ;
217+ foreach ( ClassResult classResult in classResults )
218+ {
219+ if ( classResult . _Class == _giraffeClassname )
220+ giraffeScore = classResult . Score ;
221+ if ( classResult . _Class == _turtleClassname )
222+ turtleScore = classResult . Score ;
223+ }
224+ Assert . IsTrue ( giraffeScore < turtleScore ) ;
225+ Assert . IsTrue ( result . Images . Count > 0 ) ;
226+ }
227+ }
383228
384229 [ TestMethod ]
385- public void t21_DeleteClassifier_Success ( )
230+ public void t11_DeleteClassifier_Success ( )
386231 {
387232 if ( string . IsNullOrEmpty ( _createdClassifierId ) )
388233 Assert . Fail ( "Created classsifier ID is null or empty." ) ;
@@ -423,31 +268,6 @@ private bool IsClassifierReady(string classifierId)
423268 return result . Status . ToLower ( ) == "ready" ;
424269 }
425270
426- //private void DeleteDotnetCollections()
427- //{
428- // VisualRecognitionService service = new VisualRecognitionService();
429- // service.SetCredential(apikey);
430-
431- // List<string> collectionIdsToDelete = new List<string>();
432-
433- // var collections = service.GetCollections();
434-
435- // foreach (CreateCollection collection in collections.Collections)
436- // {
437- // string name = collection.Name;
438- // string id = collection.CollectionId;
439-
440- // if (name == _collectionNameToCreate)
441- // collectionIdsToDelete.Add(id);
442- // }
443-
444- // if (collectionIdsToDelete.Count > 0)
445- // {
446- // foreach (string collectionIdToDelete in collectionIdsToDelete)
447- // service.DeleteCollection(collectionIdToDelete);
448- // }
449- //}
450-
451271 private bool ContainsClass ( GetClassifiersPerClassifierVerbose result , string classname )
452272 {
453273 bool containsClass = false ;
0 commit comments