Skip to content

Commit

Permalink
Update test to work around CsWinRT marshalling issue
Browse files Browse the repository at this point in the history
Port of 93167a6
  • Loading branch information
Sergio0694 committed Oct 12, 2024
1 parent a543bf6 commit 2fda693
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions tests/ComputeSharp.D2D1.UI.Tests/CanvasEffectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@ public void CanvasEffect_EffectSettingNotRegisteredOutputNode()
}

[TestMethod]
[ExpectedException(typeof(InvalidOperationException))]
[ExpectedException(typeof(Exception), AllowDerivedTypes = true)]
public void CanvasEffect_EffectNotRegisteringAnOutputNode()
{
const int COR_E_INVALIDOPERATION = unchecked((int)0x80131509);

EffectNotRegisteringAnOutputNode effect = new();

try
Expand All @@ -109,8 +111,14 @@ public void CanvasEffect_EffectNotRegisteringAnOutputNode()

drawingSession.DrawImage(effect);
}
catch
catch (Exception e)
{
// Note: this test should ideally expect and catch an InvalidOperationException, as that's the exception
// type thrown by CanvasEffect. But it seems that CsWinRT isn't correctly forwarding the exception type
// in this case, and it ends up only throwing a COMException on the managed side. To work around this in
// this test, we can just catch a generic Exception and manually verify that the HRESULT is a match.
// See https://github.com/microsoft/CsWinRT/issues/1393 (and ideally update the test once that's fixed).
Assert.AreEqual(COR_E_INVALIDOPERATION, e.HResult);
Assert.IsTrue(effect.WasConfigureEffectGraphCalled);

throw;
Expand Down

0 comments on commit 2fda693

Please sign in to comment.