private async Task RunTimerJobTest(Type jobClassType, Func <bool> condition)
        {
            ExplicitTypeLocator  locator = new ExplicitTypeLocator(jobClassType);
            JobHostConfiguration config  = new JobHostConfiguration
            {
                TypeLocator = locator
            };

            ILoggerFactory     loggerFactory = new LoggerFactory();
            TestLoggerProvider provider      = new TestLoggerProvider();

            loggerFactory.AddProvider(provider);

            config.LoggerFactory = loggerFactory;

            config.AddService <IWebJobsExceptionHandler>(new TestExceptionHandler());
            config.UseTimers();

            JobHost host = new JobHost(config);

            await host.StartAsync();

            await TestHelpers.Await(() =>
            {
                return(condition());
            });

            await host.StopAsync();

            // TODO: ensure there were no errors
        }
Пример #2
0
        private async Task IndexBindings(Type testType, bool includeDefaultUri = true)
        {
            // Just start the jobhost -- this should fail if function indexing fails.

            ExplicitTypeLocator locator = new ExplicitTypeLocator(testType);
            var nameResolver            = new TestNameResolver();

            if (includeDefaultUri)
            {
                nameResolver.Values.Add(MobileAppsConfiguration.AzureWebJobsMobileAppUriName, "https://default");
            }
            JobHostConfiguration config = new JobHostConfiguration
            {
                NameResolver = nameResolver,
                TypeLocator  = locator,
            };

            config.UseMobileApps();

            JobHost host = new JobHost(config);

            await host.StartAsync();

            await host.StopAsync();
        }
        private async Task <IHost> StartHostAsync(Type testType)
        {
            ExplicitTypeLocator locator = new ExplicitTypeLocator(testType);

            IHost host = new HostBuilder()
                         .ConfigureWebJobs(builder =>
            {
                builder
                .AddAzureStorage()
                .AddCosmosDB();
            })
                         .ConfigureAppConfiguration(c =>
            {
                c.AddTestSettings();
            })
                         .ConfigureServices(services =>
            {
                services.AddSingleton <ITypeLocator>(locator);
            })
                         .ConfigureLogging(logging =>
            {
                logging.ClearProviders();
                logging.AddProvider(_loggerProvider);
            })
                         .Build();

            await host.StartAsync();

            return(host);
        }
        private async Task RunTimerJobTest(Type jobClassType, Func <bool> condition)
        {
            TestTraceWriter      testTrace = new TestTraceWriter(TraceLevel.Error);
            ExplicitTypeLocator  locator   = new ExplicitTypeLocator(jobClassType);
            JobHostConfiguration config    = new JobHostConfiguration
            {
                TypeLocator = locator
            };

            config.UseTimers();
            config.Tracing.Tracers.Add(testTrace);
            JobHost host = new JobHost(config);

            host.Start();

            await TestHelpers.Await(() =>
            {
                return(condition());
            });

            host.Stop();

            // ensure there were no errors
            Assert.Equal(0, testTrace.Events.Count);
        }
Пример #5
0
        private void RunTest(string testName, IMobileServiceClientFactory factory, TraceWriter testTrace, object argument = null)
        {
            Type testType = typeof(MobileTableEndToEndFunctions);
            ExplicitTypeLocator  locator = new ExplicitTypeLocator(testType);
            JobHostConfiguration config  = new JobHostConfiguration
            {
                TypeLocator = locator,
            };

            config.Tracing.Tracers.Add(testTrace);

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

            arguments.Add("triggerData", argument);

            var mobileAppsConfig = new MobileAppsConfiguration
            {
                MobileAppUri  = new Uri("https://someuri"),
                ApiKey        = "api_key",
                ClientFactory = factory
            };

            var resolver = new TestNameResolver();

            config.NameResolver = resolver;

            config.UseMobileApps(mobileAppsConfig);

            JobHost host = new JobHost(config);

            host.Start();
            host.Call(testType.GetMethod(testName), arguments);
            host.Stop();
        }
        private async Task IndexBindings(Type testType, bool includeDefaultUri = true)
        {
            // Just start the host -- this should fail if function indexing fails.
            ExplicitTypeLocator locator = new ExplicitTypeLocator(testType);
            var resolver = new TestNameResolver();

            if (includeDefaultUri)
            {
                resolver.Values.Add(MobileAppsExtensionConfigProvider.AzureWebJobsMobileAppUriName, "https://default");
            }

            IHost host = new HostBuilder()
                         .ConfigureWebJobs(builder =>
            {
                builder.AddMobileApps();
            })
                         .ConfigureServices(services =>
            {
                services.AddSingleton <INameResolver>(resolver);
                services.AddSingleton <ITypeLocator>(locator);
            })
                         .ConfigureLogging(logging =>
            {
                logging.ClearProviders();
                logging.AddProvider(_loggerProvider);
            })
                         .Build();

            await host.StartAsync();

            await host.StopAsync();
        }
Пример #7
0
        private async Task RunTestAsync(string testName, ISendGridClientFactory factory, object argument = null, string configApiKey = null, bool includeDefaultApiKey = true)
        {
            Type           testType      = typeof(SendGridEndToEndFunctions);
            var            locator       = new ExplicitTypeLocator(testType);
            ILoggerFactory loggerFactory = new LoggerFactory();

            loggerFactory.AddProvider(_loggerProvider);

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

            arguments.Add("triggerData", argument);

            var resolver = new TestNameResolver();

            IHost host = new HostBuilder()
                         .ConfigureWebJobs(builder =>
            {
                builder.AddSendGrid(o =>
                {
                    if (configApiKey != null)
                    {
                        o.ApiKey = configApiKey;
                    }

                    o.ToAddress   = new EmailAddress("*****@*****.**");
                    o.FromAddress = new EmailAddress("*****@*****.**");
                });
            })
                         .ConfigureServices(services =>
            {
                services.AddSingleton <ISendGridClientFactory>(factory);
                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>
                {
                    { "MyKey1", AttributeApiKey1 },
                    { "MyKey2", AttributeApiKey2 }
                };

                if (includeDefaultApiKey)
                {
                    collection.Add(SendGridExtensionConfigProvider.AzureWebJobsSendGridApiKeyName, DefaultApiKey);
                }

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

            await host.GetJobHost().CallAsync(testType.GetMethod(testName), arguments);
        }
Пример #8
0
        private async Task RunTestAsync(Type testType, string testName, ICosmosDBServiceFactory factory, object argument = null, string configConnectionString = ConfigConnStr, bool includeDefaultConnectionString = true)
        {
            ExplicitTypeLocator locator = new ExplicitTypeLocator(testType);

            var arguments = new Dictionary <string, object>
            {
                { "triggerData", argument }
            };

            var resolver = new TestNameResolver();

            resolver.Values.Add("Database", "ResolvedDatabase");
            resolver.Values.Add("Collection", "ResolvedCollection");
            resolver.Values.Add("Query", "ResolvedQuery");

            IHost host = new HostBuilder()
                         .ConfigureWebJobs(builder =>
            {
                builder.AddAzureStorage()
                .AddCosmosDB();
            })
                         .ConfigureAppConfiguration(c =>
            {
                c.Sources.Clear();
                if (includeDefaultConnectionString)
                {
                    c.AddInMemoryCollection(new Dictionary <string, string>
                    {
                        { $"ConnectionStrings:{Constants.DefaultConnectionStringName}", DefaultConnStr },
                        { ConnectionStringNames.Storage, "UseDevelopmentStorage=true" },
                        { "MyConnectionString", AttributeConnStr }
                    });
                }
            })
                         .ConfigureServices(services =>
            {
                services.AddSingleton <ICosmosDBServiceFactory>(factory);
                services.AddSingleton <INameResolver>(resolver);
                services.AddSingleton <ITypeLocator>(locator);

                if (configConnectionString != null)
                {
                    services.Configure <CosmosDBOptions>(o => o.ConnectionString = configConnectionString);
                }
            })
                         .ConfigureLogging(logging =>
            {
                logging.ClearProviders();
                logging.AddProvider(_loggerProvider);
            })
                         .Build();

            await host.StartAsync();

            await host.GetJobHost().CallAsync(testType.GetMethod(testName), arguments);

            await host.StopAsync();
        }
Пример #9
0
        public ApiHubTestFixture()
        {
            // The default ConnectionLimit which is 2 needs to be increased for ApiHub file tests as there are many triggers calling to the same end point.
            ServicePointManager.DefaultConnectionLimit = 30;

            if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("AzureWebJobsDropBox")))
            {
                ApiHubConnectionString = Environment.GetEnvironmentVariable("AzureWebJobsDropBox");
            }
            else
            {
                ApiHubConnectionString = "UseLocalFileSystem=true;Path=" + Path.GetTempPath() + "ApiHubDropBox";
            }

            ExplicitTypeLocator locator = new ExplicitTypeLocator(typeof(ApiHubFileTestJobs));

            // Use MachineName as the host Id
            var machineName = Environment.MachineName.ToLower(CultureInfo.InvariantCulture);

            if (machineName.Length > 30)
            {
                machineName = machineName.Substring(0, 30);
            }

            Config = new JobHostConfiguration
            {
                TypeLocator = locator,
                HostId      = machineName,
            };

            RootFolder = ItemFactory.Parse(ApiHubConnectionString);

            CloudStorageAccount account    = CloudStorageAccount.Parse(Config.StorageConnectionString);
            CloudBlobClient     blobClient = account.CreateCloudBlobClient();

            string apiHubBlobDirectoryPath = string.Format(ApiHubBlobDirectoryPathTemplate, Config.HostId);

            ApiHubBlobDirectory = blobClient.GetContainerReference(HostContainerName).GetDirectoryReference(apiHubBlobDirectoryPath);
            CloudQueueClient queueClient = CloudStorageAccount.Parse(this.Config.StorageConnectionString).CreateCloudQueueClient();

            this.PoisonQueue = queueClient.GetQueueReference(PoisonQueueName);
            this.PoisonQueue.CreateIfNotExists();

            CreateFolder(ImportTestPath).Wait();
            CreateFolder(ExceptionPath).Wait();
            CreateFolder(PathsTestPath).Wait();

            DeleteExistingArtifcats();

            this.Serializer = JsonSerializer.Create();

            this.TraceWriter = new TestTraceWriter(System.Diagnostics.TraceLevel.Verbose);
            Config.Tracing.Tracers.Add(this.TraceWriter);
        }
        private async Task RunTestAsync(string testName, IMobileServiceClientFactory factory, object argument = null,
                                        Uri configUri = null, string configKey = null, bool includeDefaultKey = true, bool includeDefaultUri = true, Type testType = null)
        {
            testType = testType ?? typeof(MobileTableEndToEndFunctions);
            ExplicitTypeLocator locator = new ExplicitTypeLocator(testType);

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

            arguments.Add("triggerData", argument);

            var resolver = new TestNameResolver();

            resolver.Values.Add("MyUri", AttributeUri);
            resolver.Values.Add("MyKey", AttributeKey);
            if (includeDefaultUri)
            {
                resolver.Values.Add(MobileAppsExtensionConfigProvider.AzureWebJobsMobileAppUriName, DefaultUri);
            }
            if (includeDefaultKey)
            {
                resolver.Values.Add(MobileAppsExtensionConfigProvider.AzureWebJobsMobileAppApiKeyName, DefaultKey);
            }

            IHost host = new HostBuilder()
                         .ConfigureWebJobs(builder =>
            {
                builder.AddAzureStorage()
                .AddMobileApps(o =>
                {
                    o.MobileAppUri = configUri;
                    o.ApiKey       = configKey;
                });
            })
                         .ConfigureServices(services =>
            {
                services.AddSingleton <IMobileServiceClientFactory>(factory);
                services.AddSingleton <INameResolver>(resolver);
                services.AddSingleton <ITypeLocator>(locator);
            })
                         .ConfigureLogging(logging =>
            {
                logging.ClearProviders();
                logging.AddProvider(_loggerProvider);
            })
                         .Build();

            await host.StartAsync();

            await host.GetJobHost().CallAsync(testType.GetMethod(testName), arguments);

            await host.StopAsync();
        }
        public static ITypeLocator GetTypeLocator()
        {
            var types = new Type[]
            {
                typeof(TestOrchestrations),
                typeof(TestActivities),
                typeof(ClientFunctions),
            };

            ITypeLocator typeLocator = new ExplicitTypeLocator(types);

            return(typeLocator);
        }
Пример #12
0
        private async Task RunTestAsync(string testName, ISendGridClientFactory factory, object argument = null, string configApiKey = null, bool includeDefaultApiKey = true)
        {
            Type testType = typeof(SendGridEndToEndFunctions);
            ExplicitTypeLocator  locator = new ExplicitTypeLocator(testType);
            JobHostConfiguration config  = new JobHostConfiguration
            {
                TypeLocator = locator,
            };

            ILoggerFactory loggerFactory = new LoggerFactory();

            loggerFactory.AddProvider(_loggerProvider);

            config.LoggerFactory = loggerFactory;

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

            arguments.Add("triggerData", argument);

            var sendGridConfig = new SendGridConfiguration
            {
                ApiKey        = configApiKey,
                ClientFactory = factory,
                ToAddress     = new EmailAddress("*****@*****.**"),
                FromAddress   = new EmailAddress("*****@*****.**")
            };

            var resolver = new TestNameResolver();

            resolver.Values.Add("MyKey1", AttributeApiKey1);
            resolver.Values.Add("MyKey2", AttributeApiKey2);

            if (includeDefaultApiKey)
            {
                resolver.Values.Add(SendGridConfiguration.AzureWebJobsSendGridApiKeyName, DefaultApiKey);
            }

            config.NameResolver = resolver;

            config.UseSendGrid(sendGridConfig);

            JobHost host = new JobHost(config);

            await host.StartAsync();

            await host.CallAsync(testType.GetMethod(testName), arguments);

            await host.StopAsync();
        }
        private async Task RunTestAsync(string testName, IMobileServiceClientFactory factory, TraceWriter testTrace, object argument = null,
                                        Uri configUri = null, string configKey = null, bool includeDefaultKey = true, bool includeDefaultUri = true)
        {
            Type testType = typeof(MobileTableEndToEndFunctions);
            ExplicitTypeLocator  locator = new ExplicitTypeLocator(testType);
            JobHostConfiguration config  = new JobHostConfiguration
            {
                TypeLocator = locator,
            };

            config.Tracing.Tracers.Add(testTrace);

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

            arguments.Add("triggerData", argument);

            var mobileAppsConfig = new MobileAppsConfiguration
            {
                MobileAppUri  = configUri,
                ApiKey        = configKey,
                ClientFactory = factory
            };

            var resolver = new TestNameResolver();

            resolver.Values.Add("MyUri", AttributeUri);
            resolver.Values.Add("MyKey", AttributeKey);
            if (includeDefaultUri)
            {
                resolver.Values.Add(MobileAppsConfiguration.AzureWebJobsMobileAppUriName, DefaultUri);
            }
            if (includeDefaultKey)
            {
                resolver.Values.Add(MobileAppsConfiguration.AzureWebJobsMobileAppApiKeyName, DefaultKey);
            }

            config.NameResolver = resolver;

            config.UseMobileApps(mobileAppsConfig);

            JobHost host = new JobHost(config);

            await host.StartAsync();

            await host.CallAsync(testType.GetMethod(testName), arguments);

            await host.StopAsync();
        }
        private JobHost CreateTestJobHost()
        {
            ExplicitTypeLocator locator = new ExplicitTypeLocator(typeof(ApiHubTestJobs));

            JobHostConfiguration config = new JobHostConfiguration
            {
                TypeLocator = locator,
            };

            var apiHubConfig = new ApiHubConfiguration();

            apiHubConfig.AddKeyPath("dropbox", _apiHubConnectionString);
            config.UseApiHub(apiHubConfig);

            return(new JobHost(config));
        }
        private JobHost CreateTestJobHost()
        {
            ExplicitTypeLocator  locator = new ExplicitTypeLocator(typeof(FilesTestJobs));
            JobHostConfiguration config  = new JobHostConfiguration
            {
                TypeLocator = locator
            };

            FilesConfiguration filesConfig = new FilesConfiguration
            {
                RootPath = rootPath
            };

            config.UseFiles(filesConfig);

            return(new JobHost(config));
        }
Пример #16
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);
        }
Пример #17
0
        private void IndexBindings(Type testType, MobileAppsConfiguration mobileConfig = null)
        {
            // Just start the jobhost -- this should fail if function indexing fails.

            ExplicitTypeLocator  locator = new ExplicitTypeLocator(testType);
            JobHostConfiguration config  = new JobHostConfiguration
            {
                TypeLocator = locator,
            };

            config.UseMobileApps(mobileConfig);

            JobHost host = new JobHost(config);

            host.Start();
            host.Stop();
        }
Пример #18
0
        private void RunTest(Type testType, string testName, INotificationHubClientServiceFactory factory, TraceWriter testTrace, object argument = null, string configConnectionString = ConfigConnStr, string configHubName = ConfigHubName, bool includeDefaultConnectionString = true, bool includeDefaultHubName = true)
        {
            ExplicitTypeLocator  locator = new ExplicitTypeLocator(testType);
            JobHostConfiguration config  = new JobHostConfiguration
            {
                TypeLocator = locator,
            };

            config.Tracing.Tracers.Add(testTrace);

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

            arguments.Add("triggerData", argument);

            var notificationHubConfig = new NotificationHubsConfiguration()
            {
                ConnectionString = configConnectionString,
                HubName          = configHubName,
                NotificationHubClientServiceFactory = factory
            };

            var resolver = new TestNameResolver();

            resolver.Values.Add("HubName", "ResolvedHubName");
            resolver.Values.Add("MyConnectionString", AttributeConnStr);
            if (includeDefaultConnectionString)
            {
                resolver.Values.Add(NotificationHubsConfiguration.NotificationHubConnectionStringName, DefaultConnStr);
            }
            if (includeDefaultHubName)
            {
                resolver.Values.Add(NotificationHubsConfiguration.NotificationHubSettingName, DefaultHubName);
            }

            config.NameResolver = resolver;

            config.UseNotificationHubs(notificationHubConfig);

            JobHost host = new JobHost(config);

            host.Start();
            host.Call(testType.GetMethod(testName), arguments);
            host.Stop();
        }
Пример #19
0
        private async Task RunTestAsync(Type testType, string testName, ICosmosDBServiceFactory factory, TraceWriter testTrace, object argument = null, string configConnectionString = ConfigConnStr, bool includeDefaultConnectionString = true)
        {
            ExplicitTypeLocator  locator = new ExplicitTypeLocator(testType);
            JobHostConfiguration config  = new JobHostConfiguration
            {
                TypeLocator = locator,
            };

            config.Tracing.Tracers.Add(testTrace);

            var arguments = new Dictionary <string, object>
            {
                { "triggerData", argument }
            };

            var cosmosDBConfig = new CosmosDBConfiguration()
            {
                ConnectionString       = configConnectionString,
                CosmosDBServiceFactory = factory
            };

            var resolver = new TestNameResolver();

            resolver.Values.Add("Database", "ResolvedDatabase");
            resolver.Values.Add("Collection", "ResolvedCollection");
            resolver.Values.Add("MyConnectionString", AttributeConnStr);
            resolver.Values.Add("Query", "ResolvedQuery");
            if (includeDefaultConnectionString)
            {
                resolver.Values.Add(CosmosDBConfiguration.AzureWebJobsCosmosDBConnectionStringName, DefaultConnStr);
            }

            config.NameResolver = resolver;

            config.UseCosmosDB(cosmosDBConfig);

            JobHost host = new JobHost(config);

            await host.StartAsync();

            await host.CallAsync(testType.GetMethod(testName), arguments);

            await host.StopAsync();
        }
Пример #20
0
        private async Task RunTimerJobTest(Type jobClassType, Func <bool> condition)
        {
            ExplicitTypeLocator  locator = new ExplicitTypeLocator(jobClassType);
            JobHostConfiguration config  = new JobHostConfiguration
            {
                TypeLocator = locator
            };

            config.UseTimers();
            JobHost host = new JobHost(config);

            host.Start();

            await TestHelpers.Await(() =>
            {
                return(condition());
            });

            host.Stop();
        }
Пример #21
0
        private async Task <JobHost> StartHostAsync(Type testType)
        {
            ExplicitTypeLocator locator       = new ExplicitTypeLocator(testType);
            ILoggerFactory      loggerFactory = new LoggerFactory();

            loggerFactory.AddProvider(_loggerProvider);

            JobHostConfiguration config = new JobHostConfiguration
            {
                TypeLocator   = locator,
                LoggerFactory = loggerFactory
            };

            config.UseCosmosDB();

            JobHost host = new JobHost(config);

            await host.StartAsync();

            return(host);
        }
        private JobHost CreateTestJobHost()
        {
            ExplicitTypeLocator locator = new ExplicitTypeLocator(typeof(FilesTestJobs));
            var resolver = new TestNameResolver();

            resolver.Values.Add("test", "TestValue");
            JobHostConfiguration config = new JobHostConfiguration
            {
                TypeLocator  = locator,
                NameResolver = resolver
            };

            FilesConfiguration filesConfig = new FilesConfiguration
            {
                RootPath = rootPath
            };

            config.UseFiles(filesConfig);

            return(new JobHost(config));
        }
        private async Task RunTimerJobTest(Type jobClassType, Func <bool> condition)
        {
            ExplicitTypeLocator locator      = new ExplicitTypeLocator(jobClassType);
            var                resolver      = new TestNameResolver();
            ILoggerFactory     loggerFactory = new LoggerFactory();
            TestLoggerProvider provider      = new TestLoggerProvider();

            loggerFactory.AddProvider(provider);

            IHost host = new HostBuilder()
                         .ConfigureWebJobs(builder =>
            {
                builder.AddAzureStorageCoreServices()
                .AddTimers();
            })
                         .ConfigureServices(services =>
            {
                services.AddSingleton <IWebJobsExceptionHandler>(new TestExceptionHandler());
                services.AddSingleton <INameResolver>(resolver);
                services.AddSingleton <ITypeLocator>(locator);
            })
                         .ConfigureLogging(logging =>
            {
                logging.ClearProviders();
                logging.AddProvider(_loggerProvider);
            })
                         .Build();

            await host.StartAsync();

            await TestHelpers.Await(() =>
            {
                return(condition());
            });

            await host.StopAsync();

            // TODO: ensure there were no errors
        }
Пример #24
0
        private void RunTest(Type testType, string testName, IDocumentDBServiceFactory factory, TraceWriter testTrace, object argument = null, DocumentDBConfiguration documentDBConfig = null)
        {
            ExplicitTypeLocator  locator = new ExplicitTypeLocator(testType);
            JobHostConfiguration config  = new JobHostConfiguration
            {
                TypeLocator = locator,
            };

            config.Tracing.Tracers.Add(testTrace);

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

            arguments.Add("triggerData", argument);

            if (documentDBConfig == null)
            {
                documentDBConfig = new DocumentDBConfiguration()
                {
                    ConnectionString         = "AccountEndpoint=https://someuri;AccountKey=some_key",
                    DocumentDBServiceFactory = factory
                };
            }

            var resolver = new TestNameResolver();

            resolver.Values.Add("Database", "ResolvedDatabase");
            resolver.Values.Add("Collection", "ResolvedCollection");

            config.NameResolver = resolver;

            config.UseDocumentDB(documentDBConfig);

            JobHost host = new JobHost(config);

            host.Start();
            host.Call(testType.GetMethod(testName), arguments);
            host.Stop();
        }
Пример #25
0
        private JobHost CreateTestJobHost()
        {
            ExplicitTypeLocator locator = new ExplicitTypeLocator(typeof(FilesTestJobs));
            var resolver = new TestNameResolver();

            resolver.Values.Add("test", "TestValue");

            ILoggerFactory     loggerFactory = new LoggerFactory();
            TestLoggerProvider provider      = new TestLoggerProvider();

            loggerFactory.AddProvider(provider);

            IHost host = new HostBuilder()
                         .ConfigureWebJobs(builder =>
            {
                builder.AddAzureStorageCoreServices()
                .AddFiles(o =>
                {
                    o.RootPath = this.rootPath;
                });
            })
                         .ConfigureServices(services =>
            {
                services.AddSingleton <IWebJobsExceptionHandler>(new TestExceptionHandler());
                services.AddSingleton <INameResolver>(resolver);
                services.AddSingleton <ITypeLocator>(locator);
            })
                         .ConfigureLogging(logging =>
            {
                logging.ClearProviders();
                logging.AddProvider(provider);
            })
                         .Build();

            return(host.GetJobHost());
        }
        private async Task RunTestAsync(string testName, IMobileServiceClientFactory factory, object argument = null,
                                        Uri configUri = null, string configKey = null, bool includeDefaultKey = true, bool includeDefaultUri = true, Type testType = null)
        {
            testType = testType ?? typeof(MobileTableEndToEndFunctions);
            ExplicitTypeLocator locator = new ExplicitTypeLocator(testType);

            var arguments = new Dictionary <string, object>
            {
                { "triggerData", argument }
            };

            var resolver = new TestNameResolver();

            IHost host = new HostBuilder()
                         .ConfigureWebJobs(builder =>
            {
                builder.AddAzureStorage()
                .AddMobileApps(o =>
                {
                    if (configUri != null)
                    {
                        o.MobileAppUri = configUri;
                    }

                    if (configKey != null)
                    {
                        o.ApiKey = configKey;
                    }
                });
            })
                         .ConfigureServices(services =>
            {
                services.AddSingleton <IMobileServiceClientFactory>(factory);
                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>
                {
                    { ConnectionStringNames.Storage, "UseDevelopmentStorage=true" },
                    { "MyUri", AttributeUri },
                    { "MyKey", AttributeKey }
                };

                if (includeDefaultUri)
                {
                    collection.Add(MobileAppsExtensionConfigProvider.AzureWebJobsMobileAppUriName, DefaultUri);
                }
                if (includeDefaultKey)
                {
                    collection.Add(MobileAppsExtensionConfigProvider.AzureWebJobsMobileAppApiKeyName, DefaultKey);
                }

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

            await host.StartAsync();

            await host.GetJobHost().CallAsync(testType.GetMethod(testName), arguments);

            await host.StopAsync();
        }