summaryrefslogtreecommitdiff
path: root/src/SMAPI.Tests/Core
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-11-24 13:49:30 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-11-24 13:49:30 -0500
commita3f21685049cabf2d824c8060dc0b1de47e9449e (patch)
treead9add30e9da2a50e0ea0245f1546b7378f0d282 /src/SMAPI.Tests/Core
parent6521df7b131924835eb797251c1e956fae0d6e13 (diff)
parent277bf082675b98b95bf6184fe3c7a45b969c7ac2 (diff)
downloadSMAPI-a3f21685049cabf2d824c8060dc0b1de47e9449e.tar.gz
SMAPI-a3f21685049cabf2d824c8060dc0b1de47e9449e.tar.bz2
SMAPI-a3f21685049cabf2d824c8060dc0b1de47e9449e.zip
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI.Tests/Core')
-rw-r--r--src/SMAPI.Tests/Core/ModResolverTests.cs30
-rw-r--r--src/SMAPI.Tests/Core/TranslationTests.cs54
2 files changed, 40 insertions, 44 deletions
diff --git a/src/SMAPI.Tests/Core/ModResolverTests.cs b/src/SMAPI.Tests/Core/ModResolverTests.cs
index 4a1f04c6..a9c88c60 100644
--- a/src/SMAPI.Tests/Core/ModResolverTests.cs
+++ b/src/SMAPI.Tests/Core/ModResolverTests.cs
@@ -5,13 +5,15 @@ using System.Linq;
using Moq;
using Newtonsoft.Json;
using NUnit.Framework;
+using StardewModdingAPI;
using StardewModdingAPI.Framework;
using StardewModdingAPI.Framework.ModLoading;
using StardewModdingAPI.Toolkit;
using StardewModdingAPI.Toolkit.Framework.ModData;
-using StardewModdingAPI.Toolkit.Serialisation.Models;
+using StardewModdingAPI.Toolkit.Serialization.Models;
+using SemanticVersion = StardewModdingAPI.SemanticVersion;
-namespace StardewModdingAPI.Tests.Core
+namespace SMAPI.Tests.Core
{
/// <summary>Unit tests for <see cref="ModResolver"/>.</summary>
[TestFixture]
@@ -27,7 +29,7 @@ namespace StardewModdingAPI.Tests.Core
public void ReadBasicManifest_NoMods_ReturnsEmptyList()
{
// arrange
- string rootFolder = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"));
+ string rootFolder = this.GetTempFolderPath();
Directory.CreateDirectory(rootFolder);
// act
@@ -41,7 +43,7 @@ namespace StardewModdingAPI.Tests.Core
public void ReadBasicManifest_EmptyModFolder_ReturnsFailedManifest()
{
// arrange
- string rootFolder = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"));
+ string rootFolder = this.GetTempFolderPath();
string modFolder = Path.Combine(rootFolder, Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(modFolder);
@@ -55,7 +57,7 @@ namespace StardewModdingAPI.Tests.Core
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.")]
+ [Test(Description = "Assert that the resolver correctly reads manifest data from a randomized file.")]
public void ReadBasicManifest_CanReadFile()
{
// create manifest data
@@ -78,7 +80,7 @@ namespace StardewModdingAPI.Tests.Core
};
// write to filesystem
- string rootFolder = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"));
+ string rootFolder = this.GetTempFolderPath();
string modFolder = Path.Combine(rootFolder, Guid.NewGuid().ToString("N"));
string filename = Path.Combine(modFolder, "manifest.json");
Directory.CreateDirectory(modFolder);
@@ -209,7 +211,7 @@ namespace StardewModdingAPI.Tests.Core
IManifest manifest = this.GetManifest();
// create DLL
- string modFolder = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"));
+ string modFolder = Path.Combine(this.GetTempFolderPath(), Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(modFolder);
File.WriteAllText(Path.Combine(modFolder, manifest.EntryDll), "");
@@ -462,7 +464,13 @@ namespace StardewModdingAPI.Tests.Core
/*********
** Private methods
*********/
- /// <summary>Get a randomised basic manifest.</summary>
+ /// <summary>Get a generated folder path in the temp folder. This folder isn't created automatically.</summary>
+ private string GetTempFolderPath()
+ {
+ return Path.Combine(Path.GetTempPath(), "smapi-unit-tests", Guid.NewGuid().ToString("N"));
+ }
+
+ /// <summary>Get a randomized basic manifest.</summary>
/// <param name="id">The <see cref="IManifest.UniqueID"/> value, or <c>null</c> for a generated value.</param>
/// <param name="name">The <see cref="IManifest.Name"/> value, or <c>null</c> for a generated value.</param>
/// <param name="version">The <see cref="IManifest.Version"/> value, or <c>null</c> for a generated value.</param>
@@ -486,14 +494,14 @@ namespace StardewModdingAPI.Tests.Core
};
}
- /// <summary>Get a randomised basic manifest.</summary>
+ /// <summary>Get a randomized 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"));
}
- /// <summary>Get a randomised basic manifest.</summary>
+ /// <summary>Get a randomized basic manifest.</summary>
/// <param name="uniqueID">The mod's name and unique ID.</param>
/// <param name="dependencies">The dependencies this mod requires.</param>
/// <param name="allowStatusChange">Whether the code being tested is allowed to change the mod status.</param>
@@ -503,7 +511,7 @@ namespace StardewModdingAPI.Tests.Core
return this.GetMetadata(manifest, allowStatusChange);
}
- /// <summary>Get a randomised basic manifest.</summary>
+ /// <summary>Get a randomized basic manifest.</summary>
/// <param name="manifest">The mod manifest.</param>
/// <param name="allowStatusChange">Whether the code being tested is allowed to change the mod status.</param>
private Mock<IModMetadata> GetMetadata(IManifest manifest, bool allowStatusChange = false)
diff --git a/src/SMAPI.Tests/Core/TranslationTests.cs b/src/SMAPI.Tests/Core/TranslationTests.cs
index 63404a41..457f9fad 100644
--- a/src/SMAPI.Tests/Core/TranslationTests.cs
+++ b/src/SMAPI.Tests/Core/TranslationTests.cs
@@ -2,10 +2,11 @@ using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
+using StardewModdingAPI;
using StardewModdingAPI.Framework.ModHelpers;
using StardewValley;
-namespace StardewModdingAPI.Tests.Core
+namespace SMAPI.Tests.Core
{
/// <summary>Unit tests for <see cref="TranslationHelper"/> and <see cref="Translation"/>.</summary>
[TestFixture]
@@ -31,7 +32,7 @@ namespace StardewModdingAPI.Tests.Core
var data = new Dictionary<string, IDictionary<string, string>>();
// act
- ITranslationHelper helper = new TranslationHelper("ModID", "ModName", "en", LocalizedContentManager.LanguageCode.en).SetTranslations(data);
+ ITranslationHelper helper = new TranslationHelper("ModID", "en", LocalizedContentManager.LanguageCode.en).SetTranslations(data);
Translation translation = helper.Get("key");
Translation[] translationList = helper.GetTranslations()?.ToArray();
@@ -54,7 +55,7 @@ namespace StardewModdingAPI.Tests.Core
// act
var actual = new Dictionary<string, Translation[]>();
- TranslationHelper helper = new TranslationHelper("ModID", "ModName", "en", LocalizedContentManager.LanguageCode.en).SetTranslations(data);
+ TranslationHelper helper = new TranslationHelper("ModID", "en", LocalizedContentManager.LanguageCode.en).SetTranslations(data);
foreach (string locale in expected.Keys)
{
this.AssertSetLocale(helper, locale, LocalizedContentManager.LanguageCode.en);
@@ -78,7 +79,7 @@ namespace StardewModdingAPI.Tests.Core
// act
var actual = new Dictionary<string, Translation[]>();
- TranslationHelper helper = new TranslationHelper("ModID", "ModName", "en", LocalizedContentManager.LanguageCode.en).SetTranslations(data);
+ TranslationHelper helper = new TranslationHelper("ModID", "en", LocalizedContentManager.LanguageCode.en).SetTranslations(data);
foreach (string locale in expected.Keys)
{
this.AssertSetLocale(helper, locale, LocalizedContentManager.LanguageCode.en);
@@ -108,14 +109,14 @@ namespace StardewModdingAPI.Tests.Core
[TestCase(" boop ", ExpectedResult = true)]
public bool Translation_HasValue(string text)
{
- return new Translation("ModName", "pt-BR", "key", text).HasValue();
+ return new Translation("pt-BR", "key", text).HasValue();
}
[Test(Description = "Assert that the translation's ToString method returns the expected text for various inputs.")]
public void Translation_ToString([ValueSource(nameof(TranslationTests.Samples))] string text)
{
// act
- Translation translation = new Translation("ModName", "pt-BR", "key", text);
+ Translation translation = new Translation("pt-BR", "key", text);
// assert
if (translation.HasValue())
@@ -128,7 +129,7 @@ namespace StardewModdingAPI.Tests.Core
public void Translation_ImplicitStringConversion([ValueSource(nameof(TranslationTests.Samples))] string text)
{
// act
- Translation translation = new Translation("ModName", "pt-BR", "key", text);
+ Translation translation = new Translation("pt-BR", "key", text);
// assert
if (translation.HasValue())
@@ -141,7 +142,7 @@ namespace StardewModdingAPI.Tests.Core
public void Translation_UsePlaceholder([Values(true, false)] bool value, [ValueSource(nameof(TranslationTests.Samples))] string text)
{
// act
- Translation translation = new Translation("ModName", "pt-BR", "key", text).UsePlaceholder(value);
+ Translation translation = new Translation("pt-BR", "key", text).UsePlaceholder(value);
// assert
if (translation.HasValue())
@@ -152,24 +153,11 @@ namespace StardewModdingAPI.Tests.Core
Assert.AreEqual(this.GetPlaceholderText("key"), translation.ToString(), "The translation returned an unexpected value given a null or empty input with the placeholder enabled.");
}
- [Test(Description = "Assert that the translation's Assert method throws the expected exception.")]
- public void Translation_Assert([ValueSource(nameof(TranslationTests.Samples))] string text)
- {
- // act
- Translation translation = new Translation("ModName", "pt-BR", "key", text);
-
- // assert
- if (translation.HasValue())
- Assert.That(() => translation.Assert(), Throws.Nothing, "The assert unexpected threw an exception for a valid input.");
- else
- Assert.That(() => translation.Assert(), Throws.Exception.TypeOf<KeyNotFoundException>(), "The assert didn't throw an exception for invalid input.");
- }
-
[Test(Description = "Assert that the translation returns the expected text after setting the default.")]
public void Translation_Default([ValueSource(nameof(TranslationTests.Samples))] string text, [ValueSource(nameof(TranslationTests.Samples))] string @default)
{
// act
- Translation translation = new Translation("ModName", "pt-BR", "key", text).Default(@default);
+ Translation translation = new Translation("pt-BR", "key", text).Default(@default);
// assert
if (!string.IsNullOrEmpty(text))
@@ -194,7 +182,7 @@ namespace StardewModdingAPI.Tests.Core
string expected = $"{start} tokens are properly replaced (including {middle} {middle}) {end}";
// act
- Translation translation = new Translation("ModName", "pt-BR", "key", input);
+ Translation translation = new Translation("pt-BR", "key", input);
switch (structure)
{
case "anonymous object":
@@ -235,7 +223,7 @@ namespace StardewModdingAPI.Tests.Core
string value = Guid.NewGuid().ToString("N");
// act
- Translation translation = new Translation("ModName", "pt-BR", "key", text).Tokens(new Dictionary<string, object> { [key] = value });
+ Translation translation = new Translation("pt-BR", "key", text).Tokens(new Dictionary<string, object> { [key] = value });
// assert
Assert.AreEqual(value, translation.ToString(), "The translation returned an unexpected value given a valid base text.");
@@ -245,13 +233,13 @@ namespace StardewModdingAPI.Tests.Core
[TestCase("{{value}}", "value")]
[TestCase("{{VaLuE}}", "vAlUe")]
[TestCase("{{VaLuE }}", " vAlUe")]
- public void Translation_Tokens_KeysAreNormalised(string text, string key)
+ public void Translation_Tokens_KeysAreNormalized(string text, string key)
{
// arrange
string value = Guid.NewGuid().ToString("N");
// act
- Translation translation = new Translation("ModName", "pt-BR", "key", text).Tokens(new Dictionary<string, object> { [key] = value });
+ Translation translation = new Translation("pt-BR", "key", text).Tokens(new Dictionary<string, object> { [key] = value });
// assert
Assert.AreEqual(value, translation.ToString(), "The translation returned an unexpected value given a valid base text.");
@@ -302,19 +290,19 @@ namespace StardewModdingAPI.Tests.Core
{
["default"] = new[]
{
- new Translation(string.Empty, "default", "key A", "default A"),
- new Translation(string.Empty, "default", "key C", "default C")
+ new Translation("default", "key A", "default A"),
+ new Translation("default", "key C", "default C")
},
["en"] = new[]
{
- new Translation(string.Empty, "en", "key A", "en A"),
- new Translation(string.Empty, "en", "key B", "en B"),
- new Translation(string.Empty, "en", "key C", "default C")
+ new Translation("en", "key A", "en A"),
+ new Translation("en", "key B", "en B"),
+ new Translation("en", "key C", "default C")
},
["zzz"] = new[]
{
- new Translation(string.Empty, "zzz", "key A", "zzz A"),
- new Translation(string.Empty, "zzz", "key C", "default C")
+ new Translation("zzz", "key A", "zzz A"),
+ new Translation("zzz", "key C", "default C")
}
};
expected["en-us"] = expected["en"].ToArray();