Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
ccc68c7
Ensure culture-invariant date formatting for explicit formats and set…
Krishanthaudayakumara Aug 6, 2025
979e588
Changes on copilot review - use en-US culture for test in DateFieldTa…
Krishanthaudayakumara Aug 11, 2025
30986a2
Move the formatCulture - formattedDate logic inside the ternary operator
Krishanthaudayakumara Aug 11, 2025
debfcde
Refactor culture selection logic with formatCulture
Krishanthaudayakumara Aug 11, 2025
c1b531f
fix: Update date formatting tests to handle culture-specific formats …
Krishanthaudayakumara Aug 13, 2025
f98096b
REmove manual culture setting
Krishanthaudayakumara Aug 13, 2025
6c28432
Revert "Refactor culture selection logic with formatCulture"
Krishanthaudayakumara Aug 14, 2025
5477975
Revert "Move the formatCulture - formattedDate logic inside the terna…
Krishanthaudayakumara Aug 14, 2025
b2ddb2a
Revert "Changes on copilot review - use en-US culture for test in Dat…
Krishanthaudayakumara Aug 14, 2025
47fe2db
Revert "Ensure culture-invariant date formatting for explicit formats…
Krishanthaudayakumara Aug 14, 2025
48c5743
Undo the previous changes - Date format culture invariant
Krishanthaudayakumara Aug 18, 2025
be5c60c
Refactor: use [InlineAutoNSubstituteData] attributes and receive dep…
Krishanthaudayakumara Aug 18, 2025
87488db
Update date formatting tests to handle culture-specific formats - Inl…
Krishanthaudayakumara Aug 18, 2025
f2444c7
Merge branch 'main' into fix/date-format-culture-invariant
Krishanthaudayakumara Sep 9, 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,4 +1,5 @@
using System.Net;
using System.Globalization;
using System.Net;
using AwesomeAssertions;
using HtmlAgilityPack;
using Microsoft.AspNetCore.TestHost;
Expand All @@ -18,7 +19,7 @@

public ViewFieldsBindingFixture()
{
TestServerBuilder testHostBuilder = new();

Check warning on line 22 in tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Binding/ViewFieldsBindingFixture.cs

View workflow job for this annotation

GitHub Actions / build / build

'TestServerBuilder' is obsolete: 'This class is deprecated as this is based on the old .NET Core 3.0 approach app initialisation approach. Use `TestWebApplicationFactory` approach instead.'
_mockClientHandler = new MockHttpMessageHandler();
testHostBuilder
.ConfigureServices(builder =>
Expand Down Expand Up @@ -75,7 +76,8 @@
sectionNode.ChildNodes.First(n => n.Name.Equals("p", StringComparison.OrdinalIgnoreCase)).InnerText
.Should().BeEmpty();

sectionNode.ChildNodes.First(n => n.Name.Equals("textarea", StringComparison.OrdinalIgnoreCase)).InnerText.Should().Contain("12/12/2019");
DateTime expectedDate = DateTime.Parse("12.12.19", CultureInfo.InvariantCulture);
sectionNode.ChildNodes.First(n => n.Name.Equals("textarea", StringComparison.OrdinalIgnoreCase)).InnerText.Should().Contain(expectedDate.ToString("MM/dd/yyyy", CultureInfo.CurrentCulture));

sectionNode.ChildNodes.First(n => n.Name.Equals("span", StringComparison.OrdinalIgnoreCase)).InnerHtml
.Should().Be(TestConstants.TestMultilineFieldValue.Replace(Environment.NewLine, "<br>", StringComparison.OrdinalIgnoreCase));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public async Task ComponentWithAllFieldTypes_RendersFieldsCorrectly()
sectionNode.ChildNodes.First(n => n.Name.Equals("div", StringComparison.OrdinalIgnoreCase) && n.Id.Equals("div5", StringComparison.OrdinalIgnoreCase)).InnerHtml
.Should().Be(TestConstants.AllFieldsImageValue);
sectionNode.ChildNodes.First(n => n.Name.Equals("div", StringComparison.OrdinalIgnoreCase) && n.Id.Equals("div6", StringComparison.OrdinalIgnoreCase)).InnerHtml
.Should().Be(TestConstants.DateFieldValue);
.Should().Be(TestConstants.DateTimeValue.ToString("MM/dd/yyyy", CultureInfo.CurrentCulture));
sectionNode.ChildNodes.First(n => n.Name.Equals("div", StringComparison.OrdinalIgnoreCase) && n.Id.Equals("div7", StringComparison.OrdinalIgnoreCase)).InnerHtml
.Should().Be(TestConstants.MediaLibraryItemImageFieldValue);
sectionNode.ChildNodes.First(n => n.Name.Equals("div", StringComparison.OrdinalIgnoreCase) && n.Id.Equals("div8", StringComparison.OrdinalIgnoreCase)).InnerHtml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ public async Task DateTagHelper_GeneratesProperDate()
HtmlNode? sectionNode = doc.DocumentNode.ChildNodes.First(n => n.HasClass("component-with-dates"));

// Assert
sectionNode.ChildNodes[1].InnerHtml.Should().Be("05/04/2012");
sectionNode.ChildNodes[3].InnerHtml.Should().Be("05/04/2012 00:00:00");
sectionNode.ChildNodes[1].InnerHtml.Should().Be(TestConstants.DateTimeValue.ToString("MM/dd/yyyy", CultureInfo.CurrentCulture));
sectionNode.ChildNodes[3].InnerHtml.Should().Be(TestConstants.DateTimeValue.ToString("MM/dd/yyyy HH:mm:ss", CultureInfo.CurrentCulture));
sectionNode.ChildNodes[5].InnerHtml.Should().Be(TestConstants.DateTimeValue.ToString(CultureInfo.CurrentCulture));
sectionNode.ChildNodes[9].InnerHtml.Should().Contain("04.05.2012");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Net;
using System.Globalization;
using System.Net;
using System.Text.Encodings.Web;
using AwesomeAssertions;
using HtmlAgilityPack;
Expand Down Expand Up @@ -70,7 +71,8 @@ public async Task RichTextFieldTagHelper_DoesNotResetOtherTagHelperOutput()

// Assert
// check scenario that RichTextTagHelper does not reset values of another helpers.
sectionNode.ChildNodes.First(n => n.Name.Equals("textarea", StringComparison.OrdinalIgnoreCase)).InnerText.Should().Contain("12/12/2019");
DateTime expectedDate = DateTime.Parse("12.12.19", CultureInfo.InvariantCulture);
sectionNode.ChildNodes.First(n => n.Name.Equals("textarea", StringComparison.OrdinalIgnoreCase)).InnerText.Should().Contain(expectedDate.ToString("MM/dd/yyyy", CultureInfo.CurrentCulture));
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,23 +123,26 @@ public void Process_ScDateTagWithEmptyValueInForAttribute_GeneratesEmptyOutput(
}

[Theory]
[AutoNSubstituteData]
public void Process_ScDateTagWithCustomFormat_GeneratesCustomDateFormatOutput(
DateTagHelper sut,
TagHelperContext tagHelperContext,
TagHelperOutput tagHelperOutput)
[InlineAutoNSubstituteData("en-US")]
[InlineAutoNSubstituteData("da-DK")]
[InlineAutoNSubstituteData("uk-UA")]
public void Process_ScDateTagWithCustomFormat_GeneratesCustomDateFormatOutput(string cultureName, DateTagHelper sut, TagHelperContext tagHelperContext, TagHelperOutput tagHelperOutput)
{
// Arrange
CultureInfo testCulture = new CultureInfo(cultureName);
const string dateFormat = "MM/dd/yyyy H:mm";

tagHelperOutput.TagName = RenderingEngineConstants.SitecoreTagHelpers.DateHtmlTag;
sut.DateFormat = dateFormat;
sut.Culture = cultureName;
sut.For = GetModelExpression(new DateField(_date));

// Act
sut.Process(tagHelperContext, tagHelperOutput);

// Assert
tagHelperOutput.Content.GetContent().Should().Be(_date.ToString(dateFormat, CultureInfo.InvariantCulture));
string expected = _date.ToString(dateFormat, testCulture);
tagHelperOutput.Content.GetContent().Should().Be(expected);
}

[Theory]
Expand Down Expand Up @@ -258,23 +261,26 @@ public void Process_ScDateTagWithAspDataAttributeWithEmptyValueInForAttribute_Ge
}

[Theory]
[AutoNSubstituteData]
public void Process_ScDateTagWithAspDataAttributeWithCustomFormat_GeneratesCustomDateFormatOutput(
DateTagHelper sut,
TagHelperContext tagHelperContext,
TagHelperOutput tagHelperOutput)
[InlineAutoNSubstituteData("en-US")]
[InlineAutoNSubstituteData("da-DK")]
[InlineAutoNSubstituteData("uk-UA")]
public void Process_ScDateTagWithAspDataAttributeWithCustomFormat_GeneratesCustomDateFormatOutput(string cultureName, DateTagHelper sut, TagHelperContext tagHelperContext, TagHelperOutput tagHelperOutput)
{
// Arrange
CultureInfo testCulture = new CultureInfo(cultureName);
string dateFormat = "MM/dd/yyyy H:mm";

tagHelperOutput.TagName = RenderingEngineConstants.SitecoreTagHelpers.DateHtmlTag;
sut.DateFormat = dateFormat;
sut.Culture = cultureName;
sut.DateModel = new DateField(_date);

// Act
sut.Process(tagHelperContext, tagHelperOutput);

// Assert
tagHelperOutput.Content.GetContent().Should().Be(_date.ToString(dateFormat, CultureInfo.InvariantCulture));
string expected = _date.ToString(dateFormat, testCulture);
tagHelperOutput.Content.GetContent().Should().Be(expected);
}

[Theory]
Expand Down
Loading