public override Task Start(CancellationToken token)
            {
                endpoint = new TestableFunctionEndpoint(context =>
                {
                    var functionEndpointConfiguration = new StorageQueueTriggeredEndpointConfiguration(Name);

                    // Tests are not exercising pub/sub and processing pipeline is the same as with the regular endpoints (message-driven pub/sub should work as usual)
                    functionEndpointConfiguration.Transport.DisablePublishing();

                    var endpointConfiguration = functionEndpointConfiguration.AdvancedConfiguration;

                    endpointConfiguration.TypesToIncludeInScan(functionComponentType.GetTypesScopedByTestClass());

                    endpointConfiguration.Recoverability()
                    .Immediate(i => i.NumberOfRetries(0))
                    .Delayed(d => d.NumberOfRetries(0))
                    .Failed(c => c
                            // track messages sent to the error queue to fail the test
                            .OnMessageSentToErrorQueue(failedMessage =>
                    {
                        scenarioContext.FailedMessages.AddOrUpdate(
                            Name,
                            new[] { failedMessage },
                            (_, fm) =>
                        {
                            var messages = fm.ToList();
                            messages.Add(failedMessage);
                            return(messages);
                        });
                        return(Task.CompletedTask);
                    }));

                    endpointConfiguration.RegisterComponents(c => c.RegisterSingleton(scenarioContext.GetType(), scenarioContext));

                    configurationCustomization(functionEndpointConfiguration);
                    return(functionEndpointConfiguration);
                });

                return(Task.CompletedTask);
            }
        public async Task Should_load_handlers_from_assembly()
        {
            // The message handler assembly shouldn't be loaded at this point because there is no reference in the code to it.
            Assert.False(AppDomain.CurrentDomain.GetAssemblies().Any(a => a.FullName == "Testing.Handlers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"));

            SettingsHolder settings = null;
            var            endpoint = new TestableFunctionEndpoint(context =>
            {
                var configuration = new StorageQueueTriggeredEndpointConfiguration("assemblyTest");
                configuration.UseSerialization <XmlSerializer>();
                configuration.Transport.DisablePublishing();
                configuration.EndpointConfiguration.UsePersistence <InMemoryPersistence>();

                settings = configuration.AdvancedConfiguration.GetSettings();
                return(configuration);
            })
            {
                AssemblyDirectoryResolver = _ => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ExternalHandlers")
            };


            // we need to process an actual message to have the endpoint being created
            await endpoint.Process(GenerateMessage(), new ExecutionContext());

            // The message handler assembly should be loaded now because scanning should find and load the handler assembly
            Assert.True(AppDomain.CurrentDomain.GetAssemblies().Any(a => a.FullName == "Testing.Handlers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"));

            // Verify the handler and message type have been identified and loaded:
            var registry         = settings.Get <MessageHandlerRegistry>();
            var dummyMessageType = registry.GetMessageTypes().FirstOrDefault(t => t.FullName == "Testing.Handlers.DummyMessage");

            Assert.NotNull(dummyMessageType);
            var dummyMessageHandler = registry.GetHandlersFor(dummyMessageType).SingleOrDefault();

            Assert.AreEqual("Testing.Handlers.DummyMessageHandler", dummyMessageHandler.HandlerType.FullName);

            // ensure the assembly is loaded into the right context
            Assert.AreEqual(AssemblyLoadContext.GetLoadContext(Assembly.GetExecutingAssembly()), AssemblyLoadContext.GetLoadContext(dummyMessageType.Assembly));
        }