summaryrefslogtreecommitdiff
path: root/src/SMAPI.Tests.ModApiProvider/Framework/SimpleApi.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-02-10 22:03:09 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-02-10 22:03:09 -0500
commit3064b58719060a145058ab295792d8c97128b433 (patch)
treef78239aac67e00f033a02c24cafe731332832c35 /src/SMAPI.Tests.ModApiProvider/Framework/SimpleApi.cs
parent25a9f54ecfdaf6c4ad67dfb46c3f8c556d15d949 (diff)
downloadSMAPI-3064b58719060a145058ab295792d8c97128b433.tar.gz
SMAPI-3064b58719060a145058ab295792d8c97128b433.tar.bz2
SMAPI-3064b58719060a145058ab295792d8c97128b433.zip
add basic unit tests for API interface proxying
Diffstat (limited to 'src/SMAPI.Tests.ModApiProvider/Framework/SimpleApi.cs')
-rw-r--r--src/SMAPI.Tests.ModApiProvider/Framework/SimpleApi.cs108
1 files changed, 108 insertions, 0 deletions
diff --git a/src/SMAPI.Tests.ModApiProvider/Framework/SimpleApi.cs b/src/SMAPI.Tests.ModApiProvider/Framework/SimpleApi.cs
new file mode 100644
index 00000000..1100af36
--- /dev/null
+++ b/src/SMAPI.Tests.ModApiProvider/Framework/SimpleApi.cs
@@ -0,0 +1,108 @@
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+
+namespace SMAPI.Tests.ModApiProvider.Framework
+{
+ /// <summary>A mod-provided API which provides basic events, properties, and methods.</summary>
+ public class SimpleApi : BaseApi
+ {
+ /*********
+ ** Test interface
+ *********/
+ /****
+ ** Events
+ ****/
+ /// <summary>A simple event field.</summary>
+ public event EventHandler<int> OnEventRaised;
+
+ /// <summary>A simple event property with custom add/remove logic.</summary>
+ public event EventHandler<int> OnEventRaisedProperty
+ {
+ add => this.OnEventRaised += value;
+ remove => this.OnEventRaised -= value;
+ }
+
+
+ /****
+ ** Properties
+ ****/
+ /// <summary>A simple numeric property.</summary>
+ public int NumberProperty { get; set; }
+
+ /// <summary>A simple object property.</summary>
+ public object ObjectProperty { get; set; }
+
+ /// <summary>A simple list property.</summary>
+ public List<string> ListProperty { get; set; }
+
+ /// <summary>A simple list property with an interface.</summary>
+ public IList<string> ListPropertyWithInterface { get; set; }
+
+ /// <summary>A property with nested generics.</summary>
+ public IDictionary<string, IList<string>> GenericsProperty { get; set; }
+
+ /// <summary>A property using an enum available to both mods.</summary>
+ public BindingFlags EnumProperty { get; set; }
+
+ /// <summary>A read-only property.</summary>
+ public int GetterProperty => 42;
+
+
+ /****
+ ** Methods
+ ****/
+ /// <summary>A simple method with no return value.</summary>
+ public void GetNothing() { }
+
+ /// <summary>A simple method which returns a number.</summary>
+ public int GetInt(int value)
+ {
+ return value;
+ }
+
+ /// <summary>A simple method which returns an object.</summary>
+ public object GetObject(object value)
+ {
+ return value;
+ }
+
+ /// <summary>A simple method which returns a list.</summary>
+ public List<string> GetList(string value)
+ {
+ return new() { value };
+ }
+
+ /// <summary>A simple method which returns a list with an interface.</summary>
+ public IList<string> GetListWithInterface(string value)
+ {
+ return new List<string> { value };
+ }
+
+ /// <summary>A simple method which returns nested generics.</summary>
+ public IDictionary<string, IList<string>> GetGenerics(string key, string value)
+ {
+ return new Dictionary<string, IList<string>>
+ {
+ [key] = new List<string> { value }
+ };
+ }
+
+ /// <summary>A simple method which returns a lambda.</summary>
+ public Func<string, string> GetLambda(Func<string, string> value)
+ {
+ return value;
+ }
+
+
+ /*********
+ ** Helper methods
+ *********/
+ /// <summary>Raise the <see cref="OnEventRaised"/> event.</summary>
+ /// <param name="value">The value to pass to the event.</param>
+ public void RaiseEventField(int value)
+ {
+ this.OnEventRaised?.Invoke(null, value);
+ }
+ }
+}