Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
6ac0dea
Refactored TestWebApplicationFactory usage, updated Pages Fixtures, u…
robearlam Sep 12, 2025
6af9aae
Merge branch 'feat/36-TestWebApplicationFactoryMigration' into feat/3…
Krishanthaudayakumara Sep 12, 2025
197e9e0
Refactored TestWebApplicationFactory usage, updated Pages Fixtures, u…
Krishanthaudayakumara Sep 12, 2025
c5f63b7
Migrate ModelBindingFixture.cs
Krishanthaudayakumara Sep 12, 2025
d44de35
Migrate ModelBindingErrorHandlingFixture.cs
Krishanthaudayakumara Sep 12, 2025
e4890f5
Migrate CustomModelContextBindingFixture.cs
Krishanthaudayakumara Sep 12, 2025
1fbb5a0
Migrate CustomResolverBindingFixture.cs
Krishanthaudayakumara Sep 12, 2025
74fbf45
Migrate ViewFieldsBindingFixture.cs
Krishanthaudayakumara Sep 12, 2025
8d56749
Migrate custom render types fixtures
Krishanthaudayakumara Sep 12, 2025
d3317b7
Apply the same file-specific rename pattern to the Binding and Custom…
Krishanthaudayakumara Sep 16, 2025
a7443f4
migrate ForwardHeadersToLayoutServiceFixture
Krishanthaudayakumara Sep 16, 2025
5f953d9
Migrate Localization fixtures
Krishanthaudayakumara Sep 16, 2025
381f7f6
Revert "Migrate Localization fixtures"
Krishanthaudayakumara Sep 16, 2025
b984d87
Migrate Multisite fixture
Krishanthaudayakumara Sep 16, 2025
07a4c03
Migrate SearchOptimization fixtures
Krishanthaudayakumara Sep 16, 2025
6740448
Migrate TagHelper Fixtures
Krishanthaudayakumara Sep 16, 2025
80e47d8
Migrate RequestHeadersValidationFixture
Krishanthaudayakumara Sep 16, 2025
5f6fecb
Migrate ControllerMiddlewareFixture
Krishanthaudayakumara Sep 17, 2025
e67407f
Migrate ErrorHandlingFixture
Krishanthaudayakumara Sep 17, 2025
34535ad
Migrate GlobalMiddlewareFixture
Krishanthaudayakumara Sep 17, 2025
f954915
Migrate SitecoreLayoutClientBuilderExtensionsFixture
Krishanthaudayakumara Sep 17, 2025
459624d
Migtrate RequestDefaultsConfigurationFixture
Krishanthaudayakumara Sep 17, 2025
ccd8ef7
Remove unused package- RequestDefaultsConfigurationFixture
Krishanthaudayakumara Sep 17, 2025
6eba6ef
Migrate RequestExtensionsFixture
Krishanthaudayakumara Sep 17, 2025
8e5f519
Migrate RequestMappingFixture
Krishanthaudayakumara Sep 17, 2025
7bcfb2f
Migrate Tracking Fixtures
Krishanthaudayakumara Sep 18, 2025
2e6b703
Migrate Localization fixtures
Krishanthaudayakumara Sep 18, 2025
b93f305
Restructure methods to fix warnings
Krishanthaudayakumara Sep 18, 2025
1f6c2ed
Migrate ExperienceEditor fixtures
Krishanthaudayakumara Sep 18, 2025
7b07bc7
Migrate Benchmarks tests
Krishanthaudayakumara Sep 18, 2025
09a1244
revert syntax changes
Krishanthaudayakumara Sep 22, 2025
28d9311
Explicitly start the host without creating an unused client
Krishanthaudayakumara Sep 22, 2025
a6558e6
test(fixture): reuse TestWebApplicationFactory across integration tests
Krishanthaudayakumara Sep 23, 2025
3c2b7f2
add default response and start TestServer in MultisiteFixture and set…
Krishanthaudayakumara Sep 26, 2025
7750d47
Migrate integration test fixtures to shared TestWebApplicationFactory
Krishanthaudayakumara Sep 30, 2025
8779577
Use the same approach TestServerBuilder used: register a simple mock …
Krishanthaudayakumara Sep 30, 2025
16b6bbc
wire layout service to mock HttpClient in RenderingEngine benchmarks
Krishanthaudayakumara Sep 30, 2025
617f047
Address Copilot reviews - Use the same approach TestServerBuilder used.
Krishanthaudayakumara Sep 30, 2025
b585376
use app.Start() in TestWebApplicationProgram
Krishanthaudayakumara Sep 30, 2025
05d4eaf
Add comment explaining variable startedServer
Krishanthaudayakumara Sep 30, 2025
5a6dd01
Use the same layout-service builder pattern previously used in Tracki…
Krishanthaudayakumara Sep 30, 2025
496fa60
Minor change of new line after single line comment
Krishanthaudayakumara Sep 30, 2025
f99bd36
Merge pull request #39 - Fixes regarding to Copilot reviews
Krishanthaudayakumara Sep 30, 2025
629695a
use _ = _factory.Server; to clearly indicate the variable is intentio…
Krishanthaudayakumara Sep 30, 2025
fb87e28
using the more modern collection expression syntax for consistency i…
Krishanthaudayakumara Sep 30, 2025
0d5ba60
Refactor RequestHeadersValidationFixture to implement similar constru…
Krishanthaudayakumara Sep 30, 2025
0275d1b
Merge pull request #40 Fixes regarding to copilot review
Krishanthaudayakumara Sep 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Diagnostics.CodeAnalysis;
using BenchmarkDotNet.Attributes;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.DependencyInjection;
using NSubstitute;
Expand All @@ -17,37 +19,42 @@ namespace Sitecore.AspNetCore.SDK.RenderingEngine.Benchmarks;
[ExcludeFromCodeCoverage]
public class ExperienceEditorMiddlewareBenchmarks : IDisposable
{
private readonly TestServer _server;
private readonly WebApplicationFactory<TestWebApplicationProgram> _factory;
private readonly HttpClient _client;
private readonly StringContent _content;
private RenderingEngineBenchmarks? _baseLineTestInstance;

public ExperienceEditorMiddlewareBenchmarks()
{
TestServerBuilder testHostBuilder = new();
testHostBuilder
.ConfigureServices(builder =>
WebApplicationFactory<TestWebApplicationProgram> factory = new TestWebApplicationFactory<TestWebApplicationProgram>();

_factory = factory.WithWebHostBuilder(builder =>
{
builder.ConfigureTestServices(services =>
{
builder.AddSingleton(Substitute.For<ISitecoreLayoutClient>());
builder.AddSitecoreRenderingEngine(options =>
services.AddRouting();

services.AddSingleton(Substitute.For<ISitecoreLayoutClient>());

services.AddSitecoreRenderingEngine(options =>
{
options.AddDefaultComponentRenderer();
}).WithExperienceEditor(options =>
{
options.Endpoint = TestConstants.EEMiddlewarePostEndpoint;
options.JssEditingSecret = TestConstants.JssEditingSecret;
});
})
.Configure(app =>
});

builder.Configure(app =>
{
app.UseSitecoreExperienceEditor();
app.UseRouting();
app.UseSitecoreRenderingEngine();
});
});

_server = testHostBuilder.BuildServer(new Uri("http://localhost"));

_client = _server.CreateClient();
_client = _factory.CreateClient();
_content = new StringContent(TestConstants.EESampleRequest);
}

Expand Down Expand Up @@ -76,7 +83,7 @@ public async Task RegularExperienceEditorRequestHandling()

public void Dispose()
{
_server.Dispose();
_factory.Dispose();
_client.Dispose();
_content.Dispose();
_baseLineTestInstance?.Dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
using System.Net;
using BenchmarkDotNet.Attributes;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.TestHost;
using Microsoft.AspNetCore.Hosting;
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.LayoutService.Client.Interfaces;
using Sitecore.AspNetCore.SDK.RenderingEngine.Extensions;
using Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests;
using Sitecore.AspNetCore.SDK.TestData;

namespace Sitecore.AspNetCore.SDK.RenderingEngine.Benchmarks;
Expand All @@ -16,38 +18,42 @@ namespace Sitecore.AspNetCore.SDK.RenderingEngine.Benchmarks;
[ExcludeFromCodeCoverage]
public class RenderingEngineBenchmarks : IDisposable
{
private TestServer? _server;
private WebApplicationFactory<TestWebApplicationProgram>? _factory;
private HttpClient? _client;
private MockHttpMessageHandler? _mockClientHandler;

[GlobalSetup]
public void Setup()
{
TestServerBuilder testHostBuilder = new();
_mockClientHandler = new MockHttpMessageHandler();
testHostBuilder
.ConfigureServices(builder =>
{
builder
.AddSitecoreLayoutService()
.AddHttpHandler("mock", _ => new HttpClient(_mockClientHandler) { BaseAddress = new Uri("http://layout.service") })
.AsDefaultHandler();
{
_mockClientHandler = new MockHttpMessageHandler();

builder.AddSitecoreRenderingEngine(options =>
_factory = new WebApplicationFactory<TestWebApplicationProgram>()
.WithWebHostBuilder(builder =>
{
options.AddDefaultComponentRenderer();
});
})
.Configure(app =>
{
app.UseRouting();
app.UseSitecoreRenderingEngine();
});
builder.ConfigureServices(services =>
{
services.AddRouting();

_server = testHostBuilder.BuildServer(new Uri("http://localhost"));
ISitecoreLayoutClientBuilder layoutBuilder = services.AddSitecoreLayoutService();
layoutBuilder
.AddHttpHandler("mock", _ => new HttpClient(_mockClientHandler!) { BaseAddress = new Uri("http://layout.service") })
.AsDefaultHandler();

_client = _server.CreateClient();
}
services.AddSitecoreRenderingEngine(options =>
{
options.AddDefaultComponentRenderer();
});
});

builder.Configure(app =>
{
app.UseRouting();
app.UseSitecoreRenderingEngine();
});
});

_client = _factory.CreateClient();
}

[Benchmark(Baseline = true)]
public async Task RegularHomePageRequest()
Expand All @@ -71,8 +77,8 @@ public async Task RegularHomePageRequest()

public void Dispose()
{
_server?.Dispose();
_client?.Dispose();
_factory?.Dispose();
_mockClientHandler?.Dispose();
GC.SuppressFinalize(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
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.LayoutService.Client.Interfaces;
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;
Expand All @@ -21,31 +22,33 @@ 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;
});
services.Configure<ForwardedHeadersOptions>(options =>
{
options.ForwardedHeaders = ForwardedHeaders.XForwardedFor |
ForwardedHeaders.XForwardedProto;
});

builder
.AddSitecoreLayoutService()
.AddHttpHandler("mock", _ => new HttpClient(_mockClientHandler) { BaseAddress = new Uri("http://layout.service") })
.AsDefaultHandler();
ISitecoreLayoutClientBuilder layoutBuilder = services.AddSitecoreLayoutService();
layoutBuilder
.AddHttpHandler("mock", _ => new HttpClient(_mockClientHandler!) { BaseAddress = new Uri("http://layout.service") })
.AsDefaultHandler();

builder.AddSitecoreRenderingEngine(options =>
services.AddSitecoreRenderingEngine(options =>
{
options.AddDefaultComponentRenderer();
}).ForwardHeaders(options =>
Expand All @@ -66,22 +69,15 @@ public void TrackingBenchmarksSetup()
})
.WithTracking();

builder.AddSitecoreVisitorIdentification(options =>
{
options.SitecoreInstanceUri = new Uri("http://layout.service");
services.AddSitecoreVisitorIdentification(options =>
{
options.SitecoreInstanceUri = new Uri("http://layout.service");
});
services.AddSingleton<IStartupFilter, PipelineStartupFilter>();
});
})
.Configure(app =>
{
app.UseForwardedHeaders();
app.UseRouting();
app.UseSitecoreVisitorIdentification();
app.UseSitecoreRenderingEngine();
});

_server = testHostBuilder.BuildServer(new Uri("http://localhost"));

_client = _server.CreateClient();
_client = _factory.CreateClient();
}

[GlobalSetup(Target = nameof(RegularHomePageRequest))]
Expand Down Expand Up @@ -119,10 +115,25 @@ public async Task RegularHomePageRequestWithTracking()

public void Dispose()
{
_server?.Dispose();
_client?.Dispose();
_factory?.Dispose();
_mockClientHandler?.Dispose();
_baseLineTestInstance?.Dispose();
GC.SuppressFinalize(this);
}

private class PipelineStartupFilter : IStartupFilter
{
public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)
{
return app =>
{
app.UseForwardedHeaders();
app.UseRouting();
app.UseSitecoreVisitorIdentification();
app.UseSitecoreRenderingEngine();
next(app);
};
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Net;
using AwesomeAssertions;
using HtmlAgilityPack;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.AspNetCore.TestHost;
using Sitecore.AspNetCore.SDK.AutoFixture.Mocks;
using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions;
Expand All @@ -10,31 +11,32 @@

namespace Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.Fixtures.Binding;

public class ComplexModelBindingFixture : IDisposable
public class ComplexModelBindingFixture : IClassFixture<TestWebApplicationFactory<TestWebApplicationProgram>>, IDisposable
{
private readonly TestServer _server;
private readonly MockHttpMessageHandler _mockClientHandler;
private readonly MockHttpMessageHandler _mockClientHandler = new();
private readonly Uri _layoutServiceUri = new("http://layout.service");

public ComplexModelBindingFixture()
private readonly WebApplicationFactory<TestWebApplicationProgram> _factory;

public ComplexModelBindingFixture(TestWebApplicationFactory<TestWebApplicationProgram> factory)
{
TestServerBuilder testHostBuilder = new();
_mockClientHandler = new MockHttpMessageHandler();
testHostBuilder
.ConfigureServices(builder =>
_factory = factory.WithWebHostBuilder(builder =>
{
builder.ConfigureTestServices(services =>
{
builder
services
.AddSitecoreLayoutService()
.AddHttpHandler("mock", _ => new HttpClient(_mockClientHandler) { BaseAddress = _layoutServiceUri })
.AsDefaultHandler();
builder.AddSitecoreRenderingEngine(options =>
services.AddSitecoreRenderingEngine(options =>
{
options
.AddModelBoundView<ComponentModels.ComplexComponent>(name => name.Equals("Complex-Component", StringComparison.OrdinalIgnoreCase), "ComplexComponent")
.AddDefaultComponentRenderer();
});
})
.Configure(app =>
});

builder.Configure(app =>
{
app.UseRouting();
app.UseSitecoreRenderingEngine();
Expand All @@ -43,8 +45,10 @@ public ComplexModelBindingFixture()
endpoints.MapDefaultControllerRoute();
});
});
});

_server = testHostBuilder.BuildServer(new Uri("http://localhost"));
// Accessing _factory.Server forces the TestServer to start. The variable is unused; this is intentional.
_ = _factory.Server;
}

[Fact]
Expand All @@ -57,7 +61,7 @@ public async Task SitecoreLayoutModelBinders_BindDataCorrectly()
Content = new StringContent(Serializer.Serialize(CannedResponses.WithNestedPlaceholder))
});

HttpClient client = _server.CreateClient();
HttpClient client = _factory.CreateClient();

// Act
string response = await client.GetStringAsync(new Uri("/", UriKind.Relative));
Expand Down Expand Up @@ -103,8 +107,8 @@ public async Task SitecoreLayoutModelBinders_BindDataCorrectly()

public void Dispose()
{
_server.Dispose();
_mockClientHandler.Dispose();
_factory.Dispose();
GC.SuppressFinalize(this);
}
}
Loading