Skip to content

Commit

Permalink
Add test for Control.Language property resource
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Dec 1, 2020
1 parent 8dac449 commit 2d3d8c6
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
2 changes: 2 additions & 0 deletions GUI/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Resources;
using System.Reflection;
using System.Runtime.CompilerServices;

[assembly: AssemblyTitle("CKAN-GUI")]
[assembly: AssemblyDescription("CKAN GUI Client")]
[assembly: NeutralResourcesLanguage("en-GB")]

[assembly: InternalsVisibleTo("CKAN.Tests")]
2 changes: 1 addition & 1 deletion GUI/SingleAssemblyComponentResourceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace CKAN
{
// Thanks and credit to this guy: https://stackoverflow.com/q/1952638/2422988

class SingleAssemblyComponentResourceManager : ComponentResourceManager
internal class SingleAssemblyComponentResourceManager : ComponentResourceManager
{
public SingleAssemblyComponentResourceManager(Type t) : base(t)
{
Expand Down
64 changes: 64 additions & 0 deletions Tests/GUI/ResourcesTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using System.Linq;
using System.ComponentModel;
using System.Globalization;
using NUnit.Framework;

namespace Tests.GUI
{
[TestFixture]
public class ResourcesTests
{
/// <summary>
/// .resx files should never have a $this.Language property because it
/// does not deserialize properly in Windows when serialized on Mono 6+
/// </summary>
[Test,
// Controls
TestCase(typeof(CKAN.AllModVersions)),
TestCase(typeof(CKAN.Changeset)),
TestCase(typeof(CKAN.ChooseProvidedMods)),
TestCase(typeof(CKAN.ChooseRecommendedMods)),
TestCase(typeof(CKAN.DeleteDirectories)),
TestCase(typeof(CKAN.EditModpack)),
TestCase(typeof(CKAN.EditModSearch)),
TestCase(typeof(CKAN.HintTextBox)),
TestCase(typeof(CKAN.ManageMods)),
TestCase(typeof(CKAN.ModInfo)),
TestCase(typeof(CKAN.Wait)),

// Dialogs
TestCase(typeof(CKAN.Main)),
TestCase(typeof(CKAN.AboutDialog)),
TestCase(typeof(CKAN.AskUserForAutoUpdatesDialog)),
TestCase(typeof(CKAN.CloneFakeKspDialog)),
TestCase(typeof(CKAN.CompatibleKspVersionsDialog)),
TestCase(typeof(CKAN.EditLabelsDialog)),
TestCase(typeof(CKAN.ErrorDialog)),
TestCase(typeof(CKAN.KSPCommandLineOptionsDialog)),
TestCase(typeof(CKAN.ManageKspInstancesDialog)),
TestCase(typeof(CKAN.NewRepoDialog)),
TestCase(typeof(CKAN.NewUpdateDialog)),
TestCase(typeof(CKAN.PluginsDialog)),
TestCase(typeof(CKAN.RenameInstanceDialog)),
TestCase(typeof(CKAN.SelectionDialog)),
TestCase(typeof(CKAN.YesNoDialog)),
]
public void ControlOrDialog_LanguageResource_NotSet(Type t)
{
// Arrange
ComponentResourceManager resources = new CKAN.SingleAssemblyComponentResourceManager(t);

// Act/Assert
foreach (CultureInfo resourceCulture in cultures)
{
Assert.IsNull(resources.GetObject("$this.Language", resourceCulture));
}
}

// The cultures to test
private static CultureInfo[] cultures = CKAN.Utilities.AvailableLanguages
.Select(l => new CultureInfo(l))
.ToArray();
}
}

0 comments on commit 2d3d8c6

Please sign in to comment.