You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by pa...@apache.org on 2026/07/10 13:15:10 UTC

(lucenenet) branch master updated: fix(ReplicatorTestCase): Replace deprecated WebHostBuilder with HostBuilder (#1411) (#1416)

This is an automated email from the ASF dual-hosted git repository.

paulirwin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git


The following commit(s) were added to refs/heads/master by this push:
     new 034c009d2 fix(ReplicatorTestCase): Replace deprecated WebHostBuilder with HostBuilder (#1411) (#1416)
034c009d2 is described below

commit 034c009d260a455e7a54385820daea4fd67ba28a
Author: Shashwat Sinha <76...@users.noreply.github.com>
AuthorDate: Fri Jul 10 18:45:05 2026 +0530

    fix(ReplicatorTestCase): Replace deprecated WebHostBuilder with HostBuilder (#1411) (#1416)
    
    Signed-off-by: Shashwat Sinha <sh...@gmail.com>
---
 .../ReplicatorTestCase.cs                          | 119 ++++++++++++---------
 1 file changed, 66 insertions(+), 53 deletions(-)

diff --git a/src/Lucene.Net.Tests.Replicator/ReplicatorTestCase.cs b/src/Lucene.Net.Tests.Replicator/ReplicatorTestCase.cs
index 4a80cdbb7..dd19ca49b 100644
--- a/src/Lucene.Net.Tests.Replicator/ReplicatorTestCase.cs
+++ b/src/Lucene.Net.Tests.Replicator/ReplicatorTestCase.cs
@@ -12,6 +12,7 @@
 using Microsoft.AspNetCore.Routing;
 using Microsoft.AspNetCore.TestHost;
 using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Hosting;
 #else
 using Lucene.Net.Replicator.Net;
 #endif
@@ -85,78 +86,90 @@ public static TestServer NewHttpServer(IReplicationService service, MockErrorCon
         {
             if (useStartupClass)
             {
-                var builder = new WebHostBuilder()
-                    .ConfigureServices(container =>
+                var hostBuilder = new HostBuilder()
+                    .ConfigureWebHost(webBuilder =>
                     {
-                        container.AddSingleton(service);
-                        container.AddSingleton(mockErrorConfig);
-                    });
+                        webBuilder.UseTestServer()
+                        .ConfigureServices(container =>
+                        {
+                            container.AddSingleton(service);
+                            container.AddSingleton(mockErrorConfig);
+                        });
 
-                if (useSynchronousIO)
-                {
-                    builder.UseStartup<SynchronousReplicationServlet>();
-                }
-                else
-                {
-                    builder.UseStartup<ReplicationServlet>();
-                }
+                        if (useSynchronousIO)
+                        {
+                            webBuilder.UseStartup<SynchronousReplicationServlet>();
+                        }
+                        else
+                        {
+                            webBuilder.UseStartup<ReplicationServlet>();
+                        }
+                    });
 
-                var server = new TestServer(builder);
+                var host = hostBuilder.Build();
+                host.Start();
+                var server = host.GetTestServer();
                 server.BaseAddress = new Uri("http://localhost" + ReplicationService.REPLICATION_CONTEXT);
                 return server;
             }
             else
             {
-                var builder = new WebHostBuilder()
-                    .ConfigureServices(container =>
+                var hostBuilder = new HostBuilder()
+                    .ConfigureWebHost(webBuilder =>
                     {
-                        container.AddRouting();
-                        container.AddSingleton(service);
-                        container.AddSingleton(mockErrorConfig);
-                        if (useSynchronousIO)
+                        webBuilder.UseTestServer()
+                        .ConfigureServices(container =>
                         {
-                            container.AddSingleton<SynchronousReplicationServiceMiddleware>();
-                            container.AddSingleton<EnableSynchronousIOMiddleware>();
-                        }
-                        else
+                            container.AddRouting();
+                            container.AddSingleton(service);
+                            container.AddSingleton(mockErrorConfig);
+                            if (useSynchronousIO)
+                            {
+                                container.AddSingleton<SynchronousReplicationServiceMiddleware>();
+                                container.AddSingleton<EnableSynchronousIOMiddleware>();
+                            }
+                            else
+                            {
+                                container.AddSingleton<ReplicationServiceMiddleware>();
+                            }
+                            container.AddSingleton<MockErrorMiddleware>();
+                        })
+                        .Configure(app =>
                         {
-                            container.AddSingleton<ReplicationServiceMiddleware>();
-                        }
-                        container.AddSingleton<MockErrorMiddleware>();
-                    })
-                    .Configure(app =>
-                    {
-                        app.UseRouting();
-
-                        // Middleware so we can mock a server exception and toggle the exception on and off.
-                        app.UseMiddleware<MockErrorMiddleware>();
+                            app.UseRouting();
 
-                        if (useSynchronousIO)
-                        {
-                            app.UseMiddleware<EnableSynchronousIOMiddleware>();
-                        }
+                            // Middleware so we can mock a server exception and toggle the exception on and off.
+                            app.UseMiddleware<MockErrorMiddleware>();
 
-                        app.UseEndpoints(endpoints =>
-                        {
-                            // This is to define the endpoint for Replicator.
-                            // All URLs with the pattern /replicate/{shard?}/{action?} terminate here and any middleware that
-                            // is expected to run for Replicator must be registered before this call.
-                            string pattern = ReplicationService.REPLICATION_CONTEXT + "/{shard?}/{action?}";
                             if (useSynchronousIO)
-                                endpoints.MapReplicator<SynchronousReplicationServiceMiddleware>(pattern);
-                            else
-                                endpoints.MapReplicator<ReplicationServiceMiddleware>(pattern);
+                            {
+                                app.UseMiddleware<EnableSynchronousIOMiddleware>();
+                            }
 
-                            endpoints.MapGet("/{controller?}/{action?}/{id?}", async context =>
+                            app.UseEndpoints(endpoints =>
                             {
-                                // This is just to demonstrate allowing requests to other services/controllers in the same
-                                // application. This isn't required, but is allowed.
-                                await context.Response.WriteAsync("Hello World!");
+                                // This is to define the endpoint for Replicator.
+                                // All URLs with the pattern /replicate/{shard?}/{action?} terminate here and any middleware that
+                                // is expected to run for Replicator must be registered before this call.
+                                string pattern = ReplicationService.REPLICATION_CONTEXT + "/{shard?}/{action?}";
+                                if (useSynchronousIO)
+                                    endpoints.MapReplicator<SynchronousReplicationServiceMiddleware>(pattern);
+                                else
+                                    endpoints.MapReplicator<ReplicationServiceMiddleware>(pattern);
+
+                                endpoints.MapGet("/{controller?}/{action?}/{id?}", async context =>
+                                {
+                                    // This is just to demonstrate allowing requests to other services/controllers in the same
+                                    // application. This isn't required, but is allowed.
+                                    await context.Response.WriteAsync("Hello World!");
+                                });
                             });
                         });
                     });
-                var server = new TestServer(builder);
-                return server;
+
+                var host = hostBuilder.Build();
+                host.Start();
+                return host.GetTestServer();
             }
         }