示例#1
0
 private TestApiServer(IHost host, TestApiServerOptions options, ILogger logger)
 {
     Guard.NotNull(host, nameof(host), "Requires a 'IHost' instance to start/stop the test API server");
     _host    = host;
     _options = options;
     _logger  = logger;
 }
示例#2
0
        /// <summary>
        /// Starts a new instance of the <see cref="TestApiServer"/> using the configurable <paramref name="options"/>.
        /// </summary>
        /// <param name="options">The configurable options to control the behavior of the test API server.</param>
        /// <param name="logger">The logger instance to include in the test API server to write diagnostic messages during the lifetime of the server.</param>
        /// <exception cref="ArgumentNullException">Thrown when the <paramref name="options"/> or <paramref name="logger"/> is <c>null</c>.</exception>
        public static async Task <TestApiServer> StartNewAsync(TestApiServerOptions options, ILogger logger)
        {
            Guard.NotNull(options, nameof(options), "Requires a set of configurable options to control the behavior of the test API server");
            Guard.NotNull(logger, nameof(logger), "Requires a logger instance to write diagnostic messages during the lifetime of the test API server");

            IHostBuilder builder = Host.CreateDefaultBuilder();

            options.ApplyOptions(builder);
            options.ConfigureServices(services =>
                                      services.AddLogging(logging => logging.AddProvider(new CustomLoggerProvider(logger))));

            IHost host   = builder.Build();
            var   server = new TestApiServer(host, options, logger);
            await host.StartAsync();

            return(server);
        }