-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Making Culture Invariant When Validating Date to negate deferent form…
…ats (#17257) * CultureInfo.InvariantCulture, * adding unitTests by @Matthew-Wise
- Loading branch information
1 parent
421a3a9
commit dabaeac
Showing
2 changed files
with
31 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/Validators/DateTimeValidatorTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Globalization; | ||
using NUnit.Framework; | ||
using Umbraco.Cms.Core.PropertyEditors.Validators; | ||
|
||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.PropertyEditors.Validators; | ||
|
||
[TestFixture] | ||
public class DateTimeValidatorTests | ||
{ | ||
[TestCase("en-US", "yyyy-MM-dd HH:mm:ss", TestName = "US Thread, DateTimeValidator")] | ||
[TestCase("en-US", "dd-MM-yyyy HH:mm:ss", TestName = "US Thread, DateTimeValidator ar-SA format")] | ||
[TestCase("ar-SA", "dd-MM-yyyy HH:mm:ss", TestName = "Arabian Saudi Thread, DateTimeValidator")] | ||
[TestCase("ar-SA", "yyyy-MM-dd HH:mm:ss", TestName = "Arabian Saudi Thread, DateTimeValidator US format")] | ||
public void DateTimeValidatorIsCultureInvariant(string culture, string format) | ||
{ | ||
var dateString = DateTime.Now.ToString(format); | ||
|
||
var cultureInfo = new CultureInfo(culture); | ||
Thread.CurrentThread.CurrentCulture = cultureInfo; | ||
Thread.CurrentThread.CurrentUICulture = cultureInfo; | ||
|
||
var validator = new DateTimeValidator(); | ||
var validationResults = validator.Validate(dateString, "DATETIME", new Dictionary<string, object> | ||
{ | ||
["format"] = format | ||
}); | ||
CollectionAssert.IsEmpty(validationResults); | ||
} | ||
} |