summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI.Tests/Core
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-07-06 17:46:04 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-07-06 17:46:04 -0400
commitd928bf188e9ab171223bc07d7209d2887d954642 (patch)
tree66b41d22d97ad2f7e6cfe1773fdf8527abe19b08 /src/StardewModdingAPI.Tests/Core
parente2b9a4bab3e078851a289ad0a19b555dde09308e (diff)
downloadSMAPI-d928bf188e9ab171223bc07d7209d2887d954642.tar.gz
SMAPI-d928bf188e9ab171223bc07d7209d2887d954642.tar.bz2
SMAPI-d928bf188e9ab171223bc07d7209d2887d954642.zip
add optional mod dependencies in SMAPI 2.0 (#287)
Diffstat (limited to 'src/StardewModdingAPI.Tests/Core')
-rw-r--r--src/StardewModdingAPI.Tests/Core/ModResolverTests.cs34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/StardewModdingAPI.Tests/Core/ModResolverTests.cs b/src/StardewModdingAPI.Tests/Core/ModResolverTests.cs
index 36cc3495..b451465e 100644
--- a/src/StardewModdingAPI.Tests/Core/ModResolverTests.cs
+++ b/src/StardewModdingAPI.Tests/Core/ModResolverTests.cs
@@ -411,6 +411,40 @@ namespace StardewModdingAPI.Tests.Core
Assert.AreSame(modB.Object, mods[1], "The load order is incorrect: mod B should be second since it needs mod A.");
}
+#if SMAPI_2_0
+ [Test(Description = "Assert that optional dependencies are sorted correctly if present.")]
+ public void ProcessDependencies_IfOptional()
+ {
+ // arrange
+ // A ◀── B
+ Mock<IModMetadata> modA = this.GetMetadata(this.GetManifest("Mod A", "1.0"));
+ Mock<IModMetadata> modB = this.GetMetadata(this.GetManifest("Mod B", "1.0", new ManifestDependency("Mod A", "1.0", required: false)), allowStatusChange: false);
+
+ // act
+ IModMetadata[] mods = new ModResolver().ProcessDependencies(new[] { modB.Object, modA.Object }).ToArray();
+
+ // assert
+ Assert.AreEqual(2, mods.Length, 0, "Expected to get the same number of mods input.");
+ Assert.AreSame(modA.Object, mods[0], "The load order is incorrect: mod A should be first since it's needed by mod B.");
+ Assert.AreSame(modB.Object, mods[1], "The load order is incorrect: mod B should be second since it needs mod A.");
+ }
+
+ [Test(Description = "Assert that optional dependencies are accepted if they're missing.")]
+ public void ProcessDependencies_IfOptional_SucceedsIfMissing()
+ {
+ // arrange
+ // A ◀── B where A doesn't exist
+ Mock<IModMetadata> modB = this.GetMetadata(this.GetManifest("Mod B", "1.0", new ManifestDependency("Mod A", "1.0", required: false)), allowStatusChange: false);
+
+ // act
+ IModMetadata[] mods = new ModResolver().ProcessDependencies(new[] { modB.Object }).ToArray();
+
+ // assert
+ Assert.AreEqual(1, mods.Length, 0, "Expected to get the same number of mods input.");
+ Assert.AreSame(modB.Object, mods[0], "The load order is incorrect: mod B should be first since it's the only mod.");
+ }
+#endif
+
/*********
** Private methods