add unit test for proxied out parameters
This commit is contained in:
parent
559d763756
commit
20224d293d
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -4,4 +4,8 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<Import Project="..\..\build\common.targets" />
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SMAPI\SMAPI.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue