public async Task FacePlusPlusDetect_Success() { var client = new FacePlusPlusClient(new FacePlusPlusClientOptions { ApiKey = Defaults.API_KEY, ApiSecret = Defaults.API_SECRET }); var result = await client.GetEmotionsForPhotoAsync(PHOTO_URL); Assert.Null(result.ErrorMessage); Assert.NotNull(result.Emotions); Assert.Single(result.Emotions); }
public async Task FacePlusPlusDetect_Fail() { var client = new FacePlusPlusClient(new FacePlusPlusClientOptions { ApiKey = Defaults.API_KEY, // incorrect api_secret ApiSecret = "qffKT2SzsLtRJqwGHopiAqvUhoR3b44F" }); var result = await client.GetEmotionsForPhotoAsync(PHOTO_URL); Assert.NotNull(result.ErrorMessage); Assert.Null(result.Emotions); }
internal static async Task Main(string[] args) { FlickrPhotosetsGetPhotosResult flickrResult; using (var flickrClient = new FlickrClient(_flickrClientOptions)) flickrResult = await flickrClient.GetPhotosAsync(); if (!flickrResult.IsOk) { Error("An error occurred while getting the list of photos from Flickr API"); Error(flickrResult.ErrorMessage); return; } Info("Successfully received the list of photos from Flickr API"); Info($"Count of photos: {flickrResult.Photos.Count}"); if (flickrResult.Photos.Count == 0) { Error("List of photos is empty"); return; } var context = new MongoDbContext("mongodb://localhost"); var i = 0; using (var faceClient = new FacePlusPlusClient(_faceClientOptions)) foreach (var photo in flickrResult.Photos) { Console.Write("Processing - " + ++i); if (await context.Photos.Find(p => p.Name == photo.Title).AnyAsync()) { Info(" '" + photo.Title + " already Exist'"); continue; } var faceResult = await faceClient.GetEmotionsForPhotoAsync(photo.Photo('c')); if (!faceResult.IsOk) { Error($"Error occurred while processing photo named {photo.Title}"); Error(faceResult.ErrorMessage); return; } var emotions = new List <Emotion>(); foreach (var emotion in faceResult.Emotions) { emotions.Add(new Emotion { Fear = emotion.Fear, Anger = emotion.Anger, Disgust = emotion.Disgust, Neutral = emotion.Neutral, Sadness = emotion.Sadness, Surprise = emotion.Surprise, Happiness = emotion.Happiness }); } await context.Photos.InsertOneAsync(new DBPhotoModel { Name = photo.Title, Url = photo.Photo(), Emotions = emotions }); Info(" '" + photo.Title + " Added'"); } Console.ForegroundColor = ConsoleColor.Green; Info("All data ready! :)"); Console.ForegroundColor = ConsoleColor.Gray; }