private JobHost CreateTestJobHost(int hostId)
        {
            TestJobActivator activator = new TestJobActivator(hostId);

            JobHostConfiguration config = new JobHostConfiguration
            {
                HostId       = TestHostId,
                NameResolver = _resolver,
                TypeLocator  = new FakeTypeLocator(typeof(TestJobs)),
                JobActivator = activator
            };

            config.AddService <IWebJobsExceptionHandler>(new TestExceptionHandler());
            config.Queues.MaxPollingInterval                = TimeSpan.FromSeconds(2);
            config.Singleton.LockAcquisitionTimeout         = TimeSpan.FromSeconds(10);
            config.Singleton.LockAcquisitionPollingInterval = TimeSpan.FromMilliseconds(500);

            IExtensionRegistry registry = config.GetService <IExtensionRegistry>();

            registry.RegisterExtension <ITriggerBindingProvider>(new TestTriggerAttributeBindingProvider());

            JobHost host = new JobHost(config);

            return(host);
        }
        private IHost CreateTestJobHost <TProg>(int hostId, Action <IHostBuilder> extraConfig = null)
        {
            TestJobActivator activator = new TestJobActivator(hostId);

            var hostBuilder = new HostBuilder()
                              .ConfigureDefaultTestHost <TProg>(b =>
            {
                b.UseHostId(TestHostId)
                .AddAzureStorage()
                .AddExtension <TestTriggerAttributeBindingProvider>();
                RuntimeStorageWebJobsBuilderExtensions.AddAzureStorageCoreServices(b);
            })
                              .ConfigureTestLogger()
                              .ConfigureServices(services =>
            {
                services.AddSingleton <IJobActivator>(activator);
                services.AddSingleton <INameResolver>(_resolver);
                services.Configure((QueuesOptions o) => o.MaxPollingInterval = TimeSpan.FromSeconds(2));
                services.Configure((SingletonOptions o) =>
                {
                    o.LockAcquisitionTimeout         = TimeSpan.FromSeconds(10);
                    o.LockAcquisitionPollingInterval = TimeSpan.FromMilliseconds(500);
                });
            });

            extraConfig?.Invoke(hostBuilder); // test hook gets final say to replace.

            IHost host = hostBuilder.Build();

            return(host);
        }