Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for Control.Language property resource #3219

Merged
merged 1 commit into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}