Skip to content

Commit

Permalink
Split netcoreapp code to its own files
Browse files Browse the repository at this point in the history
  • Loading branch information
tarekgh committed Feb 8, 2017
1 parent 701815a commit 75c8d08
Show file tree
Hide file tree
Showing 10 changed files with 258 additions and 219 deletions.
36 changes: 36 additions & 0 deletions src/System.Runtime/tests/ArrayTests.netcoreapp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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 System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Xunit;

namespace System.Tests
{
public static class Array17NetcoreappTests
{
[Fact]
public static void CreateInstance_Type_Int_Invalid()
{
// Type is not a valid RuntimeType
Assert.Throws<ArgumentException>("elementType", () => Array.CreateInstance(Helpers.NonRuntimeType(), 0));
}

[Fact]
public static void CreateInstance_Type_Int_Int_Invalid()
{
// Type is not a valid RuntimeType
Assert.Throws<ArgumentException>("elementType", () => Array.CreateInstance(Helpers.NonRuntimeType(), 0, 1));
}

[Fact]
public static void CreateInstance_Type_Int_Int_Int_Invalid()
{
// Type is not a valid RuntimeType
Assert.Throws<ArgumentException>("elementType", () => Array.CreateInstance(Helpers.NonRuntimeType(), 0, 1, 2));
}
}
}
15 changes: 0 additions & 15 deletions src/System.Runtime/tests/ArrayTests.netstandard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,6 @@ public static void CreateInstance_Type_Int_Invalid()
Assert.Throws<NotSupportedException>(() => Array.CreateInstance(typeof(int).MakeByRefType(), 0)); // Element type is not supported (ref)

Assert.Throws<ArgumentOutOfRangeException>("length", () => Array.CreateInstance(typeof(int), -1)); // Length < 0

#if netcoreapp
// Type is not a valid RuntimeType
Assert.Throws<ArgumentException>("elementType", () => Array.CreateInstance(Helpers.NonRuntimeType(), 0));
#endif // netcoreapp
}

[Fact]
Expand All @@ -158,11 +153,6 @@ public static void CreateInstance_Type_Int_Int_Invalid()
Assert.Throws<NotSupportedException>(() => Array.CreateInstance(typeof(int).MakeByRefType(), 0, 1)); // Element type is not supported (ref)

Assert.Throws<ArgumentOutOfRangeException>("length2", () => Array.CreateInstance(typeof(int), 0, -1)); // Length < 0

#if netcoreapp
// Type is not a valid RuntimeType
Assert.Throws<ArgumentException>("elementType", () => Array.CreateInstance(Helpers.NonRuntimeType(), 0, 1));
#endif // netcoreapp
}

[Fact]
Expand All @@ -184,11 +174,6 @@ public static void CreateInstance_Type_Int_Int_Int_Invalid()
Assert.Throws<NotSupportedException>(() => Array.CreateInstance(typeof(int).MakeByRefType(), 0, 1, 2)); // Element type is not supported (ref)

Assert.Throws<ArgumentOutOfRangeException>("length3", () => Array.CreateInstance(typeof(int), 0, 1, -1)); // Length < 0

#if netcoreapp
// Type is not a valid RuntimeType
Assert.Throws<ArgumentException>("elementType", () => Array.CreateInstance(Helpers.NonRuntimeType(), 0, 1, 2));
#endif // netcoreapp
}

[Fact]
Expand Down
24 changes: 1 addition & 23 deletions src/System.Runtime/tests/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,8 @@

namespace System.Tests
{
public static class Helpers
public static partial class Helpers
{
#if netcoreapp // AssemblyBuilder is not in netstandard yet

private static Type s_nonRuntimeType;

public static Type NonRuntimeType()
{
if (s_nonRuntimeType == null)
{
AssemblyName assemblyName = new AssemblyName("AssemblyName");
AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run);
ModuleBuilder mboduleBuilder = assemblyBuilder.DefineDynamicModule(assemblyName.Name);

TypeBuilder typeBuilder = mboduleBuilder.DefineType("TestType", TypeAttributes.Public);

GenericTypeParameterBuilder[] typeParams = typeBuilder.DefineGenericParameters("T");
s_nonRuntimeType = typeParams[0].UnderlyingSystemType;
}

return s_nonRuntimeType;
}
#endif // netcoreapp

public static void PerformActionWithCulture(CultureInfo culture, Action test)
{
CultureInfo originalCulture = CultureInfo.CurrentCulture;
Expand Down
32 changes: 32 additions & 0 deletions src/System.Runtime/tests/Helpers.netcoreapp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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 System.Globalization;
using System.Reflection;
using System.Reflection.Emit;

namespace System.Tests
{
public static partial class Helpers
{
private static Type s_nonRuntimeType;

public static Type NonRuntimeType()
{
if (s_nonRuntimeType == null)
{
AssemblyName assemblyName = new AssemblyName("AssemblyName");
AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run);
ModuleBuilder mboduleBuilder = assemblyBuilder.DefineDynamicModule(assemblyName.Name);

TypeBuilder typeBuilder = mboduleBuilder.DefineType("TestType", TypeAttributes.Public);

GenericTypeParameterBuilder[] typeParams = typeBuilder.DefineGenericParameters("T");
s_nonRuntimeType = typeParams[0].UnderlyingSystemType;
}

return s_nonRuntimeType;
}
}
}
3 changes: 3 additions & 0 deletions src/System.Runtime/tests/System.Runtime.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@
</Compile>
</ItemGroup>
<ItemGroup Condition="'$(TargetGroup)' == 'netcoreapp'">
<Compile Include="ArrayTests.netcoreapp.cs" />
<Compile Include="Helpers.netcoreapp.cs" />
<Compile Include="System\ActivatorTests.netcoreapp.cs" />
<Compile Include="System\ArrayTests.netcoreapp.cs" />
<Compile Include="System\EnumTests.netcoreapp.cs" />
<Compile Include="System\GCTests.netcoreapp.cs" />
Expand Down
19 changes: 19 additions & 0 deletions src/System.Runtime/tests/System/ActivatorTests.netcoreapp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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 System.Reflection;
using Xunit;

namespace System.Tests
{
public static class ActivatorNetcoreTests
{
[Fact]
public static void CreateInstance_Invalid()
{
// Type is not a valid RuntimeType
Assert.Throws<ArgumentException>("type", () => Activator.CreateInstance(Helpers.NonRuntimeType()));
}
}
}
10 changes: 0 additions & 10 deletions src/System.Runtime/tests/System/ArrayTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1431,16 +1431,6 @@ public static void CreateInstance_NegativeLength_ThrowsArgumentOutOfRangeExcepti
Assert.Throws<ArgumentOutOfRangeException>("lengths[0]", () => Array.CreateInstance(typeof(int), new int[] { -1 }, new int[1]));
}

#if netcoreapp
[Fact]
public static void CreateInstance_TypeNotRuntimeType_ThrowsArgumentException()
{
Assert.Throws<ArgumentException>("elementType", () => Array.CreateInstance(Helpers.NonRuntimeType(), 0));
Assert.Throws<ArgumentException>("elementType", () => Array.CreateInstance(Helpers.NonRuntimeType(), new int[1]));
Assert.Throws<ArgumentException>("elementType", () => Array.CreateInstance(Helpers.NonRuntimeType(), new int[1], new int[1]));
}
#endif // netcoreapp

[Fact]
public static void CreateInstance_LengthsNull_ThrowsArgumentNullException()
{
Expand Down
8 changes: 8 additions & 0 deletions src/System.Runtime/tests/System/ArrayTests.netcoreapp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,13 @@ public static void Reverse_Generic_InvalidOffsetPlusLength_ThrowsArgumentExcepti
{
Assert.Throws<ArgumentException>(null, () => Array.Reverse(new string[arrayLength], index, length));
}

[Fact]
public static void CreateInstance_TypeNotRuntimeType_ThrowsArgumentException()
{
Assert.Throws<ArgumentException>("elementType", () => Array.CreateInstance(Helpers.NonRuntimeType(), 0));
Assert.Throws<ArgumentException>("elementType", () => Array.CreateInstance(Helpers.NonRuntimeType(), new int[1]));
Assert.Throws<ArgumentException>("elementType", () => Array.CreateInstance(Helpers.NonRuntimeType(), new int[1], new int[1]));
}
}
}
Loading

0 comments on commit 75c8d08

Please sign in to comment.