Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ public void CastClass_ArrayToGenericInterface_ComparesElementType()

Assert.IsNotNull((IEnumerable<int>)value);
Assert.ThrowsException(typeof(InvalidCastException), () => { _ = (IEnumerable<string>)value; });
Assert.ThrowsException(typeof(InvalidCastException), () => { _ = (IEnumerable<uint>)value; });
Assert.IsNotNull((IEnumerable<uint>)value);
Assert.ThrowsException(typeof(InvalidCastException), () => { _ = (IEnumerable<long>)value; });
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<Compile Include="UnitTestGenericParameterTypeTests.cs" />
<Compile Include="UnitTestGenericParameterConstraintTests.cs" />
<Compile Include="UnitTestGenericTypeIdentityTests.cs" />
<Compile Include="UnitTestGenericVarianceTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,13 +384,13 @@ public void EnumConstraint_IsNotSupported()
}

[TestMethod]
public void VariantInterface_NeedsVariance_IsNotSupported()
public void VariantInterface_UsesVariance()
{
Type t = Arg(typeof(GcVariant<>));

Assert.IsTrue(typeof(IGcOut<string>).IsAssignableFrom(t));
Assert.IsTrue(ThrowsNotSupported(() => (object)typeof(IGcOut<int>).IsAssignableFrom(t)));
Assert.IsTrue(ThrowsNotSupported(() => (object)typeof(IGcOut<object>).IsAssignableFrom(t)));
Assert.IsFalse(typeof(IGcOut<int>).IsAssignableFrom(t));
Assert.IsTrue(typeof(IGcOut<object>).IsAssignableFrom(t));
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,11 +479,11 @@ public void Assignable_ArraysAsInterfaces()
}

[TestMethod]
public void Assignable_VarianceUnsupported()
public void Assignable_Variance()
{
Assert.IsTrue(Throws(() => typeof(IEnumerable<object>).IsAssignableFrom(typeof(IdEnumerable))));
Assert.IsTrue(Throws(() => typeof(IEnumerable<object>).IsAssignableFrom(typeof(IEnumerable<string>))));
Assert.IsTrue(Throws(() => typeof(Func<object>).IsAssignableFrom(typeof(Func<string>))));
Assert.IsTrue(typeof(IEnumerable<object>).IsAssignableFrom(typeof(IdEnumerable)));
Assert.IsTrue(typeof(IEnumerable<object>).IsAssignableFrom(typeof(IEnumerable<string>)));
Assert.IsTrue(typeof(Func<object>).IsAssignableFrom(typeof(Func<string>)));

// the same arguments are exact, and so is an unrelated definition
Assert.IsTrue(typeof(IEnumerable<string>).IsAssignableFrom(typeof(IdEnumerable)));
Expand All @@ -497,15 +497,15 @@ public void Assignable_ExactMatchWinsOverVariance()
// both interfaces are implemented, the exact one is found whatever the order of the table
Assert.IsTrue(typeof(IEnumerable<string>).IsAssignableFrom(typeof(IdBothEnumerables)));
Assert.IsTrue(typeof(IEnumerable<object>).IsAssignableFrom(typeof(IdBothEnumerables)));
Assert.IsTrue(Throws(() => typeof(IEnumerable<IdBoxK<int>>).IsAssignableFrom(typeof(IdBothEnumerables))));
Assert.IsFalse(typeof(IEnumerable<IdBoxK<int>>).IsAssignableFrom(typeof(IdBothEnumerables)));
}

[TestMethod]
public void Assignable_IntegralArraysUnsupported()
public void Assignable_IntegralArrays()
{
Assert.IsTrue(Throws(() => typeof(int[]).IsAssignableFrom(typeof(uint[]))));
Assert.IsTrue(Throws(() => typeof(IdEnumB[]).IsAssignableFrom(typeof(int[]))));
Assert.IsTrue(Throws(() => typeof(int[][]).IsAssignableFrom(typeof(uint[][]))));
Assert.IsTrue(typeof(int[]).IsAssignableFrom(typeof(uint[])));
Assert.IsTrue(typeof(IdEnumB[]).IsAssignableFrom(typeof(int[])));
Assert.IsTrue(typeof(int[][]).IsAssignableFrom(typeof(uint[][])));
}

#endregion
Expand Down
Loading
Loading