7d466f3722edbf954f9debbfe554192ceeba4cfa
[platform/upstream/dotnet/runtime.git] /
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 Xunit;
6
7 namespace System.Globalization.Tests
8 {
9     public class DateTimeFormatInfoAbbreviatedMonthGenitiveNames
10     {
11         [Fact]
12         public void AbbreviatedMonthNames_InvariantInfo()
13         {
14             Assert.Equal(new string[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "" }, DateTimeFormatInfo.InvariantInfo.AbbreviatedMonthGenitiveNames);
15         }
16
17         [Fact]
18         public void AbbreviatedMonthNames_Set()
19         {
20             string[] newAbbreviatedMonthGenitiveNames = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "" };
21             var format = new DateTimeFormatInfo();
22             format.AbbreviatedMonthGenitiveNames = newAbbreviatedMonthGenitiveNames;
23             Assert.Equal(newAbbreviatedMonthGenitiveNames, format.AbbreviatedMonthGenitiveNames);
24         }
25
26         [Fact]
27         public void AbbreviatedMonths_Set_Invalid()
28         {
29             AssertExtensions.Throws<ArgumentNullException>("value", () => new DateTimeFormatInfo().AbbreviatedMonthGenitiveNames = null); // Value is null
30             AssertExtensions.Throws<ArgumentNullException>("value", () => new DateTimeFormatInfo().AbbreviatedMonthGenitiveNames = new string[] { "1", "2", "3", null, "5", "6", "7", "8", "9", "10", "11", "12", "" }); // Value has null
31             AssertExtensions.Throws<ArgumentException>("value", () => new DateTimeFormatInfo().AbbreviatedMonthGenitiveNames = new string[] { "Jan" }); // Value.Length is not 13
32
33             // DateTimeFormatInfo.InvariantInfo is read only
34             Assert.Throws<InvalidOperationException>(() => DateTimeFormatInfo.InvariantInfo.AbbreviatedMonthGenitiveNames = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "" });
35         }
36         
37         [Fact]
38         [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
39         public void AbbreviatedMonthNames_Format()
40         {
41             var format = new DateTimeFormatInfo();
42             format.AbbreviatedMonthGenitiveNames = new string[] { "GenJan", "GenFeb", "GenMar", "GenApr", "GenMay", "GenJun", "GenJul", "GenAug", "GenSep", "GenOct", "GenNov", "GenDec", "Gen" };
43             
44             Assert.Equal("19 GenJun 76", new DateTime(1976, 6, 19).ToString("d MMM yy", format));
45         }
46     }
47 }