public GrpcTestFixture(Action <IServiceCollection>?initialConfigureServices = null) { LoggerFactory = new LoggerFactory(); Action <IServiceCollection> configureServices = services => { // Registers a service for tests to add new methods services.AddSingleton <DynamicGrpcServiceRegistry>(); }; _server = new InProcessTestServer <TStartup>(services => { initialConfigureServices?.Invoke(services); configureServices(services); }); _server.StartServer(); DynamicGrpc = _server.Host !.Services.GetRequiredService <DynamicGrpcServiceRegistry>(); AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); Client = new HttpClient(); Client.DefaultRequestVersion = new Version(2, 0); Client.BaseAddress = new Uri(_server.Url !); }
public GrpcTestFixture(Action <IServiceCollection>?initialConfigureServices = null) { LoggerFactory = new LoggerFactory(); Action <IServiceCollection> configureServices = services => { // Registers a service for tests to add new methods services.AddSingleton <DynamicGrpcServiceRegistry>(); }; _server = new InProcessTestServer <TStartup>(services => { initialConfigureServices?.Invoke(services); configureServices(services); }); _server.StartServer(); DynamicGrpc = _server.Host !.Services.GetRequiredService <DynamicGrpcServiceRegistry>(); #if !NET5_0 AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); #endif (Client, Handler) = CreateHttpCore(); }
public GrpcTestFixture( Action <IServiceCollection>?initialConfigureServices = null, Action <KestrelServerOptions, IDictionary <TestServerEndpointName, string> >?configureKestrel = null, TestServerEndpointName?defaultClientEndpointName = null) { LoggerFactory = new LoggerFactory(); Action <IServiceCollection> configureServices = services => { // Registers a service for tests to add new methods services.AddSingleton <DynamicGrpcServiceRegistry>(); }; _server = new InProcessTestServer <TStartup>( services => { initialConfigureServices?.Invoke(services); configureServices(services); }, (options, urls) => { if (configureKestrel != null) { configureKestrel(options, urls); return; } urls[TestServerEndpointName.Http2] = "http://127.0.0.1:50050"; options.ListenLocalhost(50050, listenOptions => { listenOptions.Protocols = HttpProtocols.Http2; }); urls[TestServerEndpointName.Http1] = "http://127.0.0.1:50040"; options.ListenLocalhost(50040, listenOptions => { listenOptions.Protocols = HttpProtocols.Http1; }); urls[TestServerEndpointName.Http2WithTls] = "https://127.0.0.1:50030"; options.ListenLocalhost(50030, listenOptions => { listenOptions.Protocols = HttpProtocols.Http2; var basePath = Path.GetDirectoryName(typeof(InProcessTestServer).Assembly.Location); var certPath = Path.Combine(basePath !, "server1.pfx"); listenOptions.UseHttps(certPath, "1111"); }); urls[TestServerEndpointName.Http1WithTls] = "https://127.0.0.1:50020"; options.ListenLocalhost(50020, listenOptions => { listenOptions.Protocols = HttpProtocols.Http1; var basePath = Path.GetDirectoryName(typeof(InProcessTestServer).Assembly.Location); var certPath = Path.Combine(basePath !, "server1.pfx"); listenOptions.UseHttps(certPath, "1111"); });