summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-05-19 18:04:57 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-05-19 18:04:57 -0400
commit16281fb58944e7e829b184b014e27822c91c9f43 (patch)
treee9db3b9943d61163a87190c4293673a002d17da1 /src
parentc84310dfebafd3085dc418f3620154f9934865de (diff)
parentcbb1777ba00f581b428e61a0f7245a87ac53cf09 (diff)
downloadSMAPI-16281fb58944e7e829b184b014e27822c91c9f43.tar.gz
SMAPI-16281fb58944e7e829b184b014e27822c91c9f43.tar.bz2
SMAPI-16281fb58944e7e829b184b014e27822c91c9f43.zip
Merge branch 'develop' into stable
Diffstat (limited to 'src')
-rw-r--r--src/.editorconfig2
-rw-r--r--src/StardewModdingAPI.AssemblyRewriters/StardewModdingAPI.AssemblyRewriters.csproj24
-rw-r--r--src/StardewModdingAPI.Installer/InteractiveInstaller.cs53
-rw-r--r--src/StardewModdingAPI.Installer/StardewModdingAPI.Installer.csproj10
-rw-r--r--src/StardewModdingAPI.Tests/Framework/Sample.cs30
-rw-r--r--src/StardewModdingAPI.Tests/ModResolverTests.cs399
-rw-r--r--src/StardewModdingAPI.Tests/Properties/AssemblyInfo.cs6
-rw-r--r--src/StardewModdingAPI.Tests/StardewModdingAPI.Tests.csproj65
-rw-r--r--src/StardewModdingAPI.Tests/packages.config7
-rw-r--r--src/StardewModdingAPI.sln86
-rw-r--r--src/StardewModdingAPI/Constants.cs8
-rw-r--r--src/StardewModdingAPI/Context.cs17
-rw-r--r--src/StardewModdingAPI/Events/ContentEvents.cs7
-rw-r--r--src/StardewModdingAPI/Events/ControlEvents.cs20
-rw-r--r--src/StardewModdingAPI/Events/GameEvents.cs39
-rw-r--r--src/StardewModdingAPI/Framework/Countdown.cs44
-rw-r--r--src/StardewModdingAPI/Framework/InternalExtensions.cs22
-rw-r--r--src/StardewModdingAPI/Framework/ModHelper.cs7
-rw-r--r--src/StardewModdingAPI/Framework/ModLoading/AssemblyDefinitionResolver.cs (renamed from src/StardewModdingAPI/Framework/AssemblyDefinitionResolver.cs)2
-rw-r--r--src/StardewModdingAPI/Framework/ModLoading/AssemblyLoader.cs (renamed from src/StardewModdingAPI/Framework/AssemblyLoader.cs)2
-rw-r--r--src/StardewModdingAPI/Framework/ModLoading/AssemblyParseResult.cs (renamed from src/StardewModdingAPI/Framework/AssemblyParseResult.cs)2
-rw-r--r--src/StardewModdingAPI/Framework/ModLoading/IModMetadata.cs39
-rw-r--r--src/StardewModdingAPI/Framework/ModLoading/InvalidModStateException.cs14
-rw-r--r--src/StardewModdingAPI/Framework/ModLoading/ModDependencyStatus.cs18
-rw-r--r--src/StardewModdingAPI/Framework/ModLoading/ModMetadata.cs57
-rw-r--r--src/StardewModdingAPI/Framework/ModLoading/ModMetadataStatus.cs12
-rw-r--r--src/StardewModdingAPI/Framework/ModLoading/ModResolver.cs291
-rw-r--r--src/StardewModdingAPI/Framework/ModRegistry.cs28
-rw-r--r--src/StardewModdingAPI/Framework/Models/Manifest.cs (renamed from src/StardewModdingAPI/Framework/Manifest.cs)11
-rw-r--r--src/StardewModdingAPI/Framework/Models/ManifestDependency.cs23
-rw-r--r--src/StardewModdingAPI/Framework/Models/ModCompatibility.cs7
-rw-r--r--src/StardewModdingAPI/Framework/Models/SConfig.cs3
-rw-r--r--src/StardewModdingAPI/Framework/SGame.cs1968
-rw-r--r--src/StardewModdingAPI/Framework/Serialisation/ManifestFieldConverter.cs (renamed from src/StardewModdingAPI/Framework/Serialisation/SemanticVersionConverter.cs)39
-rw-r--r--src/StardewModdingAPI/IManifest.cs22
-rw-r--r--src/StardewModdingAPI/IManifestDependency.cs12
-rw-r--r--src/StardewModdingAPI/Mod.cs21
-rw-r--r--src/StardewModdingAPI/Program.cs281
-rw-r--r--src/StardewModdingAPI/Properties/AssemblyInfo.cs3
-rw-r--r--src/StardewModdingAPI/SemanticVersion.cs17
-rw-r--r--src/StardewModdingAPI/StardewModdingAPI.config.json312
-rw-r--r--src/StardewModdingAPI/StardewModdingAPI.csproj49
-rw-r--r--src/TrainerMod/TrainerMod.cs10
-rw-r--r--src/TrainerMod/TrainerMod.csproj9
-rw-r--r--src/crossplatform.targets1
-rw-r--r--src/prepare-install-package.targets3
46 files changed, 2711 insertions, 1391 deletions
diff --git a/src/.editorconfig b/src/.editorconfig
index 3037884e..132fe6cb 100644
--- a/src/.editorconfig
+++ b/src/.editorconfig
@@ -11,6 +11,8 @@ indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
+[*.json]
+indent_size = 2
##########
## C# formatting
diff --git a/src/StardewModdingAPI.AssemblyRewriters/StardewModdingAPI.AssemblyRewriters.csproj b/src/StardewModdingAPI.AssemblyRewriters/StardewModdingAPI.AssemblyRewriters.csproj
index 775de9f2..e25b201e 100644
--- a/src/StardewModdingAPI.AssemblyRewriters/StardewModdingAPI.AssemblyRewriters.csproj
+++ b/src/StardewModdingAPI.AssemblyRewriters/StardewModdingAPI.AssemblyRewriters.csproj
@@ -3,7 +3,7 @@
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProjectGuid>{10DB0676-9FC1-4771-A2C8-E2519F091E49}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
@@ -12,7 +12,7 @@
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
@@ -21,7 +21,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
@@ -29,24 +29,6 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
- <DebugSymbols>true</DebugSymbols>
- <OutputPath>bin\x86\Debug\</OutputPath>
- <DefineConstants>DEBUG;TRACE;SMAPI_FOR_WINDOWS</DefineConstants>
- <DebugType>full</DebugType>
- <PlatformTarget>x86</PlatformTarget>
- <ErrorReport>prompt</ErrorReport>
- <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
- <OutputPath>bin\x86\Release\</OutputPath>
- <DefineConstants>TRACE;SMAPI_FOR_WINDOWS</DefineConstants>
- <Optimize>true</Optimize>
- <DebugType>pdbonly</DebugType>
- <PlatformTarget>x86</PlatformTarget>
- <ErrorReport>prompt</ErrorReport>
- <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
- </PropertyGroup>
<ItemGroup>
<Reference Include="Mono.Cecil, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.dll</HintPath>
diff --git a/src/StardewModdingAPI.Installer/InteractiveInstaller.cs b/src/StardewModdingAPI.Installer/InteractiveInstaller.cs
index 86e3d38a..01f7a01f 100644
--- a/src/StardewModdingAPI.Installer/InteractiveInstaller.cs
+++ b/src/StardewModdingAPI.Installer/InteractiveInstaller.cs
@@ -27,32 +27,39 @@ namespace StardewModdingApi.Installer
switch (platform)
{
case Platform.Mono:
- // Linux
- yield return $"{Environment.GetEnvironmentVariable("HOME")}/GOG Games/Stardew Valley/game";
- yield return $"{Environment.GetEnvironmentVariable("HOME")}/.local/share/Steam/steamapps/common/Stardew Valley";
- yield return $"{Environment.GetEnvironmentVariable("HOME")}/.steam/steam/steamapps/common/Stardew Valley";
-
- // Mac
- yield return "/Applications/Stardew Valley.app/Contents/MacOS";
- yield return $"{Environment.GetEnvironmentVariable("HOME")}/Library/Application Support/Steam/steamapps/common/Stardew Valley/Contents/MacOS";
+ {
+ string home = Environment.GetEnvironmentVariable("HOME");
+
+ // Linux
+ yield return $"{home}/GOG Games/Stardew Valley/game";
+ yield return Directory.Exists($"{home}/.steam/steam/steamapps/common/Stardew Valley")
+ ? $"{home}/.steam/steam/steamapps/common/Stardew Valley"
+ : $"{home}/.local/share/Steam/steamapps/common/Stardew Valley";
+
+ // Mac
+ yield return "/Applications/Stardew Valley.app/Contents/MacOS";
+ yield return $"{home}/Library/Application Support/Steam/steamapps/common/Stardew Valley/Contents/MacOS";
+ }
break;
case Platform.Windows:
- // Windows
- yield return @"C:\Program Files (x86)\GalaxyClient\Games\Stardew Valley";
- yield return @"C:\Program Files (x86)\Steam\steamapps\common\Stardew Valley";
-
- // Windows registry
- IDictionary<string, string> registryKeys = new Dictionary<string, string>
- {
- [@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 413150"] = "InstallLocation", // Steam
- [@"SOFTWARE\WOW6432Node\GOG.com\Games\1453375253"] = "PATH", // GOG on 64-bit Windows
- };
- foreach (var pair in registryKeys)
{
- string path = this.GetLocalMachineRegistryValue(pair.Key, pair.Value);
- if (!string.IsNullOrWhiteSpace(path))
- yield return path;
+ // Windows
+ yield return @"C:\Program Files (x86)\GalaxyClient\Games\Stardew Valley";
+ yield return @"C:\Program Files (x86)\Steam\steamapps\common\Stardew Valley";
+
+ // Windows registry
+ IDictionary<string, string> registryKeys = new Dictionary<string, string>
+ {
+ [@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 413150"] = "InstallLocation", // Steam
+ [@"SOFTWARE\WOW6432Node\GOG.com\Games\1453375253"] = "PATH", // GOG on 64-bit Windows
+ };
+ foreach (var pair in registryKeys)
+ {
+ string path = this.GetLocalMachineRegistryValue(pair.Key, pair.Value);
+ if (!string.IsNullOrWhiteSpace(path))
+ yield return path;
+ }
}
break;
@@ -511,7 +518,7 @@ namespace StardewModdingApi.Installer
// get installed paths
DirectoryInfo[] defaultPaths =
(
- from path in this.GetDefaultInstallPaths(platform).Distinct()
+ from path in this.GetDefaultInstallPaths(platform).Distinct(StringComparer.InvariantCultureIgnoreCase)
let dir = new DirectoryInfo(path)
where dir.Exists && dir.EnumerateFiles(executableFilename).Any()
select dir
diff --git a/src/StardewModdingAPI.Installer/StardewModdingAPI.Installer.csproj b/src/StardewModdingAPI.Installer/StardewModdingAPI.Installer.csproj
index 366e1c6e..765364dc 100644
--- a/src/StardewModdingAPI.Installer/StardewModdingAPI.Installer.csproj
+++ b/src/StardewModdingAPI.Installer/StardewModdingAPI.Installer.csproj
@@ -3,7 +3,7 @@
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProjectGuid>{443DDF81-6AAF-420A-A610-3459F37E5575}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
@@ -13,8 +13,8 @@
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <PlatformTarget>AnyCPU</PlatformTarget>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+ <PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
@@ -23,8 +23,8 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
- <PlatformTarget>AnyCPU</PlatformTarget>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+ <PlatformTarget>x86</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>$(SolutionDir)\..\bin\Release\Installer</OutputPath>
diff --git a/src/StardewModdingAPI.Tests/Framework/Sample.cs b/src/StardewModdingAPI.Tests/Framework/Sample.cs
new file mode 100644
index 00000000..10006f1e
--- /dev/null
+++ b/src/StardewModdingAPI.Tests/Framework/Sample.cs
@@ -0,0 +1,30 @@
+using System;
+
+namespace StardewModdingAPI.Tests.Framework
+{
+ /// <summary>Provides sample values for unit testing.</summary>
+ internal static class Sample
+ {
+ /*********
+ ** Properties
+ *********/
+ /// <summary>A random number generator.</summary>
+ private static readonly Random Random = new Random();
+
+
+ /*********
+ ** Properties
+ *********/
+ /// <summary>Get a sample string.</summary>
+ public static string String()
+ {
+ return Guid.NewGuid().ToString("N");
+ }
+
+ /// <summary>Get a sample integer.</summary>
+ public static int Int()
+ {
+ return Sample.Random.Next();
+ }
+ }
+}
diff --git a/src/StardewModdingAPI.Tests/ModResolverTests.cs b/src/StardewModdingAPI.Tests/ModResolverTests.cs
new file mode 100644
index 00000000..efa6fa06
--- /dev/null
+++ b/src/StardewModdingAPI.Tests/ModResolverTests.cs
@@ -0,0 +1,399 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using Moq;
+using Newtonsoft.Json;
+using NUnit.Framework;
+using StardewModdingAPI.Framework.Models;
+using StardewModdingAPI.Framework.ModLoading;
+using StardewModdingAPI.Framework.Serialisation;
+using StardewModdingAPI.Tests.Framework;
+
+namespace StardewModdingAPI.Tests
+{
+ [TestFixture]
+ public class ModResolverTests
+ {
+ /*********
+ ** Unit tests
+ *********/
+ /****
+ ** ReadManifests
+ ****/
+ [Test(Description = "Assert that the resolver correctly returns an empty list if there are no mods installed.")]
+ public void ReadBasicManifest_NoMods_ReturnsEmptyList()
+ {
+ // arrange
+ string rootFolder = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"));
+ Directory.CreateDirectory(rootFolder);
+
+ // act
+ IModMetadata[] mods = new ModResolver().ReadManifests(rootFolder, new JsonHelper(), new ModCompatibility[0]).ToArray();
+
+ // assert
+ Assert.AreEqual(0, mods.Length, 0, $"Expected to find zero manifests, found {mods.Length} instead.");
+ }
+
+ [Test(Description = "Assert that the resolver correctly returns a failed metadata if there's an empty mod folder.")]
+ public void ReadBasicManifest_EmptyModFolder_ReturnsFailedManifest()
+ {
+ // arrange
+ string rootFolder = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"));
+ string modFolder = Path.Combine(rootFolder, Guid.NewGuid().ToString("N"));
+ Directory.CreateDirectory(modFolder);
+
+ // act
+ IModMetadata[] mods = new ModResolver().ReadManifests(rootFolder, new JsonHelper(), new ModCompatibility[0]).ToArray();
+ IModMetadata mod = mods.FirstOrDefault();
+
+ // assert
+ Assert.AreEqual(1, mods.Length, 0, $"Expected to find one manifest, found {mods.Length} instead.");
+ Assert.AreEqual(ModMetadataStatus.Failed, mod.Status, "The mod metadata was not marked failed.");
+ Assert.IsNotNull(mod.Error, "The mod metadata did not have an error message set.");
+ }
+
+ [Test(Description = "Assert that the resolver correctly reads manifest data from a randomised file.")]
+ public void ReadBasicManifest_CanReadFile()
+ {
+ // create manifest data
+ IDictionary<string, object> originalDependency = new Dictionary<string, object>
+ {
+ [nameof(IManifestDependency.UniqueID)] = Sample.String()
+ };
+ IDictionary<string, object> original = new Dictionary<string, object>
+ {
+ [nameof(IManifest.Name)] = Sample.String(),
+ [nameof(IManifest.Author)] = Sample.String(),
+ [nameof(IManifest.Version)] = new SemanticVersion(Sample.Int(), Sample.Int(), Sample.Int(), Sample.String()),
+ [nameof(IManifest.Description)] = Sample.String(),
+ [nameof(IManifest.UniqueID)] = $"{Sample.String()}.{Sample.String()}",
+ [nameof(IManifest.EntryDll)] = $"{Sample.String()}.dll",
+ [nameof(IManifest.MinimumApiVersion)] = $"{Sample.Int()}.{Sample.Int()}-{Sample.String()}",
+#if EXPERIMENTAL
+ [nameof(IManifest.Dependencies)] = new[] { originalDependency },
+#endif
+ ["ExtraString"] = Sample.String(),
+ ["ExtraInt"] = Sample.Int()
+ };
+
+ // write to filesystem
+ string rootFolder = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"));
+ string modFolder = Path.Combine(rootFolder, Guid.NewGuid().ToString("N"));
+ string filename = Path.Combine(modFolder, "manifest.json");
+ Directory.CreateDirectory(modFolder);
+ File.WriteAllText(filename, JsonConvert.SerializeObject(original));
+
+ // act
+ IModMetadata[] mods = new ModResolver().ReadManifests(rootFolder, new JsonHelper(), new ModCompatibility[0]).ToArray();
+ IModMetadata mod = mods.FirstOrDefault();
+
+ // assert
+ Assert.AreEqual(1, mods.Length, 0, "Expected to find one manifest.");
+ Assert.IsNotNull(mod, "The loaded manifest shouldn't be null.");
+ Assert.AreEqual(null, mod.Compatibility, "The compatibility record should be null since we didn't provide one.");
+ Assert.AreEqual(modFolder, mod.DirectoryPath, "The directory path doesn't match.");
+ Assert.AreEqual(ModMetadataStatus.Found, mod.Status, "The status doesn't match.");
+ Assert.AreEqual(null, mod.Error, "The error should be null since parsing should have succeeded.");
+
+ Assert.AreEqual(original[nameof(IManifest.Name)], mod.DisplayName, "The display name should use the manifest name.");
+ Assert.AreEqual(original[nameof(IManifest.Name)], mod.Manifest.Name, "The manifest's name doesn't match.");
+ Assert.AreEqual(original[nameof(IManifest.Author)], mod.Manifest.Author, "The manifest's author doesn't match.");
+ Assert.AreEqual(original[nameof(IManifest.Description)], mod.Manifest.Description, "The manifest's description doesn't match.");
+ Assert.AreEqual(original[nameof(IManifest.EntryDll)], mod.Manifest.EntryDll, "The manifest's entry DLL doesn't match.");
+ Assert.AreEqual(original[nameof(IManifest.MinimumApiVersion)], mod.Manifest.MinimumApiVersion, "The manifest's minimum API version doesn't match.");
+ Assert.AreEqual(original[nameof(IManifest.Version)]?.ToString(), mod.Manifest.Version?.ToString(), "The manifest's version doesn't match.");
+
+ Assert.IsNotNull(mod.Manifest.ExtraFields, "The extra fields should not be null.");
+ Assert.AreEqual(2, mod.Manifest.ExtraFields.Count, "The extra fields should contain two values.");
+ Assert.AreEqual(original["ExtraString"], mod.Manifest.ExtraFields["ExtraString"], "The manifest's extra fields should contain an 'ExtraString' value.");
+ Assert.AreEqual(original["ExtraInt"], mod.Manifest.ExtraFields["ExtraInt"], "The manifest's extra fields should contain an 'ExtraInt' value.");
+
+#if EXPERIMENTAL
+ Assert.IsNotNull(mod.Manifest.Dependencies, "The dependencies field should not be null.");
+ Assert.AreEqual(1, mod.Manifest.Dependencies.Length, "The dependencies field should contain one value.");
+ Assert.AreEqual(originalDependency[nameof(IManifestDependency.UniqueID)], mod.Manifest.Dependencies[0].UniqueID, "The first dependency's unique ID doesn't match.");
+#endif
+ }
+
+ /****
+ ** ValidateManifests
+ ****/
+ [Test(Description = "Assert that validation doesn't fail if there are no mods installed.")]
+ public void ValidateManifests_NoMods_DoesNothing()
+ {
+ new ModResolver().ValidateManifests(new ModMetadata[0], apiVersion: new SemanticVersion("1.0"));
+ }
+
+ [Test(Description = "Assert that validation skips manifests that have already failed without calling any other properties.")]
+ public void ValidateManifests_Skips_Failed()
+ {
+ // arrange
+ Mock<IModMetadata> mock = new Mock<IModMetadata>(MockBehavior.Strict);
+ mock.Setup(p => p.Status).Returns(ModMetadataStatus.Failed);
+
+ // act
+ new ModResolver().ValidateManifests(new[] { mock.Object }, apiVersion: new SemanticVersion("1.0"));
+
+ // assert
+ mock.VerifyGet(p => p.Status, Times.Once, "The validation did not check the manifest status.");
+ }
+
+ [Test(Description = "Assert that validation fails if the mod has 'assume broken' compatibility.")]
+ public void ValidateManifests_ModCompatibility_AssumeBroken_Fails()
+ {
+ // arrange
+ Mock<IModMetadata> mock = new Mock<IModMetadata>(MockBehavior.Strict);
+ mock.Setup(p => p.Status).Returns(ModMetadataStatus.Found);
+ mock.Setup(p => p.Compatibility).Returns(new ModCompatibility { Compatibility = ModCompatibilityType.AssumeBroken });
+ mock.Setup(p => p.SetStatus(ModMetadataStatus.Failed, It.IsAny<string>())).Returns(() => mock.Object);
+
+ // act
+ new ModResolver().ValidateManifests(new[] { mock.Object }, apiVersion: new SemanticVersion("1.0"));
+
+ // assert
+ mock.Verify(p => p.SetStatus(ModMetadataStatus.Failed, It.IsAny<string>()), Times.Once, "The validation did not fail the metadata.");
+ }
+
+ [Test(Description = "Assert that validation fails when the minimum API version is higher than the current SMAPI version.")]
+ public void ValidateManifests_MinimumApiVersion_Fails()
+ {
+ // arrange
+ Mock<IModMetadata> mock = new Mock<IModMetadata>(MockBehavior.Strict);
+ mock.Setup(p => p.Status).Returns(ModMetadataStatus.Found);
+ mock.Setup(p => p.Compatibility).Returns(() => null);
+ mock.Setup(p => p.Manifest).Returns(this.GetRandomManifest(m => m.MinimumApiVersion = "1.1"));
+ mock.Setup(p => p.SetStatus(ModMetadataStatus.Failed, It.IsAny<string>())).Returns(() => mock.Object);
+
+ // act
+ new ModResolver().ValidateManifests(new[] { mock.Object }, apiVersion: new SemanticVersion("1.0"));
+
+ // assert
+ mock.Verify(p => p.SetStatus(ModMetadataStatus.Failed, It.IsAny<string>()), Times.Once, "The validation did not fail the metadata.");
+ }
+
+ [Test(Description = "Assert that validation fails when the manifest references a DLL that does not exist.")]
+ public void ValidateManifests_MissingEntryDLL_Fails()
+ {
+ // arrange
+ Mock<IModMetadata> mock = new Mock<IModMetadata>(MockBehavior.Strict);
+ mock.Setup(p => p.Status).Returns(ModMetadataStatus.Found);
+ mock.Setup(p => p.Compatibility).Returns(() => null);
+ mock.Setup(p => p.Manifest).Returns(this.GetRandomManifest());
+ mock.Setup(p => p.DirectoryPath).Returns(Path.GetTempPath());
+ mock.Setup(p => p.SetStatus(ModMetadataStatus.Failed, It.IsAny<string>())).Returns(() => mock.Object);
+
+ // act
+ new ModResolver().ValidateManifests(new[] { mock.Object }, apiVersion: new SemanticVersion("1.0"));
+
+ // assert
+ mock.Verify(p => p.SetStatus(ModMetadataStatus.Failed, It.IsAny<string>()), Times.Once, "The validation did not fail the metadata.");
+ }
+
+ [Test(Description = "Assert that validation fails when the manifest references a DLL that does not exist.")]
+ public void ValidateManifests_Valid_Passes()
+ {
+ // set up manifest
+ IManifest manifest = this.GetRandomManifest();
+
+ // create DLL
+ string modFolder = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"));
+ Directory.CreateDirectory(modFolder);
+ File.WriteAllText(Path.Combine(modFolder, manifest.EntryDll), "");
+
+ // arrange
+ Mock<IModMetadata> mock = new Mock<IModMetadata>(MockBehavior.Strict);
+ mock.Setup(p => p.Status).Returns(ModMetadataStatus.Found);
+ mock.Setup(p => p.Compatibility).Returns(() => null);
+ mock.Setup(p => p.Manifest).Returns(manifest);
+ mock.Setup(p => p.DirectoryPath).Returns(modFolder);
+
+ // act
+ new ModResolver().ValidateManifests(new[] { mock.Object }, apiVersion: new SemanticVersion("1.0"));
+
+ // assert
+ // if Moq doesn't throw a method-not-setup exception, the validation didn't override the status.
+ }
+
+#if EXPERIMENTAL
+ /****
+ ** ProcessDependencies
+ ****/
+ [Test(Description = "Assert that processing dependencies doesn't fail if there are no mods installed.")]
+ public void ProcessDependencies_NoMods_DoesNothing()
+ {
+ // act
+ IModMetadata[] mods = new ModResolver().ProcessDependencies(new IModMetadata[0]).ToArray();
+
+ // assert
+ Assert.AreEqual(0, mods.Length, 0, "Expected to get an empty list of mods.");
+ }
+
+ [Test(Description = "Assert that processing dependencies doesn't change the order if there are no mod dependencies.")]
+ public void ProcessDependencies_NoDependencies_DoesNothing()
+ {
+ // arrange
+ // A B C
+ Mock<IModMetadata> modA = this.GetMetadataForDependencyTest("Mod A");
+ Mock<IModMetadata> modB = this.GetMetadataForDependencyTest("Mod B");
+ Mock<IModMetadata> modC = this.GetMetadataForDependencyTest("Mod C");
+
+ // act
+ IModMetadata[] mods = new ModResolver().ProcessDependencies(new[] { modA.Object, modB.Object, modC.Object }).ToArray();
+
+ // assert
+ Assert.AreEqual(3, mods.Length, 0, "Expected to get the same number of mods input.");
+ Assert.AreSame(modA.Object, mods[0], "The load order unexpectedly changed with no dependencies.");
+ Assert.AreSame(modB.Object, mods[1], "The load order unexpectedly changed with no dependencies.");
+ Assert.AreSame(modC.Object, mods[2], "The load order unexpectedly changed with no dependencies.");
+ }
+
+ [Test(Description = "Assert that simple dependencies are reordered correctly.")]
+ public void ProcessDependencies_Reorders_SimpleDependencies()
+ {
+