-
Notifications
You must be signed in to change notification settings - Fork 8
Migrate integration tests from TestServerBuilder to TestWebApplicationFactory #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 31 commits
6ac0dea
6af9aae
197e9e0
c5f63b7
d44de35
e4890f5
1fbb5a0
74fbf45
8d56749
d3317b7
a7443f4
5f953d9
381f7f6
b984d87
07a4c03
6740448
80e47d8
5f6fecb
e67407f
34535ad
f954915
459624d
ccd8ef7
6eba6ef
8e5f519
7bcfb2f
2e6b703
b93f305
1f6c2ed
7b07bc7
09a1244
28d9311
a6558e6
3c2b7f2
7750d47
8779577
16b6bbc
617f047
b585376
05d4eaf
5a6dd01
496fa60
f99bd36
629695a
fb87e28
0d5ba60
0275d1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2,13 +2,13 @@ | |||||
| using System.Net; | ||||||
| using BenchmarkDotNet.Attributes; | ||||||
| using Microsoft.AspNetCore.Builder; | ||||||
| using Microsoft.AspNetCore.Hosting; | ||||||
| using Microsoft.AspNetCore.HttpOverrides; | ||||||
| using Microsoft.AspNetCore.TestHost; | ||||||
| using Microsoft.AspNetCore.Mvc.Testing; | ||||||
| using Microsoft.Extensions.DependencyInjection; | ||||||
| using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; | ||||||
| using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; | ||||||
| using Sitecore.AspNetCore.SDK.RenderingEngine.Extensions; | ||||||
| using Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests; | ||||||
| using Sitecore.AspNetCore.SDK.TestData; | ||||||
| using Sitecore.AspNetCore.SDK.Tracking; | ||||||
| using Sitecore.AspNetCore.SDK.Tracking.VisitorIdentification; | ||||||
|
|
@@ -21,31 +21,30 @@ namespace Sitecore.AspNetCore.SDK.RenderingEngine.Benchmarks; | |||||
| [ExcludeFromCodeCoverage] | ||||||
| public class TrackingBenchmarks : IDisposable | ||||||
| { | ||||||
| private TestServer? _server; | ||||||
| private WebApplicationFactory<TestWebApplicationProgram>? _factory; | ||||||
| private HttpClient? _client; | ||||||
| private MockHttpMessageHandler? _mockClientHandler; | ||||||
| private RenderingEngineBenchmarks? _baseLineTestInstance; | ||||||
|
|
||||||
| [GlobalSetup(Target = nameof(RegularHomePageRequestWithTracking))] | ||||||
| public void TrackingBenchmarksSetup() | ||||||
| { | ||||||
| TestServerBuilder testHostBuilder = new(); | ||||||
| _mockClientHandler = new MockHttpMessageHandler(); | ||||||
| testHostBuilder | ||||||
| .ConfigureServices(builder => | ||||||
|
|
||||||
| _factory = new WebApplicationFactory<TestWebApplicationProgram>() | ||||||
| .WithWebHostBuilder(builder => | ||||||
| { | ||||||
| builder.Configure<ForwardedHeadersOptions>(options => | ||||||
| builder.ConfigureServices(services => | ||||||
| { | ||||||
| options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | | ||||||
| ForwardedHeaders.XForwardedProto; | ||||||
| }); | ||||||
|
|
||||||
| builder | ||||||
| .AddSitecoreLayoutService() | ||||||
| .AddHttpHandler("mock", _ => new HttpClient(_mockClientHandler) { BaseAddress = new Uri("http://layout.service") }) | ||||||
| .AsDefaultHandler(); | ||||||
| services.Configure<ForwardedHeadersOptions>(options => | ||||||
| { | ||||||
| options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | | ||||||
| ForwardedHeaders.XForwardedProto; | ||||||
| }); | ||||||
|
|
||||||
| builder.AddSitecoreRenderingEngine(options => | ||||||
| services.AddSitecoreLayoutService(); | ||||||
| services.AddHttpClient("mock").ConfigurePrimaryHttpMessageHandler(() => _mockClientHandler!); | ||||||
Krishanthaudayakumara marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| services.AddHttpClient("mock").ConfigurePrimaryHttpMessageHandler(() => _mockClientHandler!); | |
| services.AddHttpHandler(_mockClientHandler!); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used the same layout service builder pattern which used previously - Krishanthaudayakumara@5a6dd01
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the tracking benchmarks, the layout service registration is missing the connection to the 'mock' HttpClient. The layout service needs to be configured to use the mock handler via
.AddHttpHandler()method chain.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work, but I implemented register a mock HttpMessageHandler and configure the Sitecore layout service like previous here - Krishanthaudayakumara@16b6bbc