public void ThenAllFunctionsShouldBeResolvable()
        {
            var functions     = GetFunctions();
            var builder       = new TestFunctionHostBuilder();
            var configuration = GetTestConfiguration();

            var startup = new Startup();

            startup.Configure(builder, configuration);
            // Have to register the function so container can attempt to resolve them
            foreach (var function in functions)
            {
                builder.Services.AddScoped(function);
            }

            var provider = builder.Services.BuildServiceProvider();

            foreach (var function in functions)
            {
                try
                {
                    var resolvedFunction = provider.GetService(function);
                    if (resolvedFunction == null)
                    {
                        throw new NullReferenceException("Function resolved to null");
                    }
                }
                catch (Exception ex)
                {
                    Assert.Fail($"Failed to resolved {function.Name}:\n{ex}");
                }
            }
        }
        public TestFunctionHost()
        {
            var builder       = new TestFunctionHostBuilder();
            var configuration = GetTestConfiguration();

            // Add default registrations
            var startup = new Startup();

            startup.Configure(builder, configuration);

            // Override relevant test registrations
            builder.Services
            .RemoveAll <ILoggerWrapper>()
            .RemoveAll <IRepository>()
            .RemoveAll <ISyncQueue>();

            builder.Services
            .AddScoped(provider => new ServiceFactory <ProcessEntityEvent>(provider))
            .AddScoped <Dfe.Spi.Common.UnitTesting.Infrastructure.LoggerWrapper>()
            .AddScoped <RepositoryStub>()
            .AddScoped <SyncQueueStub>()
            .AddScoped <ILoggerWrapper>(provider => provider.GetService <Dfe.Spi.Common.UnitTesting.Infrastructure.LoggerWrapper>())
            .AddScoped <IRepository>(provider => provider.GetService <RepositoryStub>())
            .AddScoped <ISyncQueue>(provider => provider.GetService <SyncQueueStub>());

            // Register functions (normally done by runtime)
            var allParameters = typeof(Startup).Assembly
                                .GetTypes()
                                .SelectMany(t => t.GetMethods())
                                .SelectMany(m => m.GetParameters());
            var matchingParameters = allParameters
                                     .Where(p => p.CustomAttributes.Any(a => a.AttributeType == typeof(HttpTriggerAttribute) ||
                                                                        a.AttributeType == typeof(QueueTriggerAttribute)))
                                     .ToArray();
            var functionTypes = matchingParameters
                                .Select(m => m.Member.DeclaringType)
                                .ToArray();

            foreach (var functionType in functionTypes)
            {
                builder.Services.AddScoped(functionType);
            }

            _serviceProvider = builder.Services.BuildServiceProvider();
        }
        public void ThenAllFunctionsShouldBeResolvable()
        {
            var functions     = GetFunctions();
            var builder       = new TestFunctionHostBuilder();
            var configuration = GetTestConfiguration();

            var startup = new Startup();

            startup.Configure(builder, configuration);
            // Have to register the function so container can attempt to resolve them
            foreach (var function in functions)
            {
                builder.Services.AddScoped(function);
            }
            var provider = builder.Services.BuildServiceProvider();

            foreach (var function in functions)
            {
                Assert.IsNotNull(provider.GetService(function),
                                 $"Failed to resolve {function.Name}");
            }
        }