public void GetExtensions_ReturnsEmptyCollection_WhenServiceTypeNotFound() { DefaultExtensionRegistry registry = new DefaultExtensionRegistry(); object[] services = registry.GetExtensions(typeof(IConvertible)).ToArray(); Assert.Equal(0, services.Length); }
public void WebhookProviderThrowExceptionTest() { var builder = new HostBuilder(); builder.ConfigureWebJobs(b => { b.AddSignalR(); }); var host = builder.Build(); using (host) { var configProvider = host.Services.GetRequiredService <IExtensionConfigProvider>(); var configuration = host.Services.GetRequiredService <IConfiguration>(); var nameResolver = host.Services.GetRequiredService <INameResolver>(); var converterManager = host.Services.GetRequiredService <IConverterManager>(); var webHookProviderMock = new Mock <IWebHookProvider>(); webHookProviderMock.Setup(w => w.GetUrl(It.IsAny <IExtensionConfigProvider>())).Returns(() => { throw new Exception(null); }); IExtensionRegistry registry = new DefaultExtensionRegistry(); ExtensionConfigContext context = new ExtensionConfigContext(configuration, nameResolver, converterManager, webHookProviderMock.Object, registry); // Assert no exceptions configProvider.Initialize(context); } }
public static FunctionIndexer Create(CloudStorageAccount account = null, INameResolver nameResolver = null, IExtensionRegistry extensionRegistry = null) { IStorageAccount storageAccount = account != null ? new StorageAccount(account) : null; IStorageAccountProvider storageAccountProvider = new SimpleStorageAccountProvider { StorageAccount = account }; IExtensionTypeLocator extensionTypeLocator = new NullExtensionTypeLocator(); ContextAccessor<IMessageEnqueuedWatcher> messageEnqueuedWatcherAccessor = new ContextAccessor<IMessageEnqueuedWatcher>(); ContextAccessor<IBlobWrittenWatcher> blobWrittenWatcherAccessor = new ContextAccessor<IBlobWrittenWatcher>(); ISharedContextProvider sharedContextProvider = new SharedContextProvider(); ITriggerBindingProvider triggerBindingProvider = DefaultTriggerBindingProvider.Create(nameResolver, storageAccountProvider, extensionTypeLocator, new FixedHostIdProvider("test"), new SimpleQueueConfiguration(maxDequeueCount: 5), BackgroundExceptionDispatcher.Instance, messageEnqueuedWatcherAccessor, blobWrittenWatcherAccessor, sharedContextProvider, new DefaultExtensionRegistry(), TextWriter.Null); IBindingProvider bindingProvider = DefaultBindingProvider.Create(nameResolver, storageAccountProvider, extensionTypeLocator, messageEnqueuedWatcherAccessor, blobWrittenWatcherAccessor, new DefaultExtensionRegistry()); IFunctionOutputLoggerProvider outputLoggerProvider = new NullFunctionOutputLoggerProvider(); var task = outputLoggerProvider.GetAsync(CancellationToken.None); task.Wait(); IFunctionOutputLogger outputLogger = task.Result; IFunctionExecutor executor = new FunctionExecutor(new NullFunctionInstanceLogger(), outputLogger, BackgroundExceptionDispatcher.Instance); if (extensionRegistry == null) { extensionRegistry = new DefaultExtensionRegistry(); } return new FunctionIndexer(triggerBindingProvider, bindingProvider, DefaultJobActivator.Instance, executor, extensionRegistry); }
public void RegisterExtension_RegisterMultipleInstances() { DefaultExtensionRegistry registry = new DefaultExtensionRegistry(); ServiceA serviceA = new ServiceA(); ServiceB serviceB = new ServiceB(); ServiceC serviceC = new ServiceC(); registry.RegisterExtension(typeof(IMyService), serviceA); registry.RegisterExtension(typeof(IMyService), serviceB); registry.RegisterExtension(typeof(IMyService), serviceC); OtherServiceA otherServiceA = new OtherServiceA(); OtherServiceB otherServiceB = new OtherServiceB(); registry.RegisterExtension(typeof(IMyOtherService), otherServiceA); registry.RegisterExtension(typeof(IMyOtherService), otherServiceB); object[] services = registry.GetExtensions(typeof(IMyService)).ToArray(); Assert.Equal(3, services.Length); Assert.True(services.Contains(serviceA)); Assert.True(services.Contains(serviceB)); Assert.True(services.Contains(serviceC)); services = registry.GetExtensions(typeof(IMyOtherService)).ToArray(); Assert.Equal(2, services.Length); Assert.True(services.Contains(otherServiceA)); Assert.True(services.Contains(otherServiceB)); }
/// <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); AddService <IExtensionRegistry>(extensions); AddService <StorageClientFactory>(new StorageClientFactory()); AddService <INameResolver>(new DefaultNameResolver()); AddService <IJobActivator>(DefaultJobActivator.Instance); AddService <ITypeLocator>(typeLocator); string value = ConfigurationUtility.GetSettingFromConfigOrEnvironment(Constants.EnvironmentSettingName); IsDevelopment = string.Compare(Constants.DevelopmentEnvironmentValue, value, StringComparison.OrdinalIgnoreCase) == 0; }
public void TryCreate_DelegatesToExtensions() { DefaultExtensionRegistry extensions = new DefaultExtensionRegistry(); TableArgumentBindingExtensionProvider provider = new TableArgumentBindingExtensionProvider(extensions); // before binding extensions are registered for these types, // the provider returns null Assert.Null(provider.TryCreate(_parameters[0])); Assert.Null(provider.TryCreate(_parameters[1])); Assert.Null(provider.TryCreate(_parameters[2])); // register the binding extensions FooBarTableArgumentBindingExtensionProvider fooBarExtensionProvider = new FooBarTableArgumentBindingExtensionProvider(); BazTableArgumentBindingExtensionProvider bazExtensionProvider = new BazTableArgumentBindingExtensionProvider(); extensions.RegisterExtension<ITableArgumentBindingExtensionProvider>(fooBarExtensionProvider); extensions.RegisterExtension<ITableArgumentBindingExtensionProvider>(bazExtensionProvider); provider = new TableArgumentBindingExtensionProvider(extensions); ITableArgumentBinding binding = provider.TryCreate(_parameters[0]); Assert.Same(typeof(IFoo), binding.ValueType); binding = provider.TryCreate(_parameters[1]); Assert.Same(typeof(IBar), binding.ValueType); binding = provider.TryCreate(_parameters[2]); Assert.Same(typeof(IBaz), binding.ValueType); }
public void TryCreate_DelegatesToExtensions() { DefaultExtensionRegistry extensions = new DefaultExtensionRegistry(); TableArgumentBindingExtensionProvider provider = new TableArgumentBindingExtensionProvider(extensions); // before binding extensions are registered for these types, // the provider returns null Assert.Null(provider.TryCreate(_parameters[0])); Assert.Null(provider.TryCreate(_parameters[1])); Assert.Null(provider.TryCreate(_parameters[2])); // register the binding extensions FooBarTableArgumentBindingProvider fooBarExtensionProvider = new FooBarTableArgumentBindingProvider(); BazTableArgumentBindingProvider bazExtensionProvider = new BazTableArgumentBindingProvider(); extensions.RegisterExtension <IArgumentBindingProvider <ITableArgumentBinding> >(fooBarExtensionProvider); extensions.RegisterExtension <IArgumentBindingProvider <ITableArgumentBinding> >(bazExtensionProvider); provider = new TableArgumentBindingExtensionProvider(extensions); IStorageTableArgumentBinding binding = provider.TryCreate(_parameters[0]); Assert.Same(typeof(IFoo), binding.ValueType); binding = provider.TryCreate(_parameters[1]); Assert.Same(typeof(IBar), binding.ValueType); binding = provider.TryCreate(_parameters[2]); Assert.Same(typeof(IBaz), binding.ValueType); }
public void RegisterExtension_ThrowsArgumentNull_WhenTypeIsNull() { DefaultExtensionRegistry registry = new DefaultExtensionRegistry(); ArgumentNullException exception = Assert.Throws<ArgumentNullException>( () => registry.RegisterExtension(null, new ServiceA()) ); Assert.Equal("type", exception.ParamName); }
public void RegisterExtension_ThrowsArgumentNull_WhenInstanceIsNull() { DefaultExtensionRegistry registry = new DefaultExtensionRegistry(); ArgumentNullException exception = Assert.Throws<ArgumentNullException>( () => registry.RegisterExtension(typeof(IMyService), null) ); Assert.Equal("instance", exception.ParamName); }
public void GetExtensions_ThrowsArgumentNull_WhenTypeIsNull() { DefaultExtensionRegistry registry = new DefaultExtensionRegistry(); ArgumentNullException exception = Assert.Throws<ArgumentNullException>( () => registry.GetExtensions(null) ); Assert.Equal("type", exception.ParamName); }
public void RegisterExtension_ThrowsArgumentOutOfRange_WhenInstanceNotInstanceOfType() { DefaultExtensionRegistry registry = new DefaultExtensionRegistry(); ArgumentOutOfRangeException exception = Assert.Throws<ArgumentOutOfRangeException>( () => registry.RegisterExtension(typeof(IMyService), new ServiceD()) ); Assert.Equal("instance", exception.ParamName); }
public void GetExtensions_ThrowsArgumentNull_WhenTypeIsNull() { DefaultExtensionRegistry registry = new DefaultExtensionRegistry(); ArgumentNullException exception = Assert.Throws <ArgumentNullException>( () => registry.GetExtensions(null) ); Assert.Equal("type", exception.ParamName); }
public void RegisterExtension_ThrowsArgumentNull_WhenTypeIsNull() { DefaultExtensionRegistry registry = new DefaultExtensionRegistry(); ArgumentNullException exception = Assert.Throws <ArgumentNullException>( () => registry.RegisterExtension(null, new ServiceA()) ); Assert.Equal("type", exception.ParamName); }
public void RegisterExtension_ThrowsArgumentOutOfRange_WhenInstanceNotInstanceOfType() { DefaultExtensionRegistry registry = new DefaultExtensionRegistry(); ArgumentOutOfRangeException exception = Assert.Throws <ArgumentOutOfRangeException>( () => registry.RegisterExtension(typeof(IMyService), new ServiceD()) ); Assert.Equal("instance", exception.ParamName); }
public void RegisterExtension_ThrowsArgumentNull_WhenInstanceIsNull() { DefaultExtensionRegistry registry = new DefaultExtensionRegistry(); ArgumentNullException exception = Assert.Throws <ArgumentNullException>( () => registry.RegisterExtension(typeof(IMyService), null) ); Assert.Equal("instance", exception.ParamName); }
/// <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)); }
private JobHostConfiguration(DefaultStorageAccountProvider storageAccountProvider) { _storageAccountProvider = storageAccountProvider; IExtensionRegistry extensions = new DefaultExtensionRegistry(); _typeLocator = new DefaultTypeLocator(ConsoleProvider.Out, extensions); Singleton = new SingletonConfiguration(); // add our built in services here AddService <IExtensionRegistry>(extensions); }
public static TestJobHost <TProgram> Create <TProgram>(CloudStorageAccount storageAccount, int maxDequeueCount) { IStorageAccountProvider storageAccountProvider = new SimpleStorageAccountProvider { 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); ContextAccessor <IMessageEnqueuedWatcher> messageEnqueuedWatcherAccessor = new ContextAccessor <IMessageEnqueuedWatcher>(); ContextAccessor <IBlobWrittenWatcher> blobWrittenWatcherAccessor = new ContextAccessor <IBlobWrittenWatcher>(); ISharedContextProvider sharedContextProvider = new SharedContextProvider(); IExtensionRegistry extensions = new DefaultExtensionRegistry(); IFunctionOutputLoggerProvider outputLoggerProvider = new NullFunctionOutputLoggerProvider(); var task = outputLoggerProvider.GetAsync(CancellationToken.None); task.Wait(); IFunctionOutputLogger outputLogger = task.Result; IFunctionExecutor executor = new FunctionExecutor(new NullFunctionInstanceLogger(), outputLogger, BackgroundExceptionDispatcher.Instance); var triggerBindingProvider = DefaultTriggerBindingProvider.Create( nameResolver, storageAccountProvider, extensionTypeLocator, hostIdProvider, queueConfiguration, BackgroundExceptionDispatcher.Instance, messageEnqueuedWatcherAccessor, blobWrittenWatcherAccessor, sharedContextProvider, extensions, TextWriter.Null); var bindingProvider = DefaultBindingProvider.Create(nameResolver, storageAccountProvider, extensionTypeLocator, messageEnqueuedWatcherAccessor, blobWrittenWatcherAccessor, extensions); var functionIndexProvider = new FunctionIndexProvider(new FakeTypeLocator(typeof(TProgram)), triggerBindingProvider, bindingProvider, DefaultJobActivator.Instance, executor, new DefaultExtensionRegistry()); IJobHostContextFactory contextFactory = new TestJobHostContextFactory { FunctionIndexProvider = functionIndexProvider, StorageAccountProvider = storageAccountProvider, Queues = queueConfiguration }; IServiceProvider serviceProvider = new TestJobHostConfiguration { ContextFactory = contextFactory }; return(new TestJobHost <TProgram>(serviceProvider)); }
public void IsJobMethod_ReturnsTrue_IfMethodHasJobParameterAttributes_FromExtensionAssemblies() { // Arrange Mock <IFunctionIndex> indexMock = new Mock <IFunctionIndex>(); IExtensionRegistry extensions = new DefaultExtensionRegistry(); extensions.RegisterExtension <ITriggerBindingProvider>(new TestExtensionTriggerBindingProvider()); extensions.RegisterExtension <IBindingProvider>(new TestExtensionBindingProvider()); FunctionIndexer product = FunctionIndexerFactory.Create(extensionRegistry: extensions); // Act bool actual = product.IsJobMethod(typeof(FunctionIndexerTests).GetMethod("MethodWithExtensionJobParameterAttributes")); // Verify Assert.Equal(true, actual); }
public void IExtensionRegistryExtensions_RegisterAndRetrieve() { DefaultExtensionRegistry registry = new DefaultExtensionRegistry(); // use the generic extension methods to register ServiceA serviceA = new ServiceA(); ServiceB serviceB = new ServiceB(); ServiceC serviceC = new ServiceC(); registry.RegisterExtension<IMyService>(serviceA); registry.RegisterExtension<IMyService>(serviceB); registry.RegisterExtension<IMyService>(serviceC); IMyService[] services = registry.GetExtensions<IMyService>().ToArray(); Assert.Equal(3, services.Length); Assert.True(services.Contains(serviceA)); Assert.True(services.Contains(serviceB)); Assert.True(services.Contains(serviceC)); }
public void IExtensionRegistryExtensions_RegisterAndRetrieve() { DefaultExtensionRegistry registry = new DefaultExtensionRegistry(); // use the generic extension methods to register ServiceA serviceA = new ServiceA(); ServiceB serviceB = new ServiceB(); ServiceC serviceC = new ServiceC(); registry.RegisterExtension <IMyService>(serviceA); registry.RegisterExtension <IMyService>(serviceB); registry.RegisterExtension <IMyService>(serviceC); IMyService[] services = registry.GetExtensions <IMyService>().ToArray(); Assert.Equal(3, services.Length); Assert.True(services.Contains(serviceA)); Assert.True(services.Contains(serviceB)); Assert.True(services.Contains(serviceC)); }
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)); }
public async Task TryCreate_ReturnsTableArgumentBindingExtensionWrapper() { DefaultExtensionRegistry extensions = new DefaultExtensionRegistry(); FooBarTableArgumentBindingExtensionProvider fooBarExtensionProvider = new FooBarTableArgumentBindingExtensionProvider(); extensions.RegisterExtension<ITableArgumentBindingExtensionProvider>(fooBarExtensionProvider); TableArgumentBindingExtensionProvider provider = new TableArgumentBindingExtensionProvider(extensions); ITableArgumentBinding binding = provider.TryCreate(_parameters[0]); Assert.Equal(typeof(TableArgumentBindingExtensionProvider.TableArgumentBindingExtension), binding.GetType()); Assert.Null(BoundTable); CloudTable table = new CloudTable(new Uri("http://localhost:10000/test/table")); IStorageTable storageTable = new StorageTable(table); FunctionBindingContext functionContext = new FunctionBindingContext(Guid.NewGuid(), CancellationToken.None, new StringWriter()); ValueBindingContext context = new ValueBindingContext(functionContext, CancellationToken.None); IValueProvider valueProvider = await binding.BindAsync(storageTable, context); Assert.NotNull(valueProvider); Assert.Same(table, BoundTable); }
public void Table_IfBoundToCustomTableBindingExtension_BindsCorrectly() { // Arrange IStorageAccount account = CreateFakeStorageAccount(); IStorageQueue triggerQueue = CreateQueue(account, TriggerQueueName); triggerQueue.AddMessage(triggerQueue.CreateMessage("ignore")); // register our custom table binding extension provider DefaultExtensionRegistry extensions = new DefaultExtensionRegistry(); extensions.RegisterExtension <IArgumentBindingProvider <ITableArgumentBinding> >(new CustomTableArgumentBindingProvider()); // Act RunTrigger(account, typeof(CustomTableBindingExtensionProgram), extensions); // Assert Assert.Equal(TableName, CustomTableBinding <Poco> .Table.Name); Assert.True(CustomTableBinding <Poco> .AddInvoked); Assert.True(CustomTableBinding <Poco> .DeleteInvoked); }
public static FunctionIndexer Create(CloudStorageAccount account = null, INameResolver nameResolver = null, IExtensionRegistry extensionRegistry = 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(); TestTraceWriter logger = new TestTraceWriter(TraceLevel.Verbose); SingletonManager singletonManager = new SingletonManager(); ITriggerBindingProvider triggerBindingProvider = DefaultTriggerBindingProvider.Create(nameResolver, storageAccountProvider, extensionTypeLocator, new FixedHostIdProvider("test"), new SimpleQueueConfiguration(maxDequeueCount: 5), BackgroundExceptionDispatcher.Instance, messageEnqueuedWatcherAccessor, blobWrittenWatcherAccessor, sharedContextProvider, new DefaultExtensionRegistry(), singletonManager, logger); IBindingProvider bindingProvider = DefaultBindingProvider.Create(nameResolver, storageAccountProvider, extensionTypeLocator, messageEnqueuedWatcherAccessor, blobWrittenWatcherAccessor, new DefaultExtensionRegistry()); TraceWriter trace = new TestTraceWriter(TraceLevel.Verbose); IFunctionOutputLoggerProvider outputLoggerProvider = new NullFunctionOutputLoggerProvider(); IFunctionOutputLogger outputLogger = outputLoggerProvider.GetAsync(CancellationToken.None).Result; IFunctionExecutor executor = new FunctionExecutor(new NullFunctionInstanceLogger(), outputLogger, BackgroundExceptionDispatcher.Instance, trace, null); if (extensionRegistry == null) { extensionRegistry = new DefaultExtensionRegistry(); } return new FunctionIndexer(triggerBindingProvider, bindingProvider, DefaultJobActivator.Instance, executor, extensionRegistry, new SingletonManager(), trace); }
/// <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); AddService <IExtensionRegistry>(extensions); AddService <StorageClientFactory>(new StorageClientFactory()); AddService <INameResolver>(new DefaultNameResolver()); AddService <IJobActivator>(DefaultJobActivator.Instance); AddService <ITypeLocator>(typeLocator); }
public async Task TryCreate_ReturnsTableArgumentBindingExtensionWrapper() { DefaultExtensionRegistry extensions = new DefaultExtensionRegistry(); FooBarTableArgumentBindingProvider fooBarExtensionProvider = new FooBarTableArgumentBindingProvider(); extensions.RegisterExtension <IArgumentBindingProvider <ITableArgumentBinding> >(fooBarExtensionProvider); TableArgumentBindingExtensionProvider provider = new TableArgumentBindingExtensionProvider(extensions); IStorageTableArgumentBinding binding = provider.TryCreate(_parameters[0]); Assert.Equal(typeof(TableArgumentBindingExtensionProvider.TableArgumentBindingExtension), binding.GetType()); Assert.Null(BoundTable); CloudTable table = new CloudTable(new Uri("http://localhost:10000/test/table")); IStorageTable storageTable = new StorageTable(table); FunctionBindingContext functionContext = new FunctionBindingContext(Guid.NewGuid(), CancellationToken.None, new StringWriter()); ValueBindingContext context = new ValueBindingContext(functionContext, CancellationToken.None); IValueProvider valueProvider = await binding.BindAsync(storageTable, context); Assert.NotNull(valueProvider); Assert.Same(table, BoundTable); }
public static FunctionIndexer Create(CloudStorageAccount account = null, INameResolver nameResolver = null, IExtensionRegistry extensionRegistry = null) { IStorageAccount storageAccount = account != null ? new StorageAccount(account) : null; IStorageAccountProvider storageAccountProvider = new SimpleStorageAccountProvider { StorageAccount = account }; IExtensionTypeLocator extensionTypeLocator = new NullExtensionTypeLocator(); ContextAccessor <IMessageEnqueuedWatcher> messageEnqueuedWatcherAccessor = new ContextAccessor <IMessageEnqueuedWatcher>(); ContextAccessor <IBlobWrittenWatcher> blobWrittenWatcherAccessor = new ContextAccessor <IBlobWrittenWatcher>(); ISharedContextProvider sharedContextProvider = new SharedContextProvider(); TestTraceWriter logger = new TestTraceWriter(TraceLevel.Verbose); ITriggerBindingProvider triggerBindingProvider = DefaultTriggerBindingProvider.Create(nameResolver, storageAccountProvider, extensionTypeLocator, new FixedHostIdProvider("test"), new SimpleQueueConfiguration(maxDequeueCount: 5), BackgroundExceptionDispatcher.Instance, messageEnqueuedWatcherAccessor, blobWrittenWatcherAccessor, sharedContextProvider, new DefaultExtensionRegistry(), logger); IBindingProvider bindingProvider = DefaultBindingProvider.Create(nameResolver, storageAccountProvider, extensionTypeLocator, messageEnqueuedWatcherAccessor, blobWrittenWatcherAccessor, new DefaultExtensionRegistry()); IFunctionOutputLoggerProvider outputLoggerProvider = new NullFunctionOutputLoggerProvider(); var task = outputLoggerProvider.GetAsync(CancellationToken.None); task.Wait(); IFunctionOutputLogger outputLogger = task.Result; IFunctionExecutor executor = new FunctionExecutor(new NullFunctionInstanceLogger(), outputLogger, BackgroundExceptionDispatcher.Instance, new TestTraceWriter(TraceLevel.Verbose)); if (extensionRegistry == null) { extensionRegistry = new DefaultExtensionRegistry(); } return(new FunctionIndexer(triggerBindingProvider, bindingProvider, DefaultJobActivator.Instance, executor, extensionRegistry, new SingletonManager())); }
/// <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(); Aggregator = new FunctionResultAggregatorConfiguration(); // add our built in services here _tooling = new JobHostMetadataProvider(this); IExtensionRegistry extensions = new DefaultExtensionRegistry(_tooling); ITypeLocator typeLocator = new DefaultTypeLocator(ConsoleProvider.Out, extensions); IConverterManager converterManager = new ConverterManager(); IWebJobsExceptionHandler exceptionHandler = new WebJobsExceptionHandler(); AddService <IQueueConfiguration>(_queueConfiguration); AddService <IConsoleProvider>(ConsoleProvider); 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.GetSettingFromConfigOrEnvironment(Host.Constants.EnvironmentSettingName); IsDevelopment = string.Compare(Host.Constants.DevelopmentEnvironmentValue, value, StringComparison.OrdinalIgnoreCase) == 0; }
private static IServiceProvider CreateServiceProvider <TResult>(IStorageAccount storageAccount, Type programType, IExtensionTypeLocator extensionTypeLocator, IJobActivator activator, TaskCompletionSource <TResult> taskSource, IFunctionInstanceLogger functionInstanceLogger, IExtensionRegistry extensions = null) { IStorageAccountProvider storageAccountProvider = new FakeStorageAccountProvider { StorageAccount = storageAccount }; IHostIdProvider hostIdProvider = new FakeHostIdProvider(); INameResolver nameResolver = null; IQueueConfiguration queueConfiguration = new FakeQueueConfiguration(storageAccountProvider); IBackgroundExceptionDispatcher backgroundExceptionDispatcher = new TaskBackgroundExceptionDispatcher <TResult>(taskSource); ContextAccessor <IMessageEnqueuedWatcher> messageEnqueuedWatcherAccessor = new ContextAccessor <IMessageEnqueuedWatcher>(); ContextAccessor <IBlobWrittenWatcher> blobWrittenWatcherAccessor = new ContextAccessor <IBlobWrittenWatcher>(); ISharedContextProvider sharedContextProvider = new SharedContextProvider(); if (extensions == null) { extensions = new DefaultExtensionRegistry(); } ITriggerBindingProvider triggerBindingProvider = DefaultTriggerBindingProvider.Create(nameResolver, storageAccountProvider, extensionTypeLocator, hostIdProvider, queueConfiguration, backgroundExceptionDispatcher, messageEnqueuedWatcherAccessor, blobWrittenWatcherAccessor, sharedContextProvider, extensions, TextWriter.Null); IBindingProvider bindingProvider = DefaultBindingProvider.Create(nameResolver, storageAccountProvider, extensionTypeLocator, messageEnqueuedWatcherAccessor, blobWrittenWatcherAccessor, extensions); IFunctionInstanceLoggerProvider functionInstanceLoggerProvider = new NullFunctionInstanceLoggerProvider(); IFunctionOutputLoggerProvider functionOutputLoggerProvider = new NullFunctionOutputLoggerProvider(); Task <IFunctionOutputLogger> task = functionOutputLoggerProvider.GetAsync(CancellationToken.None); task.Wait(); IFunctionOutputLogger functionOutputLogger = task.Result; FunctionExecutor executor = new FunctionExecutor(functionInstanceLogger, functionOutputLogger, backgroundExceptionDispatcher); ITypeLocator typeLocator = new FakeTypeLocator(programType); FunctionIndexProvider functionIndexProvider = new FunctionIndexProvider( typeLocator, triggerBindingProvider, bindingProvider, activator, executor, extensions); IJobHostContextFactory contextFactory = new FakeJobHostContextFactory { TypeLocator = typeLocator, FunctionIndexProvider = functionIndexProvider, StorageAccountProvider = storageAccountProvider, BackgroundExceptionDispatcher = backgroundExceptionDispatcher, BindingProvider = bindingProvider, ConsoleProvider = new NullConsoleProvider(), HostInstanceLoggerProvider = new NullHostInstanceLoggerProvider(), FunctionExecutor = executor, FunctionInstanceLoggerProvider = functionInstanceLoggerProvider, FunctionOutputLoggerProvider = functionOutputLoggerProvider, HostIdProvider = hostIdProvider, QueueConfiguration = queueConfiguration }; return(new FakeServiceProvider { ContextFactory = contextFactory }); }