summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-04-16 16:59:53 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-04-16 16:59:53 -0400
commit20224d293d03d34860505980cabdb4bc5cf13319 (patch)
tree36e9e6da9abe939e7f84f6c42b7a4d9cb703eec3 /src
parent559d763756e3ccbd7feaa3b82d7924d8cd97969f (diff)
downloadSMAPI-20224d293d03d34860505980cabdb4bc5cf13319.tar.gz
SMAPI-20224d293d03d34860505980cabdb4bc5cf13319.tar.bz2
SMAPI-20224d293d03d34860505980cabdb4bc5cf13319.zip
add unit test for proxied out parameters
Diffstat (limited to 'src')
-rw-r--r--src/SMAPI.Tests.ModApiConsumer/Interfaces/ISimpleApi.cs4
-rw-r--r--src/SMAPI.Tests.ModApiProvider/Framework/SimpleApi.cs15
-rw-r--r--src/SMAPI.Tests.ModApiProvider/SMAPI.Tests.ModApiProvider.csproj4
-rw-r--r--src/SMAPI.Tests/Core/InterfaceProxyTests.cs39
4 files changed, 62 insertions, 0 deletions
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
/// <summary>A simple method which returns a lambda.</summary>
Func<string, string> GetLambda(Func<string, string> value);
+ /// <summary>A simple method which returns out parameters.</summary>
+ bool TryGetOutParameter(int inputNumber, out int outNumber, out string outString, out PerScreen<int> outReference, out IDictionary<int, PerScreen<int>> 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;
}
+ /// <summary>A simple method which returns out parameters.</summary>
+ public bool TryGetOutParameter(int inputNumber, out int outNumber, out string outString, out PerScreen<int> outReference, out IDictionary<int, PerScreen<int>> outComplexType)
+ {
+ outNumber = inputNumber;
+ outString = inputNumber.ToString();
+ outReference = new PerScreen<int>(() => inputNumber);
+ outComplexType = new Dictionary<int, PerScreen<int>>
+ {
+ [inputNumber] = new PerScreen<int>(() => 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 @@
</PropertyGroup>
<Import Project="..\..\build\common.targets" />
+
+ <ItemGroup>
+ <ProjectReference Include="..\SMAPI\SMAPI.csproj" />
+ </ItemGroup>
</Project>
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);
}
+ /// <summary>Assert that a method with out parameters can be proxied correctly.</summary>
+ [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<int> outReference,
+ out IDictionary<int, PerScreen<int>> 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