Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 FluentAssertions;
using HtmlAgilityPack;
using Microsoft.AspNetCore.TestHost;
Expand Down Expand Up @@ -75,7 +76,8 @@ public async Task SitecoreLayoutModelBinders_BindDataCorrectly()
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);
Copy link

Copilot AI Aug 13, 2025

Choose a reason for hiding this comment

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

The hardcoded date string '12.12.19' should be replaced with a more explicit format like '2019-12-12' or use DateTime constructor for better clarity and maintenance.

Suggested change
DateTime expectedDate = DateTime.Parse("12.12.19", CultureInfo.InvariantCulture);
DateTime expectedDate = new DateTime(2019, 12, 12);

Copilot uses AI. Check for mistakes.
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 FluentAssertions;
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);
Copy link

Copilot AI Aug 13, 2025

Choose a reason for hiding this comment

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

The hardcoded date string '12.12.19' should be replaced with a more explicit format like '2019-12-12' or use DateTime constructor for better clarity and maintenance.

Suggested change
DateTime expectedDate = DateTime.Parse("12.12.19", CultureInfo.InvariantCulture);
DateTime expectedDate = new DateTime(2019, 12, 12);

Copilot uses AI. Check for mistakes.
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";
Copy link

Copilot AI Aug 18, 2025

Choose a reason for hiding this comment

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

The hardcoded date format 'MM/dd/yyyy H:mm' may not work correctly across all cultures being tested. Consider using culture-specific format patterns or testing with formats that are more universal across the specified cultures (en-US, da-DK, uk-UA).

Suggested change
const string dateFormat = "MM/dd/yyyy H:mm";
const string dateFormat = "yyyy-MM-dd HH:mm";

Copilot uses AI. Check for mistakes.

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";
Copy link

Copilot AI Aug 18, 2025

Choose a reason for hiding this comment

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

The hardcoded date format 'MM/dd/yyyy H:mm' may not work correctly across all cultures being tested. Consider using culture-specific format patterns or testing with formats that are more universal across the specified cultures (en-US, da-DK, uk-UA).

Suggested change
string dateFormat = "MM/dd/yyyy H:mm";
string dateFormat = "yyyy-MM-dd HH:mm";

Copilot uses AI. Check for mistakes.

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