summaryrefslogtreecommitdiff
path: root/src/SMAPI.Tests.ModApiConsumer/ApiConsumer.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-05-01 18:16:09 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-05-01 18:16:09 -0400
commitc8ad50dad1d706a1901798f9396f6becfea36c0e (patch)
tree28bd818a5db39ec5ece1bd141a28de955950463b /src/SMAPI.Tests.ModApiConsumer/ApiConsumer.cs
parent451b70953ff4c0b1b27ae0de203ad99379b45b2a (diff)
parentf78093bdb58d477b400cde3f19b70ffd6ddf833d (diff)
downloadSMAPI-c8ad50dad1d706a1901798f9396f6becfea36c0e.tar.gz
SMAPI-c8ad50dad1d706a1901798f9396f6becfea36c0e.tar.bz2
SMAPI-c8ad50dad1d706a1901798f9396f6becfea36c0e.zip
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI.Tests.ModApiConsumer/ApiConsumer.cs')
-rw-r--r--src/SMAPI.Tests.ModApiConsumer/ApiConsumer.cs46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/SMAPI.Tests.ModApiConsumer/ApiConsumer.cs b/src/SMAPI.Tests.ModApiConsumer/ApiConsumer.cs
new file mode 100644
index 00000000..ac7bd338
--- /dev/null
+++ b/src/SMAPI.Tests.ModApiConsumer/ApiConsumer.cs
@@ -0,0 +1,46 @@
+using System;
+using SMAPI.Tests.ModApiConsumer.Interfaces;
+
+namespace SMAPI.Tests.ModApiConsumer
+{
+ /// <summary>A simulated API consumer.</summary>
+ public class ApiConsumer
+ {
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Call the event field on the given API.</summary>
+ /// <param name="api">The API to call.</param>
+ /// <param name="getValues">Get the number of times the event was called and the last value received.</param>
+ public void UseEventField(ISimpleApi api, out Func<(int timesCalled, int actualValue)> getValues)
+ {
+ // act
+ int calls = 0;
+ int lastValue = -1;
+ api.OnEventRaised += (_, value) =>
+ {
+ calls++;
+ lastValue = value;
+ };
+
+ getValues = () => (timesCalled: calls, actualValue: lastValue);
+ }
+
+ /// <summary>Call the event property on the given API.</summary>
+ /// <param name="api">The API to call.</param>
+ /// <param name="getValues">Get the number of times the event was called and the last value received.</param>
+ public void UseEventProperty(ISimpleApi api, out Func<(int timesCalled, int actualValue)> getValues)
+ {
+ // act
+ int calls = 0;
+ int lastValue = -1;
+ api.OnEventRaisedProperty += (_, value) =>
+ {
+ calls++;
+ lastValue = value;
+ };
+
+ getValues = () => (timesCalled: calls, actualValue: lastValue);
+ }
+ }
+}