summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI.Tests/Core/ModResolverTests.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/StardewModdingAPI.Tests/Core/ModResolverTests.cs')
-rw-r--r--src/StardewModdingAPI.Tests/Core/ModResolverTests.cs48
1 files changed, 32 insertions, 16 deletions
diff --git a/src/StardewModdingAPI.Tests/Core/ModResolverTests.cs b/src/StardewModdingAPI.Tests/Core/ModResolverTests.cs
index b451465e..e6ec632a 100644
--- a/src/StardewModdingAPI.Tests/Core/ModResolverTests.cs
+++ b/src/StardewModdingAPI.Tests/Core/ModResolverTests.cs
@@ -126,7 +126,7 @@ namespace StardewModdingAPI.Tests.Core
public void ValidateManifests_Skips_Failed()
{
// arrange
- Mock<IModMetadata> mock = new Mock<IModMetadata>(MockBehavior.Strict);
+ Mock<IModMetadata> mock = this.GetMetadata("Mod A");
mock.Setup(p => p.Status).Returns(ModMetadataStatus.Failed);
// act
@@ -140,10 +140,8 @@ namespace StardewModdingAPI.Tests.Core
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);
+ Mock<IModMetadata> mock = this.GetMetadata("Mod A", new string[0], allowStatusChange: true);
+ this.SetupMetadataForValidation(mock, new ModCompatibility { Compatibility = ModCompatibilityType.AssumeBroken });
// act
new ModResolver().ValidateManifests(new[] { mock.Object }, apiVersion: new SemanticVersion("1.0"));
@@ -156,11 +154,9 @@ namespace StardewModdingAPI.Tests.Core
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<IModMetadata> mock = this.GetMetadata("Mod A", new string[0], allowStatusChange: true);
mock.Setup(p => p.Manifest).Returns(this.GetManifest(m => m.MinimumApiVersion = new SemanticVersion("1.1")));
- mock.Setup(p => p.SetStatus(ModMetadataStatus.Failed, It.IsAny<string>())).Returns(() => mock.Object);
+ this.SetupMetadataForValidation(mock);
// act
new ModResolver().ValidateManifests(new[] { mock.Object }, apiVersion: new SemanticVersion("1.0"));
@@ -173,12 +169,8 @@ namespace StardewModdingAPI.Tests.Core
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.GetManifest());
- mock.Setup(p => p.DirectoryPath).Returns(Path.GetTempPath());
- mock.Setup(p => p.SetStatus(ModMetadataStatus.Failed, It.IsAny<string>())).Returns(() => mock.Object);
+ Mock<IModMetadata> mock = this.GetMetadata(this.GetManifest("Mod A", "1.0", manifest => manifest.EntryDll = "Missing.dll"), allowStatusChange: true);
+ this.SetupMetadataForValidation(mock);
// act
new ModResolver().ValidateManifests(new[] { mock.Object }, apiVersion: new SemanticVersion("1.0"));
@@ -469,8 +461,9 @@ namespace StardewModdingAPI.Tests.Core
/// <summary>Get a randomised basic manifest.</summary>
/// <param name="uniqueID">The mod's name and unique ID.</param>
/// <param name="version">The mod version.</param>
+ /// <param name="adjust">Adjust the generated manifest.</param>
/// <param name="dependencies">The dependencies this mod requires.</param>
- private IManifest GetManifest(string uniqueID, string version, params IManifestDependency[] dependencies)
+ private IManifest GetManifest(string uniqueID, string version, Action<Manifest> adjust, params IManifestDependency[] dependencies)
{
return this.GetManifest(manifest =>
{
@@ -478,11 +471,21 @@ namespace StardewModdingAPI.Tests.Core
manifest.UniqueID = uniqueID;
manifest.Version = new SemanticVersion(version);
manifest.Dependencies = dependencies;
+ adjust?.Invoke(manifest);
});
}
/// <summary>Get a randomised basic manifest.</summary>
/// <param name="uniqueID">The mod's name and unique ID.</param>
+ /// <param name="version">The mod version.</param>
+ /// <param name="dependencies">The dependencies this mod requires.</param>
+ private IManifest GetManifest(string uniqueID, string version, params IManifestDependency[] dependencies)
+ {
+ return this.GetManifest(uniqueID, version, null, dependencies);
+ }
+
+ /// <summary>Get a randomised basic manifest.</summary>
+ /// <param name="uniqueID">The mod's name and unique ID.</param>
private Mock<IModMetadata> GetMetadata(string uniqueID)
{
return this.GetMetadata(this.GetManifest(uniqueID, "1.0"));
@@ -504,6 +507,7 @@ namespace StardewModdingAPI.Tests.Core
private Mock<IModMetadata> GetMetadata(IManifest manifest, bool allowStatusChange = false)
{
Mock<IModMetadata> mod = new Mock<IModMetadata>(MockBehavior.Strict);
+ mod.Setup(p => p.Compatibility).Returns(() => null);
mod.Setup(p => p.Status).Returns(ModMetadataStatus.Found);
mod.Setup(p => p.DisplayName).Returns(manifest.UniqueID);
mod.Setup(p => p.Manifest).Returns(manifest);
@@ -516,5 +520,17 @@ namespace StardewModdingAPI.Tests.Core
}
return mod;
}
+
+ /// <summary>Set up a mock mod metadata for <see cref="ModResolver.ValidateManifests"/>.</summary>
+ /// <param name="mod">The mock mod metadata.</param>
+ /// <param name="compatibility">The compatibility record to set.</param>
+ private void SetupMetadataForValidation(Mock<IModMetadata> mod, ModCompatibility compatibility = null)
+ {
+ mod.Setup(p => p.Status).Returns(ModMetadataStatus.Found);
+ mod.Setup(p => p.Compatibility).Returns(() => null);
+ mod.Setup(p => p.Manifest).Returns(this.GetManifest());
+ mod.Setup(p => p.DirectoryPath).Returns(Path.GetTempPath());
+ mod.Setup(p => p.Compatibility).Returns(compatibility);
+ }
}
}