public CosmosDBExtensionConfigProvider(IOptions <CosmosDBOptions> options, ICosmosDBServiceFactory cosmosDBServiceFactory, INameResolver nameResolver, ILoggerFactory loggerFactory) { _cosmosDBServiceFactory = cosmosDBServiceFactory; _nameResolver = nameResolver; _options = options.Value; _loggerFactory = loggerFactory; }
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(); }
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(); }
private Task RunTestAsync(string testName, ICosmosDBServiceFactory factory, object argument = null, string configConnectionString = ConfigConnStr) { return(RunTestAsync(typeof(CosmosDBEndToEndFunctions), testName, factory, argument, configConnectionString)); }