23e1e753471a101bd238b1e6154fc06ad28ec922
[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 System.Collections.Generic;
6 using Xunit;
7
8 namespace System.Globalization.Tests
9 {
10     public class DateTimeFormatInfoGetAbbreviatedDayName
11     {
12         public static IEnumerable<object[]> GetAbbreviatedDayName_TestData()
13         {
14             string[] englishAbbreviatedDayNames = new string[] { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
15             yield return new object[] { DateTimeFormatInfo.InvariantInfo, englishAbbreviatedDayNames };
16             yield return new object[] { new CultureInfo("en-US").DateTimeFormat, englishAbbreviatedDayNames };
17             yield return new object[] { new DateTimeFormatInfo(), englishAbbreviatedDayNames };
18
19             if (!PlatformDetection.IsUbuntu || PlatformDetection.IsUbuntu1404)
20             {
21                 yield return new object[] { new CultureInfo("fr-FR").DateTimeFormat, DateTimeFormatInfoData.FrFRAbbreviatedDayNames() };
22             }
23         }
24
25         [Theory]
26         [MemberData(nameof(GetAbbreviatedDayName_TestData))]
27         public void GetAbbreviatedDayName(DateTimeFormatInfo info, string[] expected)
28         {
29             DayOfWeek[] values = new DayOfWeek[]
30             {
31                 DayOfWeek.Sunday,
32                 DayOfWeek.Monday,
33                 DayOfWeek.Tuesday,
34                 DayOfWeek.Wednesday,
35                 DayOfWeek.Thursday,
36                 DayOfWeek.Friday,
37                 DayOfWeek.Saturday
38             };
39
40             for (int i = 0; i < values.Length; ++i)
41             {
42                 Assert.Equal(expected[i], info.GetAbbreviatedDayName(values[i]));
43             }
44         }
45
46         [Theory]
47         [InlineData(DayOfWeek.Sunday - 1)]
48         [InlineData(DayOfWeek.Saturday + 1)]
49         public void GetAbbreviatedDayName_Invalid_ThrowsArgumentOutOfRangeException(DayOfWeek dayofweek)
50         {
51             AssertExtensions.Throws<ArgumentOutOfRangeException>("dayofweek", () => new DateTimeFormatInfo().GetAbbreviatedDayName(dayofweek));
52         }
53     }
54 }