Tests fixes and minor refactoring:

- Fixed broken test due to missing static images.
- Fixed NUnitEngineExeption thrown due to StackOverflowException when searching
  for non-existing assembly (due to wrong branding).
- Commented out ignored tests causing the overall NUnit result to be reported as
  Warning instead of Passed.

Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
Konstantina Chremmou 2021-07-25 14:49:50 +01:00
parent d790d5c516
commit e0bedb88a9
6 changed files with 55 additions and 25 deletions

View File

@ -122,6 +122,9 @@
<data name="BRAND_CONSOLE" xml:space="preserve">
<value>[XenCenter]</value>
</data>
<data name="BRAND_CONSOLE_NO_SPACE" xml:space="preserve">
<value>[XenCenter_No_Space]</value>
</data>
<data name="CIS" xml:space="preserve">
<value>Citrix Insight Services</value>
</data>

View File

@ -175,8 +175,8 @@ namespace XenAdmin.Controls
{
get
{
int t1, t2;
return CalcSizeAndTrunc(int.MaxValue, out t1, out t2);
using (var g = Parent.CreateGraphics())
return CalcSizeAndTrunc(g, int.MaxValue, out _, out _);
}
}
@ -264,14 +264,6 @@ namespace XenAdmin.Controls
return theSize;
}
private Size CalcSizeAndTrunc(int width, out int trunc1, out int trunc2)
{
Graphics g = this.Parent.CreateGraphics();
Size sz = CalcSizeAndTrunc(g, width, out trunc1, out trunc2);
g.Dispose();
return sz;
}
private FLIControl OnControl(Point point)
{
foreach (FLIControl control in controls)

View File

@ -861,6 +861,8 @@ namespace XenAdmin
public static Bitmap pool_up_16 = Properties.Resources.pool_up_16;
public static Bitmap redhat_16x = Properties.Resources.redhat_16x;
public static Bitmap Refresh16 = Properties.Resources.Refresh16;
public static Bitmap RightArrow = Properties.Resources.RightArrow;
public static Bitmap LeftArrow = Properties.Resources.LeftArrow;
public static Bitmap RunningDC_16 = Properties.Resources.RunningDC_16;
public static Bitmap saved_searches_16 = Properties.Resources.saved_searches_16;
public static Bitmap saved_searches_24 = Properties.Resources.saved_searches_24;

View File

@ -37,6 +37,7 @@ using System.Configuration;
using System.Drawing;
using System.Reflection;
using NUnit.Framework;
using XenAdmin.Core;
namespace XenAdminTests.CodeTests
@ -44,6 +45,38 @@ namespace XenAdminTests.CodeTests
[TestFixture, Category(TestCategories.Unit)]
public class AssemblyTests
{
private static readonly string MainAssemblyName = $"{BrandManager.BrandConsoleNoSpace}Main";
public class TestDataClass
{
public string AssemblyName { get; set; }
public string Locale { get; set; }
}
private static IEnumerable<TestDataClass> TestCasesForI18NFiles
{
get
{
yield return new TestDataClass {AssemblyName = MainAssemblyName, Locale = "ja"};
yield return new TestDataClass {AssemblyName = MainAssemblyName, Locale = "zh-CN"};
yield return new TestDataClass {AssemblyName = "XenModel", Locale = "ja"};
yield return new TestDataClass {AssemblyName = "XenModel", Locale = "zh-CN"};
yield return new TestDataClass {AssemblyName = "XenOvf", Locale = "ja"};
yield return new TestDataClass {AssemblyName = "XenOvf", Locale = "zh-CN"};
}
}
private static IEnumerable<TestDataClass> TestCasesForRoaming
{
get
{
yield return new TestDataClass {AssemblyName = MainAssemblyName};
yield return new TestDataClass {AssemblyName = "XenOvf"};
yield return new TestDataClass {AssemblyName = "XenServerHealthCheck"};
}
}
[Test]
[Description("Checks that there are no Bitmaps in XenAdmin.Resources" +
"without a counterpart in XenAdmin.Images.StaticImages")]
@ -72,14 +105,12 @@ namespace XenAdminTests.CodeTests
$"Resources without a static counterpart: {string.Join(", ", extraImages)}");
}
[Test, Combinatorial]
[Test, TestCaseSource(typeof(AssemblyTests), nameof(TestCasesForI18NFiles))]
[Description("Checks all resx files in the project have their i18n counterparts in place")]
public void TestEnsureI18NFilesInPlace(
[Values("ja", "zh-CN")] string locale,
[Values("XenCenterMain", "XenModel", "XenOvf")] string assemblyName)
public void TestEnsureI18NFilesInPlace(TestDataClass tc)
{
var assembly = FindAssemblyByNameRecursively(assemblyName);
Assert.NotNull($"Assembly {assemblyName} was not found.");
var assembly = FindAssemblyByNameRecursively(tc.AssemblyName);
Assert.NotNull($"Assembly {tc.AssemblyName} was not found.");
var excludeFromCheck = new[] {"XenAdmin.Help.HelpManager", "XenAdmin.Branding", "DotNetVnc.KeyMap"};
var missing = new List<string>();
@ -87,7 +118,7 @@ namespace XenAdminTests.CodeTests
List<string> defaultResx = new List<string>(assembly.GetManifestResourceNames().Where(resource => resource.EndsWith("resources")));
CultureInfo cultureInfo = new CultureInfo(locale);
CultureInfo cultureInfo = new CultureInfo(tc.Locale);
Assembly localeDll = assembly.GetSatelliteAssembly(cultureInfo);
List<string> localeResx = new List<string>(localeDll.GetManifestResourceNames());
@ -96,7 +127,7 @@ namespace XenAdminTests.CodeTests
var name = def.Substring(0, def.Length - ".resources".Length);
var exclude = excludeFromCheck.Contains(name);
string localName = $"{name}.{locale}.resources";
string localName = $"{name}.{tc.Locale}.resources";
var localized = localeResx.Contains(localName);
if (localized && exclude)
@ -109,13 +140,12 @@ namespace XenAdminTests.CodeTests
Assert.IsEmpty(extra, "Unnecessary resources detected.");
}
[Test]
[Test, TestCaseSource(typeof(AssemblyTests), nameof(TestCasesForRoaming))]
[Description("Checks that if there are user-scoped settings in an assembly, these have roaming=true")]
public void TestUserSettingsAreRoaming(
[Values("XenCenterMain", "XenOvf", "XenServerHealthCheck")] string assemblyName)
public void TestUserSettingsAreRoaming(TestDataClass tc)
{
var assembly = FindAssemblyByNameRecursively(assemblyName);
Assert.NotNull($"Assembly {assemblyName} was not found.");
var assembly = FindAssemblyByNameRecursively(tc.AssemblyName);
Assert.NotNull($"Assembly {tc.AssemblyName} was not found.");
var nonRoaming = new List<string>();

View File

@ -54,12 +54,13 @@ namespace XenAdminTests.Controls.Folders
parent.Dispose();
}
[Ignore("Needs revisiting")]
/*TODO: needs revisiting
[Test]
[TestCase("", ExpectedResult = 43)]
[TestCase("mypath", ExpectedResult = 44)]
[TestCase("mypathmypathmypathmypathmypathmypathmypathmypathmypathmypathmypath", ExpectedResult = 454)]
public int CalculatePreferedSizes(string path)
*/
public int CalculatePreferredSizes(string path)
{
var item = new FolderListItem(path, FolderListItem.AllowSearch.None, false)
{

View File

@ -42,6 +42,8 @@ namespace XenAdmin.Core
public static readonly string BrandConsole = Get("BRAND_CONSOLE");
public static readonly string BrandConsoleNoSpace = Get("BRAND_CONSOLE_NO_SPACE");
public static readonly string Cis = Get("CIS");
public static readonly string CompanyNameLegal = Get("COMPANY_NAME_LEGAL");