Skip to content

Conversation

@Krishanthaudayakumara
Copy link
Collaborator

@Krishanthaudayakumara Krishanthaudayakumara commented Aug 7, 2025

Description / Motivation

Issue

Tests in the Sitecore ASP.NET Core SDK were failing when run on systems with non-US locales (e.g., Danish locale). The failures occurred because the tests were using hardcoded US date format expectations while the DateTagHelper implementation correctly uses CultureInfo.CurrentCulture when no specific culture is provided.

Root Cause

The test assertions were inconsistent with the actual implementation behavior:

  • Implementation: Uses CultureInfo.CurrentCulture when no culture is specified (line 65 in DateTagHelper.cs)
  • Tests: Expected hardcoded US format strings (e.g., "05/04/2012") regardless of system locale

This mismatch caused test failures when running on systems with different date formatting conventions (e.g., Danish locale uses "05-04-2012" format).

Solution

Updated test assertions to dynamically generate expected values using the current culture instead of hardcoded strings:

  1. Unit Tests (DateTagHelperFixture.cs):

    • Modified custom format tests to explicitly specify culture and generate expected values accordingly
    • Added parameterized tests for multiple cultures (en-US, da-DK, uk-UA)
  2. Integration Tests:

    • AllFieldTagHelpersFixture.cs: Use TestConstants.DateTimeValue.ToString("MM/dd/yyyy", CultureInfo.CurrentCulture)
    • DateFieldTagHelperFixture.cs: Generate expected format strings dynamically
    • RichTextFieldTagHelperFixture.cs: Use culture-aware date parsing and formatting
    • ViewFieldsBindingFixture.cs: Parse dates with invariant culture and format with current culture

Behavior

  • Tests now pass consistently regardless of the system locale
  • Implementation behavior remains unchanged (still correctly uses current culture)
  • Test coverage is improved with explicit multi-culture testing

This fix ensures the test suite is portable across different regional settings while maintaining the correct functionality of culture-aware date formatting.

Fixes #34

Testing

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

Terms

… test cultures

- Updated DateTagHelper to use CultureInfo.InvariantCulture when DateFormat is specified and no explicit Culture is set, ensuring consistent date output regardless of system locale.
- Explicitly set culture to en-US in RichTextFieldTagHelperFixture and other relevant integration test fixtures to make test expectations stable and independent of the developer's environment.
- Updated test assertions to use the correct culture where appropriate.
- Resolves test failures related to date formatting when running tests under non-US locales (e.g., da-DK).
@robearlam robearlam requested a review from Copilot August 8, 2025 00:15

This comment was marked as outdated.

…gHelperFixture.cs, extracting the culture selection logic into a separate variable for better readability in DateTagHelper.cs

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

Copy link
Member

@robearlam robearlam left a comment

Choose a reason for hiding this comment

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

Added a couple of inline comments, also you've made code changes in the DateTagHelper.cs but I'm not seeing any changes to the Unit Tests for that class. If you've changed functionality then there should be a related unit test added to ensure it continues to function as expected.

…- Convert DateTagHelper unit tests to use InlineData pattern with multiple cultures
…eFieldTagHelperFixture.cs, extracting the culture selection logic into a separate variable for better readability in DateTagHelper.cs"

This reverts commit 979e588.
…ine Data Approach

To main PR - Update date formatting tests to handle culture-specific formats - Inline Data Approach

This comment was marked as outdated.

@Krishanthaudayakumara Krishanthaudayakumara changed the title Ensure culture-invariant date formatting for explicit formats and set test cultures Fix culture-dependent date formatting tests to work with different system locales Aug 18, 2025

This comment was marked as outdated.

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 fixes culture-dependent date formatting tests that were failing on systems with non-US locales. The tests previously used hardcoded US date format expectations while the DateTagHelper implementation correctly uses the current system culture.

  • Updated unit tests to use parameterized testing with multiple cultures (en-US, da-DK, uk-UA)
  • Modified integration tests to dynamically generate expected date strings using current culture
  • Added explicit culture specification in date formatting tests to ensure consistent behavior

Reviewed Changes

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

Show a summary per file
File Description
DateTagHelperFixture.cs Converted hardcoded date format tests to parameterized tests with explicit culture handling
AllFieldTagHelpersFixture.cs Updated date field assertion to use current culture formatting
DateFieldTagHelperFixture.cs Changed hardcoded date strings to dynamically generated culture-aware formats
RichTextFieldTagHelperFixture.cs Added culture-aware date parsing and formatting for expected values
ViewFieldsBindingFixture.cs Implemented invariant culture parsing with current culture formatting

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

robearlam
robearlam previously approved these changes Sep 9, 2025
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.

Fix date related tests in project on non en-US-like environments

2 participants