@@ -129,40 +129,28 @@ public void Process_ScDateTagWithEmptyValueInForAttribute_GeneratesEmptyOutput(
129129 public void Process_ScDateTagWithCustomFormat_GeneratesCustomDateFormatOutput ( string cultureName )
130130 {
131131 // Arrange
132- CultureInfo originalCulture = CultureInfo . CurrentCulture ;
133- CultureInfo originalUiCulture = CultureInfo . CurrentUICulture ;
134132 CultureInfo testCulture = new CultureInfo ( cultureName ) ;
133+ const string dateFormat = "MM/dd/yyyy H:mm" ;
135134
136- try
135+ DateTagHelper sut = new DateTagHelper ( new EditableChromeRenderer ( ) ) ;
136+ TagHelperContext tagHelperContext = new TagHelperContext ( [ ] , new Dictionary < object , object > ( ) , Guid . NewGuid ( ) . ToString ( "N" , CultureInfo . InvariantCulture ) ) ;
137+ TagHelperOutput tagHelperOutput = new TagHelperOutput ( string . Empty , [ ] , ( _ , _ ) =>
137138 {
138- CultureInfo . CurrentCulture = testCulture ;
139- CultureInfo . CurrentUICulture = testCulture ;
140-
141- const string dateFormat = "MM/dd/yyyy H:mm" ;
142- DateTagHelper sut = new DateTagHelper ( new EditableChromeRenderer ( ) ) ;
143- TagHelperContext tagHelperContext = new TagHelperContext ( [ ] , new Dictionary < object , object > ( ) , Guid . NewGuid ( ) . ToString ( "N" , CultureInfo . InvariantCulture ) ) ;
144- TagHelperOutput tagHelperOutput = new TagHelperOutput ( string . Empty , [ ] , ( _ , _ ) =>
145- {
146- DefaultTagHelperContent tagHelperContent = new ( ) ;
147- return Task . FromResult < TagHelperContent > ( tagHelperContent ) ;
148- } ) ;
149-
150- tagHelperOutput . TagName = RenderingEngineConstants . SitecoreTagHelpers . DateHtmlTag ;
151- sut . DateFormat = dateFormat ;
152- sut . For = GetModelExpression ( new DateField ( _date ) ) ;
153-
154- // Act
155- sut . Process ( tagHelperContext , tagHelperOutput ) ;
156-
157- // Assert - Expect culture-specific formatting based on current culture
158- string expected = _date . ToString ( dateFormat , testCulture ) ;
159- tagHelperOutput . Content . GetContent ( ) . Should ( ) . Be ( expected ) ;
160- }
161- finally
162- {
163- CultureInfo . CurrentCulture = originalCulture ;
164- CultureInfo . CurrentUICulture = originalUiCulture ;
165- }
139+ DefaultTagHelperContent tagHelperContent = new ( ) ;
140+ return Task . FromResult < TagHelperContent > ( tagHelperContent ) ;
141+ } ) ;
142+
143+ tagHelperOutput . TagName = RenderingEngineConstants . SitecoreTagHelpers . DateHtmlTag ;
144+ sut . DateFormat = dateFormat ;
145+ sut . Culture = cultureName ;
146+ sut . For = GetModelExpression ( new DateField ( _date ) ) ;
147+
148+ // Act
149+ sut . Process ( tagHelperContext , tagHelperOutput ) ;
150+
151+ // Assert
152+ string expected = _date . ToString ( dateFormat , testCulture ) ;
153+ tagHelperOutput . Content . GetContent ( ) . Should ( ) . Be ( expected ) ;
166154 }
167155
168156 [ Theory ]
@@ -287,40 +275,28 @@ public void Process_ScDateTagWithAspDataAttributeWithEmptyValueInForAttribute_Ge
287275 public void Process_ScDateTagWithAspDataAttributeWithCustomFormat_GeneratesCustomDateFormatOutput ( string cultureName )
288276 {
289277 // Arrange
290- CultureInfo originalCulture = CultureInfo . CurrentCulture ;
291- CultureInfo originalUiCulture = CultureInfo . CurrentUICulture ;
292278 CultureInfo testCulture = new CultureInfo ( cultureName ) ;
279+ string dateFormat = "MM/dd/yyyy H:mm" ;
293280
294- try
281+ DateTagHelper sut = new DateTagHelper ( new EditableChromeRenderer ( ) ) ;
282+ TagHelperContext tagHelperContext = new TagHelperContext ( [ ] , new Dictionary < object , object > ( ) , Guid . NewGuid ( ) . ToString ( "N" , CultureInfo . InvariantCulture ) ) ;
283+ TagHelperOutput tagHelperOutput = new TagHelperOutput ( string . Empty , [ ] , ( _ , _ ) =>
295284 {
296- CultureInfo . CurrentCulture = testCulture ;
297- CultureInfo . CurrentUICulture = testCulture ;
298-
299- string dateFormat = "MM/dd/yyyy H:mm" ;
300- DateTagHelper sut = new DateTagHelper ( new EditableChromeRenderer ( ) ) ;
301- TagHelperContext tagHelperContext = new TagHelperContext ( [ ] , new Dictionary < object , object > ( ) , Guid . NewGuid ( ) . ToString ( "N" , CultureInfo . InvariantCulture ) ) ;
302- TagHelperOutput tagHelperOutput = new TagHelperOutput ( string . Empty , [ ] , ( _ , _ ) =>
303- {
304- DefaultTagHelperContent tagHelperContent = new ( ) ;
305- return Task . FromResult < TagHelperContent > ( tagHelperContent ) ;
306- } ) ;
307-
308- tagHelperOutput . TagName = RenderingEngineConstants . SitecoreTagHelpers . DateHtmlTag ;
309- sut . DateFormat = dateFormat ;
310- sut . DateModel = new DateField ( _date ) ;
311-
312- // Act
313- sut . Process ( tagHelperContext , tagHelperOutput ) ;
314-
315- // Assert - Expect culture-specific formatting based on current culture
316- string expected = _date . ToString ( dateFormat , testCulture ) ;
317- tagHelperOutput . Content . GetContent ( ) . Should ( ) . Be ( expected ) ;
318- }
319- finally
320- {
321- CultureInfo . CurrentCulture = originalCulture ;
322- CultureInfo . CurrentUICulture = originalUiCulture ;
323- }
285+ DefaultTagHelperContent tagHelperContent = new ( ) ;
286+ return Task . FromResult < TagHelperContent > ( tagHelperContent ) ;
287+ } ) ;
288+
289+ tagHelperOutput . TagName = RenderingEngineConstants . SitecoreTagHelpers . DateHtmlTag ;
290+ sut . DateFormat = dateFormat ;
291+ sut . Culture = cultureName ;
292+ sut . DateModel = new DateField ( _date ) ;
293+
294+ // Act
295+ sut . Process ( tagHelperContext , tagHelperOutput ) ;
296+
297+ // Assert
298+ string expected = _date . ToString ( dateFormat , testCulture ) ;
299+ tagHelperOutput . Content . GetContent ( ) . Should ( ) . Be ( expected ) ;
324300 }
325301
326302 [ Theory ]
0 commit comments