Skip to content

Conversation

@Krishanthaudayakumara
Copy link
Collaborator

@Krishanthaudayakumara Krishanthaudayakumara commented Sep 19, 2025

Description / Motivation

This PR removes the legacy TestServerBuilder usage from the test and benchmark suites and migrates integration tests to the WebApplicationFactory<TestWebApplicationProgram> pattern (TestWebApplicationFactory). It preserves each fixture’s middleware and service ordering (rendering engine, experience editor, tracking, localization, forwarded headers, visitor identification, etc.) and keeps per-test substitutes/mock handlers where tests rely on specific layout responses.

Key changes

  • Replaced TestServerBuilder/TestServer with WebApplicationFactory<TestWebApplicationProgram> in all integration tests and benchmarks.
  • Preserved and validated middleware ordering per-fixture (kept attribute-based rendering behavior by omitting global UseSitecoreRenderingEngine where necessary).
  • Replaced direct TestServer.CreateClient()/Services usage with factory.CreateClient()/factory.Services and updated disposal.
    Added/kept per-test ISitecoreLayoutClient and ISitecoreLayoutSerializer substitutes where fixtures require specific SitecoreLayoutResponse content (e.g., Experience Editor cases that map databaseName = "master").
  • Migrated benchmarks to use WebApplicationFactory and registered mock HttpMessageHandlers via HttpClientFactory for consistent handler injection.
  • Fixed compilation issues and runtime startup ordering (ensuring TestServerDefaults runs before per-fixture mock registrations so mocks are not overwritten).
  • Minor style/analyzer warnings remain (XML docs/usings/ordering); these are low-risk and can be cleaned in a follow-up.

Fixes #36

Testing

  • The Unit & Intergration tests are passing.
  • I have added the necessary tests to cover my changes.

Terms

robearlam and others added 30 commits September 12, 2025 15:05
Copilot AI review requested due to automatic review settings September 19, 2025 08:21
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR migrates integration tests from the legacy TestServerBuilder pattern to the standard WebApplicationFactory<TestWebApplicationProgram> pattern for ASP.NET Core integration testing. The migration preserves middleware ordering and per-test service configuration while modernizing the test infrastructure.

  • Replaced TestServerBuilder/TestServer with WebApplicationFactory<TestWebApplicationProgram> across all integration tests and benchmarks
  • Preserved middleware and service ordering for each test fixture while updating configuration patterns
  • Migrated benchmarks to use the new factory pattern with proper dependency injection

Reviewed Changes

Copilot reviewed 47 out of 47 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
TestWebApplicationProgram.cs New test program entry point for WebApplicationFactory
TrackingProxyFixture.cs Migrated tracking proxy tests with preserved middleware ordering
TrackingFixture.cs Updated tracking tests to use factory pattern
AttributeBasedTrackingFixture.cs Converted attribute-based tracking tests
Various TagHelper fixtures Migrated all tag helper test fixtures to factory pattern
Various other test fixtures Updated remaining test fixtures including localization, multisite, and experience editor tests
Benchmark files Updated benchmark classes to use WebApplicationFactory pattern

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 47 out of 47 changed files in this pull request and generated 4 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 47 out of 47 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

…ISitecoreLayoutClient singleton instead of constructing a sampleRequest/sampleResponse.- ExperienceEditorCustomRoutingFixture.cs
- Use the same approach TestServerBuilder used: register a simple mock ISitecoreLayoutClient singleton instead of constructing a sampleRequest/sampleResponse.- ExperienceEditorCustomRoutingFixture.cs
- wire layout service to mock HttpClient in RenderingEngine benchmarks
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 47 out of 47 changed files in this pull request and generated 5 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 47 out of 47 changed files in this pull request and generated 5 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

- use _ = _factory.Server; to clearly indicate the variable is intentionally 
- using the more modern collection expression syntax for consistency in EdgeSitemapProxyFixture
- Refactor RequestHeadersValidationFixture to implement similar constructor pattern like other fixtures
@jballe
Copy link
Contributor

jballe commented Dec 2, 2025

I think it is looking fine, when will it be merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update Tests to follow updated mocking approach

3 participants