public static async Task TestVisionThumbnailWithImageWithResize()
        {
            ICognitiveServicesClient client = new TestCognitiveServicesClient();

            await TestHelper.ExecuteFunction <VisionFunctions, VisionThumbnailBinding>(client, "VisionFunctions.VisionThumbnailWithTooBigImageBytesWithResize");

            Assert.Equal(MockResults.SamplePhoto.Length, visionThumbnailResult.Length);
        }
        public static async Task TestVisionThumbnailMissingFile()
        {
            ICognitiveServicesClient client = new TestCognitiveServicesClient();

            var exception = await Record.ExceptionAsync(() => TestHelper.ExecuteFunction <VisionFunctions, VisionThumbnailBinding>
                                                            (client, "VisionFunctions.VisionThumbnailMissingFile"));

            exception.Should().NotBeNull();
            exception.InnerException.Should().NotBeNull();
            exception.InnerException.Should().BeOfType <ArgumentException>();
            exception.InnerException.Message.Should().Contain(VisionExceptionMessages.FileMissing);
        }
        public static async Task TestVisionDescribeWithImageWithResize()
        {
            ICognitiveServicesClient client = new TestCognitiveServicesClient();
            var mockResult = JsonConvert.DeserializeObject <VisionDescribeModel>(MockResults.VisionDescribeResults);

            await TestHelper.ExecuteFunction <VisionFunctions, VisionDescribeBinding>(client, "VisionFunctions.VisionDescribeWithTooBigImageBytesWithResize");

            var expectedResult = JsonConvert.SerializeObject(mockResult);
            var actualResult   = JsonConvert.SerializeObject(visionDescribeImageBytesResizeResult);

            Assert.Equal(expectedResult, actualResult);
        }
        public static async Task TestVisionAnalysisWithUrl()
        {
            ICognitiveServicesClient client = new TestCognitiveServicesClient();
            var mockResult = JsonConvert.DeserializeObject <VisionAnalysisModel>(MockResults.VisionAnalysisResults);

            await TestHelper.ExecuteFunction <VisionFunctions, VisionAnalysisBinding>(client, "VisionFunctions.VisionAnalysisWithUrl");

            var expectedResult = JsonConvert.SerializeObject(mockResult);
            var actualResult   = JsonConvert.SerializeObject(visionAnalysisUrlResult);

            Assert.Equal(expectedResult, actualResult);
        }
        public static async Task TestVisionThumbnailImageBytesTooLarge()
        {
            ICognitiveServicesClient client = new TestCognitiveServicesClient();

            string exceptionMessage = "or smaller for the cognitive service vision API";

            var exception = await Record.ExceptionAsync(() => TestHelper.ExecuteFunction <VisionFunctions, VisionThumbnailBinding>
                                                            (client, "VisionFunctions.VisionThumbnailWithTooBigImageBytes"));

            exception.Should().NotBeNull();
            exception.InnerException.Should().NotBeNull();
            exception.InnerException.Should().BeOfType <ArgumentException>();
            exception.InnerException.Message.Should().Contain(exceptionMessage);
        }
Esempio n. 6
0
        private static async Task RunTestAsync(string testName, object argument = null)
        {
            Type           testType      = typeof(VisionFunctions);
            var            locator       = new ExplicitTypeLocator(testType);
            ILoggerFactory loggerFactory = new LoggerFactory();

            loggerFactory.AddProvider(_loggerProvider);
            ICognitiveServicesClient testCognitiveServicesClient = new TestCognitiveServicesClient();

            var arguments = new Dictionary <string, object>();
            var resolver  = new TestNameResolver();

            IHost host = new HostBuilder()
                         .ConfigureWebJobs(builder =>
            {
                builder.AddVisionDescribe();
            })
                         .ConfigureServices(services =>
            {
                services.AddSingleton <ICognitiveServicesClient>(testCognitiveServicesClient);
                services.AddSingleton <INameResolver>(resolver);
                services.AddSingleton <ITypeLocator>(locator);
            })
                         .ConfigureLogging(logging =>
            {
                logging.ClearProviders();
                logging.AddProvider(_loggerProvider);
            })
                         .ConfigureAppConfiguration(c =>
            {
                c.Sources.Clear();

                var collection = new Dictionary <string, string>
                {
                    { "VisionKey", "1234XYZ" },
                    { "VisionUrl", "http://url" }
                };

                c.AddInMemoryCollection(collection);
            })
                         .Build();

            var method = testType.GetMethod(testName);

            await host.GetJobHost().CallAsync(method, arguments);
        }