public static FunctionIndexer Create(CloudStorageAccount account = null, INameResolver nameResolver = null, IExtensionRegistry extensionRegistry = null, TraceWriter traceWriter = null, ILoggerFactory loggerFactory = null) { IStorageAccountProvider storageAccountProvider = GetStorageAccountProvider(account); var config = TestHelpers.NewConfig(storageAccountProvider, nameResolver, extensionRegistry); var services = config.CreateStaticServices(); ITriggerBindingProvider triggerBindingProvider = services.GetService <ITriggerBindingProvider>(); IBindingProvider bindingProvider = services.GetService <IBindingProvider>(); IJobActivator activator = services.GetService <IJobActivator>(); extensionRegistry = services.GetService <IExtensionRegistry>(); SingletonManager singletonManager = new SingletonManager(); TraceWriter logger = traceWriter ?? new TestTraceWriter(TraceLevel.Verbose); IWebJobsExceptionHandler exceptionHandler = new WebJobsExceptionHandler(); IFunctionOutputLoggerProvider outputLoggerProvider = new NullFunctionOutputLoggerProvider(); IFunctionOutputLogger outputLogger = outputLoggerProvider.GetAsync(CancellationToken.None).Result; IFunctionExecutor executor = new FunctionExecutor(new NullFunctionInstanceLogger(), outputLogger, exceptionHandler, logger); return(new FunctionIndexer(triggerBindingProvider, bindingProvider, DefaultJobActivator.Instance, executor, extensionRegistry, singletonManager, logger, loggerFactory)); }
/// <summary> /// Initializes a new instance of the <see cref="JobHostConfiguration"/> class, using the /// specified connection string for both reading and writing data as well as Dashboard logging. /// </summary> /// <param name="dashboardAndStorageConnectionString">The Azure Storage connection string to use. /// </param> public JobHostConfiguration(string dashboardAndStorageConnectionString) { if (!string.IsNullOrEmpty(dashboardAndStorageConnectionString)) { _storageAccountProvider = new DefaultStorageAccountProvider(this, dashboardAndStorageConnectionString); } else { _storageAccountProvider = new DefaultStorageAccountProvider(this); } Singleton = new SingletonConfiguration(); // add our built in services here IExtensionRegistry extensions = new DefaultExtensionRegistry(); ITypeLocator typeLocator = new DefaultTypeLocator(ConsoleProvider.Out, extensions); IConverterManager converterManager = new ConverterManager(); IWebJobsExceptionHandler exceptionHandler = new WebJobsExceptionHandler(); AddService <IExtensionRegistry>(extensions); AddService <StorageClientFactory>(new StorageClientFactory()); AddService <INameResolver>(new DefaultNameResolver()); AddService <IJobActivator>(DefaultJobActivator.Instance); AddService <ITypeLocator>(typeLocator); AddService <IConverterManager>(converterManager); AddService <IWebJobsExceptionHandler>(exceptionHandler); string value = ConfigurationUtility.GetSettingFromConfigOrEnvironment(Constants.EnvironmentSettingName); IsDevelopment = string.Compare(Constants.DevelopmentEnvironmentValue, value, StringComparison.OrdinalIgnoreCase) == 0; }
/// <summary> /// Initializes a new instance of the <see cref="JobHostConfiguration"/> class, using the /// specified connection string for both reading and writing data as well as Dashboard logging. /// </summary> /// <param name="dashboardAndStorageConnectionString">The Azure Storage connection string to use. /// <param name="configuration">A configuration object that will be used as the source of application settings.</param> /// </param> public JobHostConfiguration(string dashboardAndStorageConnectionString, IConfiguration configuration) { if (configuration != null) { ConfigurationUtility.SetConfigurationFactory(() => configuration); } if (!string.IsNullOrEmpty(dashboardAndStorageConnectionString)) { _storageAccountProvider = new DefaultStorageAccountProvider(this, dashboardAndStorageConnectionString); } else { _storageAccountProvider = new DefaultStorageAccountProvider(this); } var sasBlobContainer = _storageAccountProvider.InternalSasStorage; if (sasBlobContainer != null) { var uri = new Uri(sasBlobContainer); var sdkContainer = new CloudBlobContainer(uri); this.InternalStorageConfiguration = new JobHostInternalStorageConfiguration { InternalContainer = sdkContainer }; } Singleton = new SingletonConfiguration(); Aggregator = new FunctionResultAggregatorConfiguration(); // add our built in services here IExtensionRegistry extensions = new DefaultExtensionRegistry(); ITypeLocator typeLocator = new DefaultTypeLocator(ConsoleProvider.Out, extensions); IConverterManager converterManager = new ConverterManager(); IWebJobsExceptionHandler exceptionHandler = new WebJobsExceptionHandler(); AddService <IQueueConfiguration>(_queueConfiguration); AddService <IConsoleProvider>(ConsoleProvider); AddService <ILoggerFactory>(new LoggerFactory()); AddService <IStorageAccountProvider>(_storageAccountProvider); AddService <IExtensionRegistry>(extensions); AddService <StorageClientFactory>(new StorageClientFactory()); AddService <INameResolver>(new DefaultNameResolver()); AddService <IJobActivator>(DefaultJobActivator.Instance); AddService <ITypeLocator>(typeLocator); AddService <IConverterManager>(converterManager); AddService <IWebJobsExceptionHandler>(exceptionHandler); AddService <IFunctionResultAggregatorFactory>(new FunctionResultAggregatorFactory()); string value = ConfigurationUtility.GetSetting(Host.Constants.EnvironmentSettingName); IsDevelopment = string.Compare(Host.Constants.DevelopmentEnvironmentValue, value, StringComparison.OrdinalIgnoreCase) == 0; }
public static TestJobHost <TProgram> Create <TProgram>(CloudStorageAccount storageAccount, int maxDequeueCount) { TestJobHostConfiguration config = new TestJobHostConfiguration(); IStorageAccountProvider storageAccountProvider = new SimpleStorageAccountProvider(config) { StorageAccount = storageAccount, // use null logging string since unit tests don't need logs. DashboardAccount = null }; IExtensionTypeLocator extensionTypeLocator = new NullExtensionTypeLocator(); IHostIdProvider hostIdProvider = new FixedHostIdProvider("test"); INameResolver nameResolver = null; IQueueConfiguration queueConfiguration = new SimpleQueueConfiguration(maxDequeueCount); JobHostBlobsConfiguration blobsConfiguration = new JobHostBlobsConfiguration(); ContextAccessor <IMessageEnqueuedWatcher> messageEnqueuedWatcherAccessor = new ContextAccessor <IMessageEnqueuedWatcher>(); ContextAccessor <IBlobWrittenWatcher> blobWrittenWatcherAccessor = new ContextAccessor <IBlobWrittenWatcher>(); ISharedContextProvider sharedContextProvider = new SharedContextProvider(); IExtensionRegistry extensions = new DefaultExtensionRegistry(); SingletonManager singletonManager = new SingletonManager(); TraceWriter trace = new TestTraceWriter(TraceLevel.Verbose); IWebJobsExceptionHandler exceptionHandler = new WebJobsExceptionHandler(); IFunctionOutputLoggerProvider outputLoggerProvider = new NullFunctionOutputLoggerProvider(); IFunctionOutputLogger outputLogger = outputLoggerProvider.GetAsync(CancellationToken.None).Result; IFunctionExecutor executor = new FunctionExecutor(new NullFunctionInstanceLogger(), outputLogger, exceptionHandler, trace); var triggerBindingProvider = DefaultTriggerBindingProvider.Create( nameResolver, storageAccountProvider, extensionTypeLocator, hostIdProvider, queueConfiguration, blobsConfiguration, exceptionHandler, messageEnqueuedWatcherAccessor, blobWrittenWatcherAccessor, sharedContextProvider, extensions, singletonManager, new TestTraceWriter(TraceLevel.Verbose)); var bindingProvider = DefaultBindingProvider.Create(nameResolver, null, storageAccountProvider, extensionTypeLocator, messageEnqueuedWatcherAccessor, blobWrittenWatcherAccessor, extensions); var functionIndexProvider = new FunctionIndexProvider(new FakeTypeLocator(typeof(TProgram)), triggerBindingProvider, bindingProvider, DefaultJobActivator.Instance, executor, new DefaultExtensionRegistry(), singletonManager, trace); IJobHostContextFactory contextFactory = new TestJobHostContextFactory { FunctionIndexProvider = functionIndexProvider, StorageAccountProvider = storageAccountProvider, Queues = queueConfiguration, SingletonManager = singletonManager, HostIdProvider = hostIdProvider }; config.ContextFactory = contextFactory; return(new TestJobHost <TProgram>(config)); }
public QueueTriggerBindingIntegrationTests() { IQueueTriggerArgumentBindingProvider provider = new UserTypeArgumentBindingProvider(); ParameterInfo pi = new StubParameterInfo("parameterName", typeof(UserDataType)); var argumentBinding = provider.TryCreate(pi); Mock <IStorageQueue> queueMock = new Mock <IStorageQueue>(MockBehavior.Strict); queueMock.Setup(q => q.Name).Returns("queueName"); IStorageQueue queue = queueMock.Object; IWebJobsExceptionHandler exceptionHandler = new WebJobsExceptionHandler(); _binding = new QueueTriggerBinding("parameterName", queue, argumentBinding, new Mock <IQueueConfiguration>(MockBehavior.Strict).Object, exceptionHandler, new Mock <IContextSetter <IMessageEnqueuedWatcher> >(MockBehavior.Strict).Object, new SharedContextProvider(), new TestTraceWriter(TraceLevel.Verbose), null); }
public QueueTriggerBindingIntegrationTests() { IQueueTriggerArgumentBindingProvider provider = new UserTypeArgumentBindingProvider(); ParameterInfo pi = new StubParameterInfo("parameterName", typeof(UserDataType)); var argumentBinding = provider.TryCreate(pi); var fakeAccount = new FakeStorage.FakeAccount(); CloudQueue queue = fakeAccount.CreateCloudQueueClient().GetQueueReference("queueName"); IWebJobsExceptionHandler exceptionHandler = new WebJobsExceptionHandler(new Mock <IHost>().Object); var enqueueWatcher = new Host.Queues.Listeners.SharedQueueWatcher(); _binding = new QueueTriggerBinding("parameterName", queue, argumentBinding, new QueuesOptions(), exceptionHandler, enqueueWatcher, null, null); }
public void SetUp() { _invariantCultureFixture = new InvariantCultureFixture(); IQueueTriggerArgumentBindingProvider provider = new UserTypeArgumentBindingProvider(); ParameterInfo pi = new StubParameterInfo("parameterName", typeof(UserDataType)); var argumentBinding = provider.TryCreate(pi); QueueServiceClient queueServiceClient = AzuriteNUnitFixture.Instance.GetQueueServiceClient(); QueueClient queue = queueServiceClient.GetQueueClient("queueName-queuetriggerbindingintegrationtests"); IWebJobsExceptionHandler exceptionHandler = new WebJobsExceptionHandler(new Mock <IHost>().Object); var enqueueWatcher = new SharedQueueWatcher(); _binding = new QueueTriggerBinding("parameterName", queueServiceClient, queue, argumentBinding, new QueuesOptions(), exceptionHandler, enqueueWatcher, null, null); }
public QueueTriggerBindingIntegrationTests(AzuriteFixture azuriteFixture) { IQueueTriggerArgumentBindingProvider provider = new UserTypeArgumentBindingProvider(); ParameterInfo pi = new StubParameterInfo("parameterName", typeof(UserDataType)); var argumentBinding = provider.TryCreate(pi); var fakeAccount = azuriteFixture.GetAccount(); QueueServiceClient queueServiceClient = fakeAccount.CreateQueueServiceClient(); QueueClient queue = queueServiceClient.GetQueueClient("queueName-queuetriggerbindingintegrationtests"); IWebJobsExceptionHandler exceptionHandler = new WebJobsExceptionHandler(new Mock <IHost>().Object); var enqueueWatcher = new Host.Queues.Listeners.SharedQueueWatcher(); _binding = new QueueTriggerBinding("parameterName", queueServiceClient, queue, argumentBinding, new QueuesOptions(), exceptionHandler, enqueueWatcher, null, null); }
public static FunctionIndexer Create(CloudStorageAccount account = null, INameResolver nameResolver = null, IExtensionRegistry extensionRegistry = null, TraceWriter traceWriter = null) { Mock <IServiceProvider> services = new Mock <IServiceProvider>(MockBehavior.Strict); StorageClientFactory clientFactory = new StorageClientFactory(); services.Setup(p => p.GetService(typeof(StorageClientFactory))).Returns(clientFactory); IStorageAccount storageAccount = account != null ? new StorageAccount(account, services.Object) : null; IStorageAccountProvider storageAccountProvider = new SimpleStorageAccountProvider(services.Object) { StorageAccount = account }; IExtensionTypeLocator extensionTypeLocator = new NullExtensionTypeLocator(); ContextAccessor <IMessageEnqueuedWatcher> messageEnqueuedWatcherAccessor = new ContextAccessor <IMessageEnqueuedWatcher>(); ContextAccessor <IBlobWrittenWatcher> blobWrittenWatcherAccessor = new ContextAccessor <IBlobWrittenWatcher>(); ISharedContextProvider sharedContextProvider = new SharedContextProvider(); TraceWriter logger = traceWriter ?? new TestTraceWriter(TraceLevel.Verbose); SingletonManager singletonManager = new SingletonManager(); IWebJobsExceptionHandler exceptionHandler = new WebJobsExceptionHandler(); var blobsConfiguration = new JobHostBlobsConfiguration(); ITriggerBindingProvider triggerBindingProvider = DefaultTriggerBindingProvider.Create(nameResolver, storageAccountProvider, extensionTypeLocator, new FixedHostIdProvider("test"), new SimpleQueueConfiguration(maxDequeueCount: 5), blobsConfiguration, exceptionHandler, messageEnqueuedWatcherAccessor, blobWrittenWatcherAccessor, sharedContextProvider, new DefaultExtensionRegistry(), singletonManager, logger); IBindingProvider bindingProvider = DefaultBindingProvider.Create(nameResolver, null, storageAccountProvider, extensionTypeLocator, messageEnqueuedWatcherAccessor, blobWrittenWatcherAccessor, new DefaultExtensionRegistry()); IFunctionOutputLoggerProvider outputLoggerProvider = new NullFunctionOutputLoggerProvider(); IFunctionOutputLogger outputLogger = outputLoggerProvider.GetAsync(CancellationToken.None).Result; IFunctionExecutor executor = new FunctionExecutor(new NullFunctionInstanceLogger(), outputLogger, exceptionHandler, logger); if (extensionRegistry == null) { extensionRegistry = new DefaultExtensionRegistry(); } return(new FunctionIndexer(triggerBindingProvider, bindingProvider, DefaultJobActivator.Instance, executor, extensionRegistry, new SingletonManager(), logger)); }