You've already forked linux-packaging-mono
Imported Upstream version 5.4.0.167
Former-commit-id: 5624ac747d633e885131e8349322922b6a59baaa
This commit is contained in:
parent
e49d6f06c0
commit
536cd135cc
@@ -2,7 +2,8 @@
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\dir.props" />
|
||||
<PropertyGroup>
|
||||
<AssemblyVersion>4.1.0.0</AssemblyVersion>
|
||||
<AssemblyVersion>4.1.1.0</AssemblyVersion>
|
||||
<AssemblyKey>MSFT</AssemblyKey>
|
||||
<IsNETCoreApp>true</IsNETCoreApp>
|
||||
<IsUAP>true</IsUAP>
|
||||
</PropertyGroup>
|
||||
|
@@ -6,7 +6,6 @@
|
||||
<IsPartialFacadeAssembly>true</IsPartialFacadeAssembly>
|
||||
<ProjectGuid>{7126BEDB-0903-454A-8A2B-8BE1CBDF8F2E}</ProjectGuid>
|
||||
</PropertyGroup>
|
||||
<!-- Help VS understand available configurations -->
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Unix-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Unix-Release|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Windows_NT-Debug|AnyCPU'" />
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
@@ -167,14 +167,14 @@ namespace System.Globalization.Tests
|
||||
[MemberData(nameof(Year_Month_Day_Era_TestData), DataType.Year, false)]
|
||||
public static void GetDaysInYear_Invalid(Calendar calendar, int year, int month, int day, int era, string exceptionParamName)
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(exceptionParamName, () => calendar.GetDaysInYear(year, era));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>(exceptionParamName, () => calendar.GetDaysInYear(year, era));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Year_Month_Day_Era_TestData), DataType.Year, false)]
|
||||
public static void GetMonthsInYear_Invalid(Calendar calendar, int year, int month, int day, int era, string exceptionParamName)
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(exceptionParamName, () => calendar.GetMonthsInYear(year, era));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>(exceptionParamName, () => calendar.GetMonthsInYear(year, era));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -182,7 +182,7 @@ namespace System.Globalization.Tests
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.Netcoreapp | TargetFrameworkMonikers.Uap)]
|
||||
public static void GetDaysInMonth_Invalid_net46(Calendar calendar, int year, int month, int day, int era, string exceptionParamName)
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(exceptionParamName, () => calendar.GetDaysInMonth(year, month, era));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>(exceptionParamName, () => calendar.GetDaysInMonth(year, month, era));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -190,7 +190,7 @@ namespace System.Globalization.Tests
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
|
||||
public static void GetDaysInMonth_Invalid_netcore(Calendar calendar, int year, int month, int day, int era, string exceptionParamName)
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(exceptionParamName, () => calendar.GetDaysInMonth(year, month, era));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>(exceptionParamName, () => calendar.GetDaysInMonth(year, month, era));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -198,7 +198,7 @@ namespace System.Globalization.Tests
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
|
||||
public static void IsLeapDay_Invalid_netcore(Calendar calendar, int year, int month, int day, int era, string exceptionParamName)
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(exceptionParamName, () => calendar.IsLeapDay(year, month, day, era));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>(exceptionParamName, () => calendar.IsLeapDay(year, month, day, era));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -206,7 +206,7 @@ namespace System.Globalization.Tests
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.Netcoreapp | TargetFrameworkMonikers.Uap)]
|
||||
public static void IsLeapDay_Invalid_net46(Calendar calendar, int year, int month, int day, int era, string exceptionParamName)
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(exceptionParamName, () => calendar.IsLeapDay(year, month, day, era));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>(exceptionParamName, () => calendar.IsLeapDay(year, month, day, era));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -214,7 +214,7 @@ namespace System.Globalization.Tests
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
|
||||
public static void IsLeapMonth_Invalid_netcore(Calendar calendar, int year, int month, int day, int era, string exceptionParamName)
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(exceptionParamName, () => calendar.IsLeapMonth(year, month, era));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>(exceptionParamName, () => calendar.IsLeapMonth(year, month, era));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -222,21 +222,21 @@ namespace System.Globalization.Tests
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.Netcoreapp | TargetFrameworkMonikers.Uap)]
|
||||
public static void IsLeapMonth_Invalid_net46(Calendar calendar, int year, int month, int day, int era, string exceptionParamName)
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(exceptionParamName, () => calendar.IsLeapMonth(year, month, era));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>(exceptionParamName, () => calendar.IsLeapMonth(year, month, era));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Year_Month_Day_Era_TestData), DataType.Year, false)]
|
||||
public static void IsLeapYear_Invalid(Calendar calendar, int year, int month, int day, int era, string exceptionParamName)
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(exceptionParamName, () => calendar.IsLeapYear(year, era));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>(exceptionParamName, () => calendar.IsLeapYear(year, era));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Year_Month_Day_Era_TestData), DataType.Year, false)]
|
||||
public static void GetLeapMonth_Invalid(Calendar calendar, int year, int month, int day, int era, string expectedParamName)
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(expectedParamName, () => calendar.GetLeapMonth(year, era));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>(expectedParamName, () => calendar.GetLeapMonth(year, era));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -254,8 +254,8 @@ namespace System.Globalization.Tests
|
||||
Assert.ThrowsAny<ArgumentException>(() => calendar.AddMonths(calendar.MaxSupportedDateTime, 1));
|
||||
Assert.ThrowsAny<ArgumentException>(() => calendar.AddMonths(calendar.MinSupportedDateTime, -1)); // JapaneseCalendar throws ArgumentException
|
||||
|
||||
Assert.Throws<ArgumentOutOfRangeException>("months", () => calendar.AddMonths(DateTime.Now, -120001));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("months", () => calendar.AddMonths(DateTime.Now, 120001));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("months", () => calendar.AddMonths(DateTime.Now, -120001));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("months", () => calendar.AddMonths(DateTime.Now, 120001));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -309,12 +309,12 @@ namespace System.Globalization.Tests
|
||||
public static void GetWeekOfYear_Invalid(Calendar calendar)
|
||||
{
|
||||
// Rule is outside supported range
|
||||
Assert.Throws<ArgumentOutOfRangeException>("rule", () => calendar.GetWeekOfYear(calendar.MaxSupportedDateTime, CalendarWeekRule.FirstDay - 1, DayOfWeek.Saturday));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("rule", () => calendar.GetWeekOfYear(calendar.MaxSupportedDateTime, CalendarWeekRule.FirstFourDayWeek + 1, DayOfWeek.Saturday));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("rule", () => calendar.GetWeekOfYear(calendar.MaxSupportedDateTime, CalendarWeekRule.FirstDay - 1, DayOfWeek.Saturday));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("rule", () => calendar.GetWeekOfYear(calendar.MaxSupportedDateTime, CalendarWeekRule.FirstFourDayWeek + 1, DayOfWeek.Saturday));
|
||||
|
||||
// FirstDayOfWeek is outside supported range
|
||||
Assert.Throws<ArgumentOutOfRangeException>("firstDayOfWeek", () => calendar.GetWeekOfYear(calendar.MaxSupportedDateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday - 1));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("firstDayOfWeek", () => calendar.GetWeekOfYear(calendar.MaxSupportedDateTime, CalendarWeekRule.FirstDay, DayOfWeek.Saturday + 1));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("firstDayOfWeek", () => calendar.GetWeekOfYear(calendar.MaxSupportedDateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday - 1));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("firstDayOfWeek", () => calendar.GetWeekOfYear(calendar.MaxSupportedDateTime, CalendarWeekRule.FirstDay, DayOfWeek.Saturday + 1));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -386,12 +386,12 @@ namespace System.Globalization.Tests
|
||||
[MemberData(nameof(Calendars_TestData))]
|
||||
public static void ToFourDigitYear_Invalid(Calendar calendar)
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>("year", () => calendar.ToFourDigitYear(-1));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("year", () => calendar.ToFourDigitYear(MaxCalendarYearInEra(calendar, MaxEra(calendar)) + 1));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("year", () => calendar.ToFourDigitYear(-1));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("year", () => calendar.ToFourDigitYear(MaxCalendarYearInEra(calendar, MaxEra(calendar)) + 1));
|
||||
|
||||
if (!(calendar is JapaneseLunisolarCalendar))
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>("year", () => calendar.ToFourDigitYear(MinCalendarYearInEra(calendar, MinEra(calendar)) - 2));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("year", () => calendar.ToFourDigitYear(MinCalendarYearInEra(calendar, MinEra(calendar)) - 2));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -423,28 +423,28 @@ namespace System.Globalization.Tests
|
||||
[MemberData(nameof(DateTime_TestData))]
|
||||
public static void GetYear_Invalid(Calendar calendar, DateTime dt)
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>("time", () => calendar.GetYear(dt));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("time", () => calendar.GetYear(dt));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(DateTime_TestData))]
|
||||
public static void GetMonth_Invalid(Calendar calendar, DateTime dt)
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>("time", () => calendar.GetMonth(dt));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("time", () => calendar.GetMonth(dt));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(DateTime_TestData))]
|
||||
public static void GetDayOfYear_Invalid(Calendar calendar, DateTime dt)
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>("time", () => calendar.GetDayOfYear(dt));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("time", () => calendar.GetDayOfYear(dt));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(DateTime_TestData))]
|
||||
public static void GetDayOfMonth_Invalid(Calendar calendar, DateTime dt)
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>("time", () => calendar.GetDayOfMonth(dt));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("time", () => calendar.GetDayOfMonth(dt));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -457,7 +457,7 @@ namespace System.Globalization.Tests
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>("time", () => calendar.GetDayOfWeek(dt));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("time", () => calendar.GetDayOfWeek(dt));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -41,7 +41,7 @@ namespace System.Globalization.Tests
|
||||
[InlineData(GregorianCalendarTypes.TransliteratedFrench + 1)]
|
||||
public void Ctor_GregorianCalendarTypes_InvalidType_ThrowsArgumentOutOfRangeException(GregorianCalendarTypes type)
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>("type", () => new GregorianCalendar(type));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("type", () => new GregorianCalendar(type));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -59,7 +59,7 @@ namespace System.Globalization.Tests
|
||||
public void CalendarType_Set_InvalidType_ThrowsArgumentOutOfRangeException(GregorianCalendarTypes type)
|
||||
{
|
||||
GregorianCalendar calendar = new GregorianCalendar();
|
||||
Assert.Throws<ArgumentOutOfRangeException>("m_type", () => calendar.CalendarType = type);
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("m_type", () => calendar.CalendarType = type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -46,7 +46,7 @@ namespace System.Globalization.Tests
|
||||
|
||||
// Any day in any month in any year
|
||||
int randomYear = RandomYear();
|
||||
yield return new object[] { new DateTime(RandomYear(), randomMonth, RandomDay(randomYear, randomMonth)), RandomCalendarWeekRule(), RandomDayOfWeek() };
|
||||
yield return new object[] { new DateTime(randomYear, randomMonth, RandomDay(randomYear, randomMonth)), RandomCalendarWeekRule(), RandomDayOfWeek() };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
@@ -11,8 +11,6 @@ namespace System.Globalization.Tests
|
||||
{
|
||||
public class GregorianCalendarIsLeapDay
|
||||
{
|
||||
private static readonly RandomDataGenerator s_randomDataGenerator = new RandomDataGenerator();
|
||||
|
||||
public static IEnumerable<object[]> IsLeapDay_TestData()
|
||||
{
|
||||
int randomYear = RandomYear();
|
||||
|
@@ -6,7 +6,11 @@ namespace System.Globalization.Tests
|
||||
{
|
||||
public class GregorianCalendarTestUtilities
|
||||
{
|
||||
private static readonly RandomDataGenerator s_randomDataGenerator = new RandomDataGenerator();
|
||||
[ThreadStatic]
|
||||
private static RandomDataGenerator t_randomDataGenerator;
|
||||
|
||||
private static RandomDataGenerator Generator => t_randomDataGenerator ?? (t_randomDataGenerator = new RandomDataGenerator());
|
||||
|
||||
private static readonly Calendar s_calendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish);
|
||||
|
||||
private static readonly int[] s_daysInMonthInLeapYear = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||
@@ -21,7 +25,7 @@ namespace System.Globalization.Tests
|
||||
{
|
||||
int maxYear = s_calendar.MaxSupportedDateTime.Year;
|
||||
int minYear = s_calendar.MinSupportedDateTime.Year;
|
||||
return minYear + s_randomDataGenerator.GetInt32(-55) % (maxYear + 1 - minYear);
|
||||
return minYear + Generator.GetInt32(-55) % (maxYear + 1 - minYear);
|
||||
}
|
||||
|
||||
public static int RandomLeapYear()
|
||||
@@ -50,9 +54,9 @@ namespace System.Globalization.Tests
|
||||
return randomYear;
|
||||
}
|
||||
|
||||
public static int RandomMonth() => s_randomDataGenerator.GetInt32(-55) % 12 + 1;
|
||||
public static int RandomMonth() => Generator.GetInt32(-55) % 12 + 1;
|
||||
|
||||
public static int RandomMonthNotFebruary()
|
||||
public static int RandomMonthNotFebruary()
|
||||
{
|
||||
int randomMonthNotFebruary;
|
||||
do
|
||||
@@ -62,8 +66,9 @@ namespace System.Globalization.Tests
|
||||
return randomMonthNotFebruary;
|
||||
}
|
||||
|
||||
public static int RandomLeapYearDay(int month) => s_randomDataGenerator.GetInt32(-55) % s_daysInMonthInLeapYear[month] + 1;
|
||||
public static int RandomCommonYearDay(int month) => s_randomDataGenerator.GetInt32(-55) % s_daysInMonthInCommonYear[month] + 1;
|
||||
public static int RandomLeapYearDay(int month) => Generator.GetInt32(-55) % s_daysInMonthInLeapYear[month] + 1;
|
||||
|
||||
public static int RandomCommonYearDay(int month) => Generator.GetInt32(-55) % s_daysInMonthInCommonYear[month] + 1;
|
||||
|
||||
public static int RandomDay(int year, int month)
|
||||
{
|
||||
|
@@ -40,7 +40,7 @@ namespace System.Globalization.Tests
|
||||
[Fact]
|
||||
public void ToFourDigitYear_InvalidYear_ThrowsArgumentOutOfRangeException()
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>("year", () => new KoreanCalendar().ToFourDigitYear(100));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("year", () => new KoreanCalendar().ToFourDigitYear(100));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
|
||||
namespace System.Globalization.Tests
|
||||
@@ -65,5 +66,80 @@ namespace System.Globalization.Tests
|
||||
TaiwanLunisolarCalendar tc = new TaiwanLunisolarCalendar();
|
||||
Assert.Equal(1, tc.Eras.Length);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Calendars_TestData()
|
||||
{
|
||||
// Calendar yearHasLeapMonth CalendarAlgorithmType
|
||||
yield return new object[] { new ChineseLunisolarCalendar() , 2017 , CalendarAlgorithmType.LunisolarCalendar };
|
||||
yield return new object[] { new GregorianCalendar() , 0 , CalendarAlgorithmType.SolarCalendar };
|
||||
yield return new object[] { new HebrewCalendar() , 5345 , CalendarAlgorithmType.LunisolarCalendar };
|
||||
yield return new object[] { new HijriCalendar() , 0 , CalendarAlgorithmType.LunarCalendar };
|
||||
yield return new object[] { new JapaneseCalendar() , 0 , CalendarAlgorithmType.SolarCalendar };
|
||||
yield return new object[] { new JapaneseLunisolarCalendar() , 29 , CalendarAlgorithmType.LunisolarCalendar };
|
||||
yield return new object[] { new JulianCalendar() , 0 , CalendarAlgorithmType.SolarCalendar };
|
||||
yield return new object[] { new KoreanCalendar() , 0 , CalendarAlgorithmType.SolarCalendar };
|
||||
yield return new object[] { new KoreanLunisolarCalendar() , 2017 , CalendarAlgorithmType.LunisolarCalendar };
|
||||
yield return new object[] { new PersianCalendar() , 0 , CalendarAlgorithmType.SolarCalendar };
|
||||
yield return new object[] { new TaiwanCalendar() , 0 , CalendarAlgorithmType.SolarCalendar };
|
||||
yield return new object[] { new TaiwanLunisolarCalendar() , 106 , CalendarAlgorithmType.LunisolarCalendar };
|
||||
yield return new object[] { new ThaiBuddhistCalendar() , 0 , CalendarAlgorithmType.SolarCalendar };
|
||||
yield return new object[] { new UmAlQuraCalendar() , 0 , CalendarAlgorithmType.LunarCalendar };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Calendars_TestData))]
|
||||
public static void CloningTest(Calendar calendar, int yearHasLeapMonth, CalendarAlgorithmType algorithmType)
|
||||
{
|
||||
Calendar cloned = (Calendar) calendar.Clone();
|
||||
Assert.Equal(calendar.GetType(), cloned.GetType());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Calendars_TestData))]
|
||||
public static void GetLeapMonthTest(Calendar calendar, int yearHasLeapMonth, CalendarAlgorithmType algorithmType)
|
||||
{
|
||||
if (yearHasLeapMonth > 0)
|
||||
{
|
||||
Assert.NotEqual(calendar.GetLeapMonth(yearHasLeapMonth), 0);
|
||||
Assert.Equal(0, calendar.GetLeapMonth(yearHasLeapMonth - 1));
|
||||
}
|
||||
else
|
||||
Assert.True(calendar.GetLeapMonth(calendar.GetYear(DateTime.Today)) == 0,
|
||||
"calendar.GetLeapMonth returned wrong value");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Calendars_TestData))]
|
||||
public static void ReadOnlyTest(Calendar calendar, int yearHasLeapMonth, CalendarAlgorithmType algorithmType)
|
||||
{
|
||||
Assert.False(calendar.IsReadOnly);
|
||||
var readOnlyCal = Calendar.ReadOnly(calendar);
|
||||
Assert.True(readOnlyCal.IsReadOnly, "expect readOnlyCal.IsReadOnly returns true");
|
||||
var colnedCal = (Calendar) readOnlyCal.Clone();
|
||||
Assert.False(colnedCal.IsReadOnly, "expect colnedCal.IsReadOnly returns false");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Calendars_TestData))]
|
||||
public static void AlgorithmTypeTest(Calendar calendar, int yearHasLeapMonth, CalendarAlgorithmType algorithmType)
|
||||
{
|
||||
Assert.Equal(calendar.AlgorithmType, algorithmType);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void CalendarErasTest()
|
||||
{
|
||||
Assert.Equal(1, ChineseLunisolarCalendar.ChineseEra);
|
||||
Assert.Equal(1, GregorianCalendar.ADEra);
|
||||
Assert.Equal(1, JapaneseLunisolarCalendar.JapaneseEra);
|
||||
Assert.Equal(1, HebrewCalendar.HebrewEra);
|
||||
Assert.Equal(1, HijriCalendar.HijriEra);
|
||||
Assert.Equal(1, JulianCalendar.JulianEra);
|
||||
Assert.Equal(1, KoreanCalendar.KoreanEra);
|
||||
Assert.Equal(1, KoreanLunisolarCalendar.GregorianEra);
|
||||
Assert.Equal(1, PersianCalendar.PersianEra);
|
||||
Assert.Equal(1, ThaiBuddhistCalendar.ThaiBuddhistEra);
|
||||
Assert.Equal(1, UmAlQuraCalendar.UmAlQuraEra);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,89 +0,0 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Xunit;
|
||||
using System.Globalization;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace System.Globalization.Tests
|
||||
{
|
||||
|
||||
public static class CalendarsMoreTests
|
||||
{
|
||||
public static IEnumerable<object[]> Calendars_TestData()
|
||||
{
|
||||
// Calendar yearHasLeapMonth CalendarAlgorithmType
|
||||
yield return new object[] { new ChineseLunisolarCalendar() , 2017 , CalendarAlgorithmType.LunisolarCalendar };
|
||||
yield return new object[] { new GregorianCalendar() , 0 , CalendarAlgorithmType.SolarCalendar };
|
||||
yield return new object[] { new HebrewCalendar() , 5345 , CalendarAlgorithmType.LunisolarCalendar };
|
||||
yield return new object[] { new HijriCalendar() , 0 , CalendarAlgorithmType.LunarCalendar };
|
||||
yield return new object[] { new JapaneseCalendar() , 0 , CalendarAlgorithmType.SolarCalendar };
|
||||
yield return new object[] { new JapaneseLunisolarCalendar() , 29 , CalendarAlgorithmType.LunisolarCalendar };
|
||||
yield return new object[] { new JulianCalendar() , 0 , CalendarAlgorithmType.SolarCalendar };
|
||||
yield return new object[] { new KoreanCalendar() , 0 , CalendarAlgorithmType.SolarCalendar };
|
||||
yield return new object[] { new KoreanLunisolarCalendar() , 2017 , CalendarAlgorithmType.LunisolarCalendar };
|
||||
yield return new object[] { new PersianCalendar() , 0 , CalendarAlgorithmType.SolarCalendar };
|
||||
yield return new object[] { new TaiwanCalendar() , 0 , CalendarAlgorithmType.SolarCalendar };
|
||||
yield return new object[] { new TaiwanLunisolarCalendar() , 106 , CalendarAlgorithmType.LunisolarCalendar };
|
||||
yield return new object[] { new ThaiBuddhistCalendar() , 0 , CalendarAlgorithmType.SolarCalendar };
|
||||
yield return new object[] { new UmAlQuraCalendar() , 0 , CalendarAlgorithmType.LunarCalendar };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Calendars_TestData))]
|
||||
public static void CloningTest(Calendar calendar, int yearHasLeapMonth, CalendarAlgorithmType algorithmType)
|
||||
{
|
||||
Calendar cloned = (Calendar) calendar.Clone();
|
||||
Assert.Equal(calendar.GetType(), cloned.GetType());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Calendars_TestData))]
|
||||
public static void GetLeapMonthTest(Calendar calendar, int yearHasLeapMonth, CalendarAlgorithmType algorithmType)
|
||||
{
|
||||
if (yearHasLeapMonth > 0)
|
||||
{
|
||||
Assert.NotEqual(calendar.GetLeapMonth(yearHasLeapMonth), 0);
|
||||
Assert.Equal(0, calendar.GetLeapMonth(yearHasLeapMonth - 1));
|
||||
}
|
||||
else
|
||||
Assert.True(calendar.GetLeapMonth(calendar.GetYear(DateTime.Today)) == 0,
|
||||
"calendar.GetLeapMonth returned wrong value");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Calendars_TestData))]
|
||||
public static void ReadOnlyTest(Calendar calendar, int yearHasLeapMonth, CalendarAlgorithmType algorithmType)
|
||||
{
|
||||
Assert.False(calendar.IsReadOnly);
|
||||
var readOnlyCal = Calendar.ReadOnly(calendar);
|
||||
Assert.True(readOnlyCal.IsReadOnly, "expect readOnlyCal.IsReadOnly returns true");
|
||||
var colnedCal = (Calendar) readOnlyCal.Clone();
|
||||
Assert.False(colnedCal.IsReadOnly, "expect colnedCal.IsReadOnly returns false");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Calendars_TestData))]
|
||||
public static void AlgorithmTypeTest(Calendar calendar, int yearHasLeapMonth, CalendarAlgorithmType algorithmType)
|
||||
{
|
||||
Assert.Equal(calendar.AlgorithmType, algorithmType);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void CalendarErasTest()
|
||||
{
|
||||
Assert.Equal(1, ChineseLunisolarCalendar.ChineseEra);
|
||||
Assert.Equal(1, GregorianCalendar.ADEra);
|
||||
Assert.Equal(1, JapaneseLunisolarCalendar.JapaneseEra);
|
||||
Assert.Equal(1, HebrewCalendar.HebrewEra);
|
||||
Assert.Equal(1, HijriCalendar.HijriEra);
|
||||
Assert.Equal(1, JulianCalendar.JulianEra);
|
||||
Assert.Equal(1, KoreanCalendar.KoreanEra);
|
||||
Assert.Equal(1, KoreanLunisolarCalendar.GregorianEra);
|
||||
Assert.Equal(1, PersianCalendar.PersianEra);
|
||||
Assert.Equal(1, ThaiBuddhistCalendar.ThaiBuddhistEra);
|
||||
Assert.Equal(1, UmAlQuraCalendar.UmAlQuraEra);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
|
||||
<Library>
|
||||
<!-- Needed because of [Theory] data which causes xunit to reflect on its ToString(). -->
|
||||
<Type Name="System.Globalization.ChineseLunisolarCalendar" Dynamic="Required Public" />
|
||||
<Type Name="System.Globalization.GregorianCalendar" Dynamic="Required Public" />
|
||||
<Type Name="System.Globalization.HebrewCalendar" Dynamic="Required Public" />
|
||||
<Type Name="System.Globalization.HijriCalendar" Dynamic="Required Public" />
|
||||
<Type Name="System.Globalization.JapaneseCalendar" Dynamic="Required Public" />
|
||||
<Type Name="System.Globalization.JapaneseLunisolarCalendar" Dynamic="Required Public" />
|
||||
<Type Name="System.Globalization.JulianCalendar" Dynamic="Required Public" />
|
||||
<Type Name="System.Globalization.KoreanCalendar" Dynamic="Required Public" />
|
||||
<Type Name="System.Globalization.KoreanLunisolarCalendar" Dynamic="Required Public" />
|
||||
<Type Name="System.Globalization.PersianCalendar" Dynamic="Required Public" />
|
||||
<Type Name="System.Globalization.TaiwanCalendar" Dynamic="Required Public" />
|
||||
<Type Name="System.Globalization.TaiwanLunisolarCalendar" Dynamic="Required Public" />
|
||||
<Type Name="System.Globalization.ThaiBuddhistCalendar" Dynamic="Required Public" />
|
||||
<Type Name="System.Globalization.UmAlQuraCalendar" Dynamic="Required Public" />
|
||||
</Library>
|
||||
</Directives>
|
||||
|
@@ -109,12 +109,15 @@
|
||||
<Compile Include="ThaiBuddhistCalendar\ThaiBuddhistCalendarTwoDigitYearMax.cs" />
|
||||
<Compile Include="$(CommonTestPath)\System\RandomDataGenerator.cs" />
|
||||
<!-- Helpers -->
|
||||
<Compile Include="$(CommonTestPath)\System\AssertExtensions.cs">
|
||||
<Link>Common\System\AssertExtensions.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="$(CommonTestPath)\System\PlatformDetection.cs">
|
||||
<Link>Common\System\PlatformDetection.cs</Link>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Misc\Calendars.netstandard.cs" />
|
||||
<EmbeddedResource Include="Resources\$(AssemblyName).rd.xml" />
|
||||
</ItemGroup>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
|
||||
</Project>
|
||||
</Project>
|
||||
|
@@ -11,12 +11,10 @@ namespace System.Globalization.Tests
|
||||
{
|
||||
public static IEnumerable<object[]> IsLeapDay_TestData()
|
||||
{
|
||||
int randomYear = TaiwanCalendarUtilities.RandomYear();
|
||||
int radomMonth = TaiwanCalendarUtilities.RandomMonth();
|
||||
int randomDay = TaiwanCalendarUtilities.RandomDay(randomYear, radomMonth);
|
||||
yield return new object[] { randomYear, radomMonth, randomDay, false };
|
||||
|
||||
yield return new object[] { 2000 - 1911, 2, 28, false };
|
||||
yield return new object[] { 2000 - 1911, 2, 29, true };
|
||||
yield return new object[] { 2000 - 1911, 3, 1, false };
|
||||
yield return new object[] { 2001 - 1911, 2, 28, false };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
@@ -6,7 +6,10 @@ namespace System.Globalization.Tests
|
||||
{
|
||||
public static class TaiwanCalendarUtilities
|
||||
{
|
||||
private static readonly RandomDataGenerator s_randomDataGenerator = new RandomDataGenerator();
|
||||
[ThreadStatic]
|
||||
private static RandomDataGenerator t_randomDataGenerator;
|
||||
|
||||
private static RandomDataGenerator Generator => t_randomDataGenerator ?? (t_randomDataGenerator = new RandomDataGenerator());
|
||||
|
||||
private static readonly int[] s_daysPerMonthLeapYear = new int[]
|
||||
{
|
||||
@@ -21,20 +24,22 @@ namespace System.Globalization.Tests
|
||||
public static int RandomYear()
|
||||
{
|
||||
TaiwanCalendar calendar = new TaiwanCalendar();
|
||||
return new Random(-55).Next(calendar.MinSupportedDateTime.Year, calendar.MaxSupportedDateTime.Year - 1911);
|
||||
int maxYear = calendar.MaxSupportedDateTime.Year;
|
||||
int minYear = calendar.MinSupportedDateTime.Year;
|
||||
return minYear + Generator.GetInt32(-55) % (maxYear - 1911 + 1 - minYear);
|
||||
}
|
||||
|
||||
public static int RandomMonth() => new Random(-55).Next(1, 12);
|
||||
public static int RandomMonth() => Generator.GetInt32(-55) % 12 + 1;
|
||||
|
||||
public static int RandomDay(int year, int month)
|
||||
{
|
||||
if (new TaiwanCalendar().IsLeapYear(year))
|
||||
{
|
||||
return new Random(-55).Next(1, s_daysPerMonthLeapYear[month] + 1);
|
||||
return Generator.GetInt32(-55) % s_daysPerMonthLeapYear[month] + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Random(-55).Next(1, s_daysPerMonthCommonYear[month] + 1);
|
||||
return Generator.GetInt32(-55) % s_daysPerMonthCommonYear[month] + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user