diff options
author | Tarek Mahmoud Sayed <tarekms@microsoft.com> | 2016-09-11 05:16:15 +0300 |
---|---|---|
committer | Tarek Mahmoud Sayed <tarekms@microsoft.com> | 2016-09-12 00:47:09 +0300 |
commit | beff0131761c0f71cbbdd40eac496491b4ea7ac5 (patch) | |
tree | b4e30ca00547692433e597d409477727106bc4d1 /src/System.Globalization.Calendars/tests | |
parent | 8b97159afde74103b20a76eba99c72cdefc59af7 (diff) |
Add Globalization tests and expose more APIs in Globalization and String class
Diffstat (limited to 'src/System.Globalization.Calendars/tests')
4 files changed, 133 insertions, 5 deletions
diff --git a/src/System.Globalization.Calendars/tests/Misc/Calendars.netstandard1.7.cs b/src/System.Globalization.Calendars/tests/Misc/Calendars.netstandard1.7.cs new file mode 100644 index 0000000000..ba4253dcde --- /dev/null +++ b/src/System.Globalization.Calendars/tests/Misc/Calendars.netstandard1.7.cs @@ -0,0 +1,95 @@ +// 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() , 0 , 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() , 0 , 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() , 0 , 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() , 0 , 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))] + [ActiveIssue(11605, Xunit.PlatformID.AnyUnix)] + [ActiveIssue(11605, Xunit.PlatformID.AnyUnix)] + 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))] + [ActiveIssue(11605, Xunit.PlatformID.AnyUnix)] + 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))] + [ActiveIssue(11605, Xunit.PlatformID.AnyUnix)] + 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))] + [ActiveIssue(11605, Xunit.PlatformID.AnyUnix)] + public static void AlgorithmTypeTest(Calendar calendar, int yearHasLeapMonth, CalendarAlgorithmType algorithmType) + { + Assert.Equal(calendar.AlgorithmType, algorithmType); + } + + [Fact] + [ActiveIssue(11605, Xunit.PlatformID.AnyUnix)] + 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); + } + } +} diff --git a/src/System.Globalization.Calendars/tests/System.Globalization.Calendars.Tests.builds b/src/System.Globalization.Calendars/tests/System.Globalization.Calendars.Tests.builds index a2a1a9905b..549d46d988 100644 --- a/src/System.Globalization.Calendars/tests/System.Globalization.Calendars.Tests.builds +++ b/src/System.Globalization.Calendars/tests/System.Globalization.Calendars.Tests.builds @@ -4,6 +4,10 @@ <ItemGroup> <Project Include="System.Globalization.Calendars.Tests.csproj"/> <Project Include="System.Globalization.Calendars.Tests.csproj"> + <TargetGroup>netstandard1.7</TargetGroup> + <TestTFMs>netcoreapp1.1</TestTFMs> + </Project> + <Project Include="System.Globalization.Calendars.Tests.csproj"> <TestTFMs>netcore50;net46</TestTFMs> <OSGroup>Windows_NT</OSGroup> </Project> diff --git a/src/System.Globalization.Calendars/tests/System.Globalization.Calendars.Tests.csproj b/src/System.Globalization.Calendars/tests/System.Globalization.Calendars.Tests.csproj index ebd974162e..6c0a3b70e8 100644 --- a/src/System.Globalization.Calendars/tests/System.Globalization.Calendars.Tests.csproj +++ b/src/System.Globalization.Calendars/tests/System.Globalization.Calendars.Tests.csproj @@ -8,8 +8,14 @@ <OutputType>Library</OutputType> <AssemblyName>System.Globalization.Calendars.Tests</AssemblyName> <RootNamespace>System.Globalization.Calendars.Tests</RootNamespace> - <NugetTargetMoniker>.NETStandard,Version=v1.3</NugetTargetMoniker> + <NugetTargetMoniker Condition="'$(TargetGroup)'=='netstandard1.7' AND '$(NugetTargetMoniker)'==''">.NETStandard,Version=v1.7</NugetTargetMoniker> + <NugetTargetMoniker Condition="'$(NugetTargetMoniker)'==''">.NETStandard,Version=v1.3</NugetTargetMoniker> </PropertyGroup> + <ItemGroup Condition="'$(TargetGroup)'=='netstandard1.7'"> + <TestNugetTargetMoniker Include="$(NugetTargetMoniker)"> + <Folder>netcoreapp1.1</Folder> + </TestNugetTargetMoniker> + </ItemGroup> <!-- Default configurations to help VS understand the configurations --> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU'" /> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU'" /> @@ -121,6 +127,11 @@ <Link>Common\System\PlatformDetection.cs</Link> </Compile> </ItemGroup> + + <ItemGroup Condition="'$(TargetGroup)' == 'netstandard1.7'"> + <Compile Include="Misc\Calendars.netstandard1.7.cs" /> + </ItemGroup> + <ItemGroup> <None Include="project.json" /> </ItemGroup> @@ -142,8 +153,8 @@ <Targets>Build;DebugSymbolsProjectOutputGroup</Targets> </ProjectReference> <!-- ToDo: Remove this reference to the live package of System.Globalization once prerelease gets updated again --> - <ProjectReference Include="..\..\System.Globalization\pkg\System.Globalization.pkgproj"> - <Name>System.Globalization</Name> + <ProjectReference Include="..\..\System.Runtime\pkg\System.Runtime.pkgproj"> + <Name>System.Runtime</Name> </ProjectReference> </ItemGroup> <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> diff --git a/src/System.Globalization.Calendars/tests/project.json b/src/System.Globalization.Calendars/tests/project.json index 7ec5cd0cc9..e1959e5df6 100644 --- a/src/System.Globalization.Calendars/tests/project.json +++ b/src/System.Globalization.Calendars/tests/project.json @@ -9,6 +9,7 @@ "System.Runtime.Extensions": "4.3.0-beta-devapi-24511-01", "System.Text.RegularExpressions": "4.3.0-beta-devapi-24511-01", "System.Threading.Tasks": "4.3.0-beta-devapi-24511-01", + "System.Text.Encoding": "4.3.0-beta-devapi-24511-01", "Microsoft.xunit.netcore.extensions": "1.0.0-prerelease-00731-01", "Microsoft.DotNet.BuildTools.TestSuite": "1.0.0-prerelease-00731-01", "test-runtime": { @@ -17,7 +18,8 @@ } }, "frameworks": { - "netstandard1.3": {} + "netstandard1.3": {}, + "netstandard1.7": {} }, "supports": { "coreFx.Test.netcore50": {}, @@ -25,6 +27,22 @@ "coreFx.Test.net46": {}, "coreFx.Test.net461": {}, "coreFx.Test.net462": {}, - "coreFx.Test.net463": {} + "coreFx.Test.net463": {}, + "coreFx.Test.netcoreapp1.1-ns17": { + "netstandard1.7": [ + "win7-x86", + "win7-x64", + "win10-arm64", + "osx.10.10-x64", + "centos.7-x64", + "debian.8-x64", + "rhel.7-x64", + "ubuntu.14.04-x64", + "ubuntu.16.04-x64", + "fedora.23-x64", + "linux-x64", + "opensuse.13.2-x64" + ] + } } } |