Skip to content

Commit fed7430

Browse files
Sergio0694Copilot
andcommitted
Update generic IReference tests to assert NotSupportedException
The collection cases over 'IReference<TypeName>' / 'IReference<HResult>' cannot be marshalled, so the projection now emits a throwing body for them. Update the four generic tests to validate that calling these projected members throws 'NotSupportedException', covering both the return-only and parameter directions for each type, and rename them to reflect the asserted behavior. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 9ac9581 commit fed7430

1 file changed

Lines changed: 20 additions & 28 deletions

File tree

src/Tests/UnitTest/TestComponentCSharp_Tests.cs

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3787,47 +3787,39 @@ public void ReferenceHResultProjectsAsException()
37873787
}
37883788

37893789
[TestMethod]
3790-
public void ReferenceTypeNameListProjectsAsTypeList()
3790+
public void ReferenceTypeNameListReturnThrowsNotSupported()
37913791
{
3792-
// 'IVector<IReference<TypeName>>' projects to the public 'IList<Type>', but the ABI marshaller keeps
3793-
// the 'Nullable<Type>' element marker, so it targets the correct 'IVector<IReference<TypeName>>' IID
3794-
// and boxes/unboxes each element via 'TypeMarshaller'. The list returned from native round-trips with
3795-
// usable 'Type' elements (this is the return-only direction, created entirely in C++).
3796-
IList<Type> list = Class.GetReferenceTypeNameList();
3797-
3798-
Assert.AreEqual(2, list.Count);
3799-
Assert.AreEqual(typeof(Class), list[0]);
3800-
Assert.AreEqual(typeof(int), list[1]);
3792+
// 'IVector<IReference<TypeName>>' projects its public surface as 'IList<Type>', but it cannot be
3793+
// marshalled: 'System.Type' is a reference type, so there is no valid 'Nullable<Type>' collection
3794+
// marshaller for the interop generator to produce. The projected member throws 'NotSupportedException'
3795+
// instead of referencing a marshaller that does not exist (return-only direction, created in C++)
3796+
Assert.ThrowsExactly<NotSupportedException>(() => Class.GetReferenceTypeNameList());
38013797
}
38023798

38033799
[TestMethod]
3804-
public void ReferenceTypeNameListAsParameter()
3800+
public void ReferenceTypeNameListParameterThrowsNotSupported()
38053801
{
3806-
// Passing a managed 'IList<Type>' to a native 'IVector<IReference<TypeName>>' parameter (the native
3807-
// side only reads the count here, which is element-agnostic)
3808-
Assert.AreEqual(2, Class.CountReferenceTypeNameList(new List<Type> { typeof(Class), typeof(int) }));
3802+
// Same limitation as the return direction: passing a managed 'IList<Type>' to a native
3803+
// 'IVector<IReference<TypeName>>' parameter throws 'NotSupportedException'
3804+
Assert.ThrowsExactly<NotSupportedException>(() => Class.CountReferenceTypeNameList(new List<Type> { typeof(Class), typeof(int) }));
38093805
}
38103806

38113807
[TestMethod]
3812-
public void ReferenceHResultListProjectsAsExceptionList()
3808+
public void ReferenceHResultListReturnThrowsNotSupported()
38133809
{
3814-
// 'IVector<IReference<HResult>>' projects to the public 'IList<Exception>', but the ABI marshaller keeps
3815-
// the 'Nullable<Exception>' element marker, so it targets the correct 'IVector<IReference<HResult>>' IID
3816-
// and boxes/unboxes each element via 'ExceptionMarshaller'. The list returned from native round-trips
3817-
// with usable 'Exception' elements (this is the return-only direction, created entirely in C++).
3818-
IList<Exception> list = Class.GetReferenceHResultList();
3819-
3820-
Assert.AreEqual(1, list.Count);
3821-
Assert.IsNotNull(list[0]);
3822-
Assert.AreEqual(unchecked((int)0x80070057), list[0].HResult); // 'E_INVALIDARG'
3810+
// 'IVector<IReference<HResult>>' projects its public surface as 'IList<Exception>', but it cannot be
3811+
// marshalled: 'System.Exception' is a reference type, so there is no valid 'Nullable<Exception>' collection
3812+
// marshaller for the interop generator to produce. The projected member throws 'NotSupportedException'
3813+
// instead of referencing a marshaller that does not exist (return-only direction, created in C++)
3814+
Assert.ThrowsExactly<NotSupportedException>(() => Class.GetReferenceHResultList());
38233815
}
38243816

38253817
[TestMethod]
3826-
public void ReferenceHResultListAsParameter()
3818+
public void ReferenceHResultListParameterThrowsNotSupported()
38273819
{
3828-
// Passing a managed 'IList<Exception>' to a native 'IVector<IReference<HResult>>' parameter (the native
3829-
// side only reads the count here, which is element-agnostic)
3830-
Assert.AreEqual(2, Class.CountReferenceHResultList(new List<Exception> { new ArgumentException(), new InvalidOperationException() }));
3820+
// Same limitation as the return direction: passing a managed 'IList<Exception>' to a native
3821+
// 'IVector<IReference<HResult>>' parameter throws 'NotSupportedException'
3822+
Assert.ThrowsExactly<NotSupportedException>(() => Class.CountReferenceHResultList(new List<Exception> { new ArgumentException(), new InvalidOperationException() }));
38313823
}
38323824

38333825
[TestMethod]

0 commit comments

Comments
 (0)