From 20224d293d03d34860505980cabdb4bc5cf13319 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 16 Apr 2022 16:59:53 -0400 Subject: add unit test for proxied out parameters --- src/SMAPI.Tests/Core/InterfaceProxyTests.cs | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src/SMAPI.Tests/Core') diff --git a/src/SMAPI.Tests/Core/InterfaceProxyTests.cs b/src/SMAPI.Tests/Core/InterfaceProxyTests.cs index 0b4919ed..8d27f6af 100644 --- a/src/SMAPI.Tests/Core/InterfaceProxyTests.cs +++ b/src/SMAPI.Tests/Core/InterfaceProxyTests.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using System.Linq; using System.Reflection; using FluentAssertions; using NUnit.Framework; @@ -8,6 +9,7 @@ using SMAPI.Tests.ModApiConsumer; using SMAPI.Tests.ModApiConsumer.Interfaces; using SMAPI.Tests.ModApiProvider; using StardewModdingAPI.Framework.Reflection; +using StardewModdingAPI.Utilities; namespace SMAPI.Tests.Core { @@ -308,6 +310,43 @@ namespace SMAPI.Tests.Core actualValue.Should().BeSameAs(expectedValue); } + /// Assert that a method with out parameters can be proxied correctly. + [Test] + [SuppressMessage("ReSharper", "ConvertToLocalFunction")] + public void CanProxy_Method_OutParameters() + { + // arrange + object implementation = new ProviderMod().GetModApi(); + const int expectedNumber = 42; + + // act + ISimpleApi proxy = this.GetProxy(implementation); + bool result = proxy.TryGetOutParameter( + inputNumber: expectedNumber, + + out int outNumber, + out string outString, + out PerScreen outReference, + out IDictionary> outComplexType + ); + + // assert + result.Should().BeTrue(); + + outNumber.Should().Be(expectedNumber); + + outString.Should().Be(expectedNumber.ToString()); + + outReference.Should().NotBeNull(); + outReference.Value.Should().Be(expectedNumber); + + outComplexType.Should().NotBeNull(); + outComplexType.Count.Should().Be(1); + outComplexType.Keys.First().Should().Be(expectedNumber); + outComplexType.Values.First().Should().NotBeNull(); + outComplexType.Values.First().Value.Should().Be(expectedNumber); + } + /********* ** Private methods -- cgit