Extend IDynamicInterfaceCastable test to cover public default-implemented methods...
authorJeremy Koritzinsky <jekoritz@microsoft.com>
Fri, 25 Sep 2020 03:05:32 +0000 (20:05 -0700)
committerGitHub <noreply@github.com>
Fri, 25 Sep 2020 03:05:32 +0000 (20:05 -0700)
* Extend IDynamicInterfaceCastable test suite to validate current behavior around calling a default-implemented public method defined on the interface impl type.

* Change implementation to use Assert.Fail to describe failure.

* Add public modifier.

Signed-off-by: Jeremy Koritzinsky <jekoritz@microsoft.com>
* Fix failures.

src/tests/Interop/IDynamicInterfaceCastable/Program.cs

index 2cf471f..00e9863 100644 (file)
@@ -14,7 +14,8 @@ namespace IDynamicInterfaceCastableTests
         Class,
         Interface,
         InterfacePrivate,
-        InterfaceStatic
+        InterfaceStatic,
+        ImplInterfacePublic,
     }
 
     public interface ITest
@@ -68,6 +69,12 @@ namespace IDynamicInterfaceCastableTests
             return GetNumberStaticReturnValue;
         }
 
+        public int GetNumberHelper()
+        {
+            Assert.Fail("Calling a public interface method with a default implementation should go through IDynamicInterfaceCastable for interface dispatch.");
+            return 0;
+        }
+
         int ITest.CallImplemented(ImplementationToCall toCall)
         {
             switch (toCall)
@@ -81,6 +88,8 @@ namespace IDynamicInterfaceCastableTests
                     return GetNumberPrivate();
                 case ImplementationToCall.InterfaceStatic:
                     return GetNumberStatic();
+                case ImplementationToCall.ImplInterfacePublic:
+                    return GetNumberHelper();
             }
 
             return 0;
@@ -291,6 +300,7 @@ namespace IDynamicInterfaceCastableTests
             Assert.AreEqual(ITestImpl.GetNumberReturnValue, testObj.CallImplemented(ImplementationToCall.Interface));
             Assert.AreEqual(ITestImpl.GetNumberPrivateReturnValue, testObj.CallImplemented(ImplementationToCall.InterfacePrivate));
             Assert.AreEqual(ITestImpl.GetNumberStaticReturnValue, testObj.CallImplemented(ImplementationToCall.InterfaceStatic));
+            Assert.Throws<InvalidCastException>(() => testObj.CallImplemented(ImplementationToCall.ImplInterfacePublic));
 
             Console.WriteLine(" -- Validate delegate call");
             Func<ITest> func = new Func<ITest>(testObj.ReturnThis);