From 93167a6e1b106c0c1076e767c65c7d9797bcffd0 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 20 Nov 2023 19:28:34 +0100 Subject: [PATCH] Update test to work around CsWinRT marshalling issue See https://github.com/microsoft/CsWinRT/issues/1393 --- .../Tests/CanvasEffectTests.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/ComputeSharp.D2D1.WinUI.Tests/Tests/CanvasEffectTests.cs b/tests/ComputeSharp.D2D1.WinUI.Tests/Tests/CanvasEffectTests.cs index ec58ee95..25e1e08c 100644 --- a/tests/ComputeSharp.D2D1.WinUI.Tests/Tests/CanvasEffectTests.cs +++ b/tests/ComputeSharp.D2D1.WinUI.Tests/Tests/CanvasEffectTests.cs @@ -90,9 +90,11 @@ public partial class CanvasEffectTests } [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 @@ -102,8 +104,14 @@ public partial class CanvasEffectTests 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;