예제 #1
0
        protected override ITestFrameworkExecutor CreateExecutor(AssemblyName assemblyName)
        {
            IHost?host = null;

            try
            {
                var startup = StartupLoader.CreateStartup(assemblyName);
                if (startup == null)
                {
                    return(new XunitTestFrameworkExecutor(assemblyName, SourceInformationProvider, DiagnosticMessageSink));
                }

                var hostBuilder = StartupLoader.ConfigureHost(new HostBuilder(), startup);

                StartupLoader.ConfigureServices(hostBuilder, startup);

                host = hostBuilder
                       .ConfigureServices(services =>
                                          services
                                          .AddSingleton <ITestOutputHelperAccessor, TestOutputHelperAccessor>()
                                          .AddSingleton <IMessageSink>(DiagnosticMessageSink))
                       .Build();

                StartupLoader.Configure(host.Services, startup);

                return(new DependencyInjectionTestFrameworkExecutor(host, null,
                                                                    assemblyName, SourceInformationProvider, DiagnosticMessageSink));
            }
            catch (Exception e)
            {
                return(new DependencyInjectionTestFrameworkExecutor(host, e,
                                                                    assemblyName, SourceInformationProvider, DiagnosticMessageSink));
            }
        }
예제 #2
0
        protected override ITestFrameworkExecutor CreateExecutor(AssemblyName assemblyName)
        {
            IHost?host = null;

            try
            {
                var startup = StartupLoader.CreateStartup(StartupLoader.GetStartupType(assemblyName));
                if (startup == null)
                {
                    return(new XunitTestFrameworkExecutor(assemblyName, SourceInformationProvider, DiagnosticMessageSink));
                }

                var hostBuilder = StartupLoader.CreateHostBuilder(startup, assemblyName) ??
                                  new HostBuilder()
                                  .ConfigureHostConfiguration(builder => builder.AddInMemoryCollection(new Dictionary <string, string> {
                    { HostDefaults.ApplicationKey, assemblyName.Name ! }
                }));

                StartupLoader.ConfigureHost(hostBuilder, startup);

                StartupLoader.ConfigureServices(hostBuilder, startup);

                host = hostBuilder.ConfigureServices(services => services
                                                     .AddSingleton(DiagnosticMessageSink)
                                                     .TryAddSingleton <ITestOutputHelperAccessor, TestOutputHelperAccessor>())
                       .Build();

                StartupLoader.Configure(host.Services, startup);

                return(new DependencyInjectionTestFrameworkExecutor(host, null,
                                                                    assemblyName, SourceInformationProvider, DiagnosticMessageSink));
            }