diff --git a/src/SMAPI.Tests.ModApiConsumer/Interfaces/ISimpleApi.cs b/src/SMAPI.Tests.ModApiConsumer/Interfaces/ISimpleApi.cs index 7f94e137..c99605e4 100644 --- a/src/SMAPI.Tests.ModApiConsumer/Interfaces/ISimpleApi.cs +++ b/src/SMAPI.Tests.ModApiConsumer/Interfaces/ISimpleApi.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Reflection; +using StardewModdingAPI.Utilities; namespace SMAPI.Tests.ModApiConsumer.Interfaces { @@ -69,6 +70,9 @@ namespace SMAPI.Tests.ModApiConsumer.Interfaces /// A simple method which returns a lambda. Func GetLambda(Func value); + /// A simple method which returns out parameters. + bool TryGetOutParameter(int inputNumber, out int outNumber, out string outString, out PerScreen outReference, out IDictionary> outComplexType); + /**** ** Inherited members diff --git a/src/SMAPI.Tests.ModApiProvider/Framework/SimpleApi.cs b/src/SMAPI.Tests.ModApiProvider/Framework/SimpleApi.cs index e7e1ccef..c8781da5 100644 --- a/src/SMAPI.Tests.ModApiProvider/Framework/SimpleApi.cs +++ b/src/SMAPI.Tests.ModApiProvider/Framework/SimpleApi.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Reflection; +using StardewModdingAPI.Utilities; namespace SMAPI.Tests.ModApiProvider.Framework { @@ -96,6 +97,20 @@ namespace SMAPI.Tests.ModApiProvider.Framework return value; } + /// A simple method which returns out parameters. + public bool TryGetOutParameter(int inputNumber, out int outNumber, out string outString, out PerScreen outReference, out IDictionary> outComplexType) + { + outNumber = inputNumber; + outString = inputNumber.ToString(); + outReference = new PerScreen(() => inputNumber); + outComplexType = new Dictionary> + { + [inputNumber] = new PerScreen(() => inputNumber) + }; + + return true; + } + /********* ** Helper methods diff --git a/src/SMAPI.Tests.ModApiProvider/SMAPI.Tests.ModApiProvider.csproj b/src/SMAPI.Tests.ModApiProvider/SMAPI.Tests.ModApiProvider.csproj index 70d5a0ce..7fef4ebd 100644 --- a/src/SMAPI.Tests.ModApiProvider/SMAPI.Tests.ModApiProvider.csproj +++ b/src/SMAPI.Tests.ModApiProvider/SMAPI.Tests.ModApiProvider.csproj @@ -4,4 +4,8 @@ + + + + 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