private async void ImageButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                await ImageSearchService.SearchForImageAsync();

                await PictureService.MapFaceOnImageAsync();
            } catch (Exception ex)
            {
                StatusMessage.Text = ex.Message;
                try
                {
                    await ImageSearchService.SearchForImageAsync();

                    await PictureService.MapFaceOnImageAsync();
                }
                catch (Exception ex1)
                {
                    StatusMessage.Text = ex1.Message;
                    try
                    {
                        await ImageSearchService.SearchForImageAsync();

                        await PictureService.MapFaceOnImageAsync();
                    }
                    catch (Exception ex2)
                    {
                        StatusMessage.Text = ex2.Message;
                    }
                }
            }
        }
        public async Task FindImageUrl_ReturnsNull()
        {
            // arrange
            Environment.SetEnvironmentVariable("CognitiveServicesSearchApiEndpoint", "https://fake/");
            Environment.SetEnvironmentVariable("CognitiveServicesSearchApiKey", "tempkey");
            var service = new ImageSearchService(new Random(), new HttpClient(new MockHttpMessageHandler(GetFileResourceString("0.json"))));

            // act
            var result = await service.FindImageUrlAsync("searchterm");

            // assert
            Assert.Null(result);
        }
        public async Task FindImageUrl_ReturnsExpectedUrl()
        {
            // arrange
            Environment.SetEnvironmentVariable("CognitiveServicesSearchApiEndpoint", "https://fake/");
            Environment.SetEnvironmentVariable("CognitiveServicesSearchApiKey", "tempkey");
            var service = new ImageSearchService(new Random(), new HttpClient(new MockHttpMessageHandler(GetFileResourceString("1.json"))));

            // act
            var result = await service.FindImageUrlAsync("searchterm");

            // assert
            Assert.Equal("http://images2.fanpop.com/image/photos/9400000/Funny-Cats-cats-9473312-1600-1200.jpg", result);
        }
Exemple #4
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "searchunsplash")] HttpRequest req,
            ILogger log)
        {
            log.LogInformation($"C# HTTP trigger function processed a requestto search Unsplash for {req.Query["query"]}.");

            _imageSearchService = new ImageSearchService(Environment.GetEnvironmentVariable("UNSPLASH_ACCESS_KEY"), Environment.GetEnvironmentVariable("UNSPLASH_SECRET_KEY"));

            var image = await _imageSearchService.GetImageAsync(req.Query["query"]);

            return(image != null
                ? (ActionResult) new OkObjectResult(JsonConvert.SerializeObject(image))
                : new BadRequestObjectResult("Please pass a name on the query string"));
        }
 public ImageFieldController()
 {
     _factory       = new ImageAssetFactory();
     _searchService = new ImageSearchService("my_image_index");
 }