예제 #1
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));
        }
예제 #2
0
        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 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
            };
            IServiceBusAccountProvider serviceBusAccountProvider = new NullServiceBusAccountProvider();
            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();

            IJobHostContextFactory contextFactory = new TestJobHostContextFactory
            {
                FunctionIndexProvider = new FunctionIndexProvider(new FakeTypeLocator(typeof(TProgram)),
                                                                  DefaultTriggerBindingProvider.Create(nameResolver, storageAccountProvider,
                                                                                                       serviceBusAccountProvider, extensionTypeLocator, hostIdProvider, queueConfiguration,
                                                                                                       BackgroundExceptionDispatcher.Instance, messageEnqueuedWatcherAccessor,
                                                                                                       blobWrittenWatcherAccessor, sharedContextProvider, TextWriter.Null),
                                                                  DefaultBindingProvider.Create(nameResolver, storageAccountProvider, serviceBusAccountProvider,
                                                                                                extensionTypeLocator, messageEnqueuedWatcherAccessor, blobWrittenWatcherAccessor),
                                                                  DefaultJobActivator.Instance),
                StorageAccountProvider = storageAccountProvider,
                Queues = queueConfiguration
            };

            IServiceProvider serviceProvider = new TestJobHostConfiguration
            {
                ContextFactory = contextFactory
            };

            return(new TestJobHost <TProgram>(serviceProvider));
        }