1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4 
5 using System.Collections.Generic;
6 using Xunit;
7 
8 namespace System.Globalization.Tests
9 {
10     public class DateTimeFormatInfoShortDatePattern
11     {
12         private static readonly RandomDataGenerator s_randomDataGenerator = new RandomDataGenerator();
13 
ShortDatePattern_InvariantInfo()14         public void ShortDatePattern_InvariantInfo()
15         {
16             Assert.Equal("MM/dd/yyyy", DateTimeFormatInfo.InvariantInfo.ShortDatePattern);
17         }
18 
ShortDatePattern_TestData()19         public static IEnumerable<object[]> ShortDatePattern_TestData()
20         {
21             yield return new object[] { "MM/dd/yyyy" };
22             yield return new object[] { "MM-DD-yyyy" };
23             yield return new object[] { "d" };
24             yield return new object[] { s_randomDataGenerator.GetString(-55, false, 1, 256) };
25         }
26 
27         [Theory]
28         [MemberData(nameof(ShortDatePattern_TestData))]
ShortDatePattern_Set(string newShortDatePattern)29         public void ShortDatePattern_Set(string newShortDatePattern)
30         {
31             var format = new DateTimeFormatInfo();
32             format.ShortDatePattern = newShortDatePattern;
33             Assert.Equal(newShortDatePattern, format.ShortDatePattern);
34         }
35 
36         [Fact]
ShortDatePattern_Set_Invalid()37         public void ShortDatePattern_Set_Invalid()
38         {
39             AssertExtensions.Throws<ArgumentNullException>("value", () => new DateTimeFormatInfo().ShortDatePattern = null); // Value is null
40             Assert.Throws<InvalidOperationException>(() => DateTimeFormatInfo.InvariantInfo.ShortDatePattern = "MM/dd/yyyy"); // DateTimeFormatInfo.InvariantInfo is read only
41         }
42     }
43 }
44