/// <summary> /// <para> /// Creates a TestServer instance using the MVC application defined by<typeparamref name="TStartup"/>. /// The startup code defined in <typeparamref name = "TStartup" /> will be executed to configure the application. /// </para> /// <para> /// This constructor will infer the application root directive by searching for a solution file tht matches the pattern /// <paramref name="solutionSearchPattern"/> and then appending the path <paramref name="solutionRelativePath"/> /// to the solution directory.The application root directory will be used to discover views and content files. /// </para> /// <para> /// The application assemblies will be loaded from the dependency context of the assembly containing /// <typeparamref name = "TStartup" />.This means that project dependencies of the assembly containing /// <typeparamref name = "TStartup" /> will be loaded as application assemblies. /// </para> /// </summary> /// <param name="solutionSearchPattern">The glob pattern to use when searching for a solution file by /// traversing up the folder hierarchy from the test execution folder.</param> /// <param name="solutionRelativePath">The path to the project folder relative to the solution file of your /// application. The folder of the first sln file that matches the <paramref name="solutionSearchPattern"/> /// found traversing up the folder hierarchy from the test execution folder is considered as the base path.</param> protected WebApplicationTestFixture(string solutionSearchPattern, string solutionRelativePath) { var builder = new MvcWebApplicationBuilder <TStartup>() .UseSolutionRelativeContentRoot(solutionRelativePath) .UseApplicationAssemblies(); ConfigureApplication(builder); _server = CreateServer(builder); Client = _server.CreateClient(); Client.BaseAddress = new Uri("http://localhost"); }
/// <summary> /// Gives a fixture an opportunity to configure the application before it gets built. /// </summary> /// <param name="builder">The <see cref="MvcWebApplicationBuilder{TStartup}"/> for the application.</param> protected virtual void ConfigureApplication(MvcWebApplicationBuilder <TStartup> builder) { }
/// <summary> /// Creates the <see cref="TestServer"/> with the bootstrapped application in <paramref name="builder"/>. /// </summary> /// <param name="builder">The <see cref="MvcWebApplicationBuilder{TStartup}"/> used to /// create the server.</param> /// <returns>The <see cref="TestServer"/> with the bootstrapped application.</returns> protected virtual TestServer CreateServer(MvcWebApplicationBuilder <TStartup> builder) { return(builder.Build()); }