summaryrefslogtreecommitdiff
path: root/src/SMAPI.Tests
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2018-02-24 17:54:31 -0500
committerJesse Plamondon-Willard <github@jplamondonw.com>2018-02-24 17:54:31 -0500
commit414cf5c197b5b59776d3dda914eb15710efb0868 (patch)
tree0393a95194ad78cf4440c68657b0488b7db6d68b /src/SMAPI.Tests
parent5da8b707385b9851ff3f6442de58519125f5c96f (diff)
parentf2e8450706d1971d774f870081deffdb0c6b92eb (diff)
downloadSMAPI-414cf5c197b5b59776d3dda914eb15710efb0868.tar.gz
SMAPI-414cf5c197b5b59776d3dda914eb15710efb0868.tar.bz2
SMAPI-414cf5c197b5b59776d3dda914eb15710efb0868.zip
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI.Tests')
-rw-r--r--src/SMAPI.Tests/Core/ModResolverTests.cs51
-rw-r--r--src/SMAPI.Tests/Core/PathUtilitiesTests.cs70
-rw-r--r--src/SMAPI.Tests/Properties/AssemblyInfo.cs6
-rw-r--r--src/SMAPI.Tests/StardewModdingAPI.Tests.csproj1
4 files changed, 99 insertions, 29 deletions
diff --git a/src/SMAPI.Tests/Core/ModResolverTests.cs b/src/SMAPI.Tests/Core/ModResolverTests.cs
index 051ffe99..d63eb1a2 100644
--- a/src/SMAPI.Tests/Core/ModResolverTests.cs
+++ b/src/SMAPI.Tests/Core/ModResolverTests.cs
@@ -6,6 +6,7 @@ using Moq;
using Newtonsoft.Json;
using NUnit.Framework;
using StardewModdingAPI.Framework;
+using StardewModdingAPI.Framework.ModData;
using StardewModdingAPI.Framework.Models;
using StardewModdingAPI.Framework.ModLoading;
using StardewModdingAPI.Framework.Serialisation;
@@ -30,7 +31,7 @@ namespace StardewModdingAPI.Tests.Core
Directory.CreateDirectory(rootFolder);
// act
- IModMetadata[] mods = new ModResolver().ReadManifests(rootFolder, new JsonHelper(), new ModDataRecord[0]).ToArray();
+ IModMetadata[] mods = new ModResolver().ReadManifests(rootFolder, new JsonHelper(), new ModDatabase()).ToArray();
// assert
Assert.AreEqual(0, mods.Length, 0, $"Expected to find zero manifests, found {mods.Length} instead.");
@@ -45,7 +46,7 @@ namespace StardewModdingAPI.Tests.Core
Directory.CreateDirectory(modFolder);
// act
- IModMetadata[] mods = new ModResolver().ReadManifests(rootFolder, new JsonHelper(), new ModDataRecord[0]).ToArray();
+ IModMetadata[] mods = new ModResolver().ReadManifests(rootFolder, new JsonHelper(), new ModDatabase()).ToArray();
IModMetadata mod = mods.FirstOrDefault();
// assert
@@ -84,7 +85,7 @@ namespace StardewModdingAPI.Tests.Core
File.WriteAllText(filename, JsonConvert.SerializeObject(original));
// act
- IModMetadata[] mods = new ModResolver().ReadManifests(rootFolder, new JsonHelper(), new ModDataRecord[0]).ToArray();
+ IModMetadata[] mods = new ModResolver().ReadManifests(rootFolder, new JsonHelper(), new ModDatabase()).ToArray();
IModMetadata mod = mods.FirstOrDefault();
// assert
@@ -119,7 +120,7 @@ namespace StardewModdingAPI.Tests.Core
[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"), vendorModUrls: new Dictionary<string, string>());
+ new ModResolver().ValidateManifests(new ModMetadata[0], apiVersion: new SemanticVersion("1.0"), getUpdateUrl: key => null);
}
[Test(Description = "Assert that validation skips manifests that have already failed without calling any other properties.")]
@@ -130,7 +131,7 @@ namespace StardewModdingAPI.Tests.Core
mock.Setup(p => p.Status).Returns(ModMetadataStatus.Failed);
// act
- new ModResolver().ValidateManifests(new[] { mock.Object }, apiVersion: new SemanticVersion("1.0"), vendorModUrls: new Dictionary<string, string>());
+ new ModResolver().ValidateManifests(new[] { mock.Object }, apiVersion: new SemanticVersion("1.0"), getUpdateUrl: key => null);
// assert
mock.VerifyGet(p => p.Status, Times.Once, "The validation did not check the manifest status.");
@@ -141,14 +142,14 @@ namespace StardewModdingAPI.Tests.Core
{
// arrange
Mock<IModMetadata> mock = this.GetMetadata("Mod A", new string[0], allowStatusChange: true);
- this.SetupMetadataForValidation(mock, new ModDataRecord
+ this.SetupMetadataForValidation(mock, new ParsedModDataRecord
{
- Compatibility = new[] { new ModCompatibility("~1.0", ModStatus.AssumeBroken, null) },
+ Status = ModStatus.AssumeBroken,
AlternativeUrl = "http://example.org"
});
// act
- new ModResolver().ValidateManifests(new[] { mock.Object }, apiVersion: new SemanticVersion("1.0"), vendorModUrls: new Dictionary<string, string>());
+ new ModResolver().ValidateManifests(new[] { mock.Object }, apiVersion: new SemanticVersion("1.0"), getUpdateUrl: key => null);
// assert
mock.Verify(p => p.SetStatus(ModMetadataStatus.Failed, It.IsAny<string>()), Times.Once, "The validation did not fail the metadata.");
@@ -163,7 +164,7 @@ namespace StardewModdingAPI.Tests.Core
this.SetupMetadataForValidation(mock);
// act
- new ModResolver().ValidateManifests(new[] { mock.Object }, apiVersion: new SemanticVersion("1.0"), vendorModUrls: new Dictionary<string, string>());
+ new ModResolver().ValidateManifests(new[] { mock.Object }, apiVersion: new SemanticVersion("1.0"), getUpdateUrl: key => null);
// assert
mock.Verify(p => p.SetStatus(ModMetadataStatus.Failed, It.IsAny<string>()), Times.Once, "The validation did not fail the metadata.");
@@ -177,7 +178,7 @@ namespace StardewModdingAPI.Tests.Core
this.SetupMetadataForValidation(mock);
// act
- new ModResolver().ValidateManifests(new[] { mock.Object }, apiVersion: new SemanticVersion("1.0"), vendorModUrls: new Dictionary<string, string>());
+ new ModResolver().ValidateManifests(new[] { mock.Object }, apiVersion: new SemanticVersion("1.0"), getUpdateUrl: key => null);
// assert
mock.Verify(p => p.SetStatus(ModMetadataStatus.Failed, It.IsAny<string>()), Times.Once, "The validation did not fail the metadata.");
@@ -194,7 +195,7 @@ namespace StardewModdingAPI.Tests.Core
this.SetupMetadataForValidation(mod);
// act
- new ModResolver().ValidateManifests(new[] { modA.Object, modB.Object }, apiVersion: new SemanticVersion("1.0"), vendorModUrls: new Dictionary<string, string>());
+ new ModResolver().ValidateManifests(new[] { modA.Object, modB.Object }, apiVersion: new SemanticVersion("1.0"), getUpdateUrl: key => null);
// assert
modA.Verify(p => p.SetStatus(ModMetadataStatus.Failed, It.IsAny<string>()), Times.Once, "The validation did not fail the first mod with a unique ID.");
@@ -220,7 +221,7 @@ namespace StardewModdingAPI.Tests.Core
mock.Setup(p => p.DirectoryPath).Returns(modFolder);
// act
- new ModResolver().ValidateManifests(new[] { mock.Object }, apiVersion: new SemanticVersion("1.0"), vendorModUrls: new Dictionary<string, string>());
+ new ModResolver().ValidateManifests(new[] { mock.Object }, apiVersion: new SemanticVersion("1.0"), getUpdateUrl: key => null);
// assert
// if Moq doesn't throw a method-not-setup exception, the validation didn't override the status.
@@ -233,7 +234,7 @@ namespace StardewModdingAPI.Tests.Core
public void ProcessDependencies_NoMods_DoesNothing()
{
// act
- IModMetadata[] mods = new ModResolver().ProcessDependencies(new IModMetadata[0]).ToArray();
+ IModMetadata[] mods = new ModResolver().ProcessDependencies(new IModMetadata[0], new ModDatabase()).ToArray();
// assert
Assert.AreEqual(0, mods.Length, 0, "Expected to get an empty list of mods.");
@@ -249,7 +250,7 @@ namespace StardewModdingAPI.Tests.Core
Mock<IModMetadata> modC = this.GetMetadata("Mod C");
// act
- IModMetadata[] mods = new ModResolver().ProcessDependencies(new[] { modA.Object, modB.Object, modC.Object }).ToArray();
+ IModMetadata[] mods = new ModResolver().ProcessDependencies(new[] { modA.Object, modB.Object, modC.Object }, new ModDatabase()).ToArray();
// assert
Assert.AreEqual(3, mods.Length, 0, "Expected to get the same number of mods input.");
@@ -266,7 +267,7 @@ namespace StardewModdingAPI.Tests.Core
mock.Setup(p => p.Status).Returns(ModMetadataStatus.Failed);
// act
- new ModResolver().ProcessDependencies(new[] { mock.Object });
+ new ModResolver().ProcessDependencies(new[] { mock.Object }, new ModDatabase());
// assert
mock.VerifyGet(p => p.Status, Times.Once, "The validation did not check the manifest status.");
@@ -285,7 +286,7 @@ namespace StardewModdingAPI.Tests.Core
Mock<IModMetadata> modC = this.GetMetadata("Mod C", dependencies: new[] { "Mod A", "Mod B" });
// act
- IModMetadata[] mods = new ModResolver().ProcessDependencies(new[] { modC.Object, modA.Object, modB.Object }).ToArray();
+ IModMetadata[] mods = new ModResolver().ProcessDependencies(new[] { modC.Object, modA.Object, modB.Object }, new ModDatabase()).ToArray();
// assert
Assert.AreEqual(3, mods.Length, 0, "Expected to get the same number of mods input.");
@@ -305,7 +306,7 @@ namespace StardewModdingAPI.Tests.Core
Mock<IModMetadata> modD = this.GetMetadata("Mod D", dependencies: new[] { "Mod C" });
// act
- IModMetadata[] mods = new ModResolver().ProcessDependencies(new[] { modC.Object, modA.Object, modB.Object, modD.Object }).ToArray();
+ IModMetadata[] mods = new ModResolver().ProcessDependencies(new[] { modC.Object, modA.Object, modB.Object, modD.Object }, new ModDatabase()).ToArray();
// assert
Assert.AreEqual(4, mods.Length, 0, "Expected to get the same number of mods input.");
@@ -331,7 +332,7 @@ namespace StardewModdingAPI.Tests.Core
Mock<IModMetadata> modF = this.GetMetadata("Mod F", dependencies: new[] { "Mod C", "Mod E" });
// act
- IModMetadata[] mods = new ModResolver().ProcessDependencies(new[] { modC.Object, modA.Object, modB.Object, modD.Object, modF.Object, modE.Object }).ToArray();
+ IModMetadata[] mods = new ModResolver().ProcessDependencies(new[] { modC.Object, modA.Object, modB.Object, modD.Object, modF.Object, modE.Object }, new ModDatabase()).ToArray();
// assert
Assert.AreEqual(6, mods.Length, 0, "Expected to get the same number of mods input.");
@@ -358,7 +359,7 @@ namespace StardewModdingAPI.Tests.Core
Mock<IModMetadata> modE = this.GetMetadata("Mod E", dependencies: new[] { "Mod C" }, allowStatusChange: true);
// act
- IModMetadata[] mods = new ModResolver().ProcessDependencies(new[] { modC.Object, modA.Object, modB.Object, modD.Object, modE.Object }).ToArray();
+ IModMetadata[] mods = new ModResolver().ProcessDependencies(new[] { modC.Object, modA.Object, modB.Object, modD.Object, modE.Object }, new ModDatabase()).ToArray();
// assert
Assert.AreEqual(5, mods.Length, 0, "Expected to get the same number of mods input.");
@@ -382,7 +383,7 @@ namespace StardewModdingAPI.Tests.Core
modD.Setup(p => p.Status).Returns(ModMetadataStatus.Failed);
// act
- IModMetadata[] mods = new ModResolver().ProcessDependencies(new[] { modC.Object, modA.Object, modB.Object, modD.Object }).ToArray();
+ IModMetadata[] mods = new ModResolver().ProcessDependencies(new[] { modC.Object, modA.Object, modB.Object, modD.Object }, new ModDatabase()).ToArray();
// assert
Assert.AreEqual(4, mods.Length, 0, "Expected to get the same number of mods input.");
@@ -401,7 +402,7 @@ namespace StardewModdingAPI.Tests.Core
Mock<IModMetadata> modB = this.GetMetadata(this.GetManifest("Mod B", "1.0", new ManifestDependency("Mod A", "1.1")), allowStatusChange: true);
// act
- IModMetadata[] mods = new ModResolver().ProcessDependencies(new[] { modA.Object, modB.Object }).ToArray();
+ IModMetadata[] mods = new ModResolver().ProcessDependencies(new[] { modA.Object, modB.Object }, new ModDatabase()).ToArray();
// assert
Assert.AreEqual(2, mods.Length, 0, "Expected to get the same number of mods input.");
@@ -417,7 +418,7 @@ namespace StardewModdingAPI.Tests.Core
Mock<IModMetadata> modB = this.GetMetadata(this.GetManifest("Mod B", "1.0", new ManifestDependency("Mod A", "1.0-beta")), allowStatusChange: false);
// act
- IModMetadata[] mods = new ModResolver().ProcessDependencies(new[] { modA.Object, modB.Object }).ToArray();
+ IModMetadata[] mods = new ModResolver().ProcessDependencies(new[] { modA.Object, modB.Object }, new ModDatabase()).ToArray();
// assert
Assert.AreEqual(2, mods.Length, 0, "Expected to get the same number of mods input.");
@@ -434,7 +435,7 @@ namespace StardewModdingAPI.Tests.Core
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();
+ IModMetadata[] mods = new ModResolver().ProcessDependencies(new[] { modB.Object, modA.Object }, new ModDatabase()).ToArray();
// assert
Assert.AreEqual(2, mods.Length, 0, "Expected to get the same number of mods input.");
@@ -450,7 +451,7 @@ namespace StardewModdingAPI.Tests.Core
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();
+ IModMetadata[] mods = new ModResolver().ProcessDependencies(new[] { modB.Object }, new ModDatabase()).ToArray();
// assert
Assert.AreEqual(1, mods.Length, 0, "Expected to get the same number of mods input.");
@@ -544,7 +545,7 @@ namespace StardewModdingAPI.Tests.Core
/// <summary>Set up a mock mod metadata for <see cref="ModResolver.ValidateManifests"/>.</summary>
/// <param name="mod">The mock mod metadata.</param>
/// <param name="modRecord">The extra metadata about the mod from SMAPI's internal data (if any).</param>
- private void SetupMetadataForValidation(Mock<IModMetadata> mod, ModDataRecord modRecord = null)
+ private void SetupMetadataForValidation(Mock<IModMetadata> mod, ParsedModDataRecord modRecord = null)
{
mod.Setup(p => p.Status).Returns(ModMetadataStatus.Found);
mod.Setup(p => p.DataRecord).Returns(() => null);
diff --git a/src/SMAPI.Tests/Core/PathUtilitiesTests.cs b/src/SMAPI.Tests/Core/PathUtilitiesTests.cs
new file mode 100644
index 00000000..268ba504
--- /dev/null
+++ b/src/SMAPI.Tests/Core/PathUtilitiesTests.cs
@@ -0,0 +1,70 @@
+using NUnit.Framework;
+using StardewModdingAPI.Framework.Utilities;
+
+namespace StardewModdingAPI.Tests.Core
+{
+ /// <summary>Unit tests for <see cref="PathUtilities"/>.</summary>
+ [TestFixture]
+ public class PathUtilitiesTests
+ {
+ /*********
+ ** Unit tests
+ *********/
+ [Test(Description = "Assert that GetSegments returns the expected values.")]
+ [TestCase("", ExpectedResult = "")]
+ [TestCase("/", ExpectedResult = "")]
+ [TestCase("///", ExpectedResult = "")]
+ [TestCase("/usr/bin", ExpectedResult = "usr|bin")]
+ [TestCase("/usr//bin//", ExpectedResult = "usr|bin")]
+ [TestCase("/usr//bin//.././boop.exe", ExpectedResult = "usr|bin|..|.|boop.exe")]
+ [TestCase(@"C:", ExpectedResult = "C:")]
+ [TestCase(@"C:/boop", ExpectedResult = "C:|boop")]
+ [TestCase(@"C:\boop\/usr//bin//.././boop.exe", ExpectedResult = "C:|boop|usr|bin|..|.|boop.exe")]
+ public string GetSegments(string path)
+ {
+ return string.Join("|", PathUtilities.GetSegments(path));
+ }
+
+ [Test(Description = "Assert that NormalisePathSeparators returns the expected values.")]
+#if SMAPI_FOR_WINDOWS
+ [TestCase("", ExpectedResult = "")]
+ [TestCase("/", ExpectedResult = "")]
+ [TestCase("///", ExpectedResult = "")]
+ [TestCase("/usr/bin", ExpectedResult = @"usr\bin")]
+ [TestCase("/usr//bin//", ExpectedResult = @"usr\bin")]
+ [TestCase("/usr//bin//.././boop.exe", ExpectedResult = @"usr\bin\..\.\boop.exe")]
+ [TestCase("C:", ExpectedResult = "C:")]
+ [TestCase("C:/boop", ExpectedResult = @"C:\boop")]
+ [TestCase(@"C:\usr\bin//.././boop.exe", ExpectedResult = @"C:\usr\bin\..\.\boop.exe")]
+#else
+ [TestCase("", ExpectedResult = "")]
+ [TestCase("/", ExpectedResult = "/")]
+ [TestCase("///", ExpectedResult = "/")]
+ [TestCase("/usr/bin", ExpectedResult = "/usr/bin")]
+ [TestCase("/usr//bin//", ExpectedResult = "/usr/bin")]
+ [TestCase("/usr//bin//.././boop.exe", ExpectedResult = "/usr/bin/.././boop.exe")]
+ [TestCase("C:", ExpectedResult = "C:")]
+ [TestCase("C:/boop", ExpectedResult = "C:/boop")]
+ [TestCase(@"C:\usr\bin//.././boop.exe", ExpectedResult = "C:/usr/bin/.././boop.exe")]
+#endif
+ public string NormalisePathSeparators(string path)
+ {
+ return PathUtilities.NormalisePathSeparators(path);
+ }
+
+ [Test(Description = "Assert that GetRelativePath returns the expected values.")]
+#if SMAPI_FOR_WINDOWS
+ [TestCase(@"C:\", @"C:\", ExpectedResult = "./")]
+ [TestCase(@"C:\grandparent\parent\child", @"C:\grandparent\parent\sibling", ExpectedResult = @"..\sibling")]
+ [TestCase(@"C:\grandparent\parent\child", @"C:\cousin\file.exe", ExpectedResult = @"..\..\..\cousin\file.exe")]
+#else
+ [TestCase("/", "/", ExpectedResult = "./")]
+ [TestCase("/grandparent/parent/child", "/grandparent/parent/sibling", ExpectedResult = "../sibling")]
+ [TestCase("/grandparent/parent/child", "/cousin/file.exe", ExpectedResult = "../../../cousin/file.exe")]
+#endif
+ public string GetRelativePath(string sourceDir, string targetPath)
+ {
+ return PathUtilities.GetRelativePath(sourceDir, targetPath);
+ }
+ }
+}
diff --git a/src/SMAPI.Tests/Properties/AssemblyInfo.cs b/src/SMAPI.Tests/Properties/AssemblyInfo.cs
index ee09145b..8b21e8fe 100644
--- a/src/SMAPI.Tests/Properties/AssemblyInfo.cs
+++ b/src/SMAPI.Tests/Properties/AssemblyInfo.cs
@@ -1,6 +1,4 @@
-using System.Reflection;
-using System.Runtime.InteropServices;
+using System.Reflection;
-[assembly: AssemblyTitle("StardewModdingAPI.Tests")]
+[assembly: AssemblyTitle("SMAPI.Tests")]
[assembly: AssemblyDescription("")]
-[assembly: Guid("36ccb19e-92eb-48c7-9615-98eefd45109b")]
diff --git a/src/SMAPI.Tests/StardewModdingAPI.Tests.csproj b/src/SMAPI.Tests/StardewModdingAPI.Tests.csproj
index 6e7fa1f0..e4b2c8c6 100644
--- a/src/SMAPI.Tests/StardewModdingAPI.Tests.csproj
+++ b/src/SMAPI.Tests/StardewModdingAPI.Tests.csproj
@@ -49,6 +49,7 @@
<Compile Include="..\..\build\GlobalAssemblyInfo.cs">
<Link>Properties\GlobalAssemblyInfo.cs</Link>
</Compile>
+ <Compile Include="Core\PathUtilitiesTests.cs" />
<Compile Include="Utilities\SemanticVersionTests.cs" />
<Compile Include="Utilities\SDateTests.cs" />
<Compile Include="Core\TranslationTests.cs" />