Skip to content

Commit

Permalink
Merge pull request #292 from atc-net/feature/CodeCompliance-for-Local…
Browse files Browse the repository at this point in the history
…ization-Translations

Extend code compliance for localization translations
  • Loading branch information
davidkallesen authored Oct 19, 2023
2 parents 97559e4 + 3c6bfe8 commit 6e66f97
Show file tree
Hide file tree
Showing 10 changed files with 637 additions and 11 deletions.
35 changes: 34 additions & 1 deletion docs/CodeDoc/Atc.XUnit/Atc.XUnit.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,35 @@ CodeComplianceNamingHelper.
><b>Parameters:</b><br>
>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`type`&nbsp;&nbsp;-&nbsp;&nbsp;The type.<br />
>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`useFullName`&nbsp;&nbsp;-&nbsp;&nbsp;if set to true [use full name].<br />
#### AssertLocalizationResources
>```csharp
>void AssertLocalizationResources(Assembly assembly, IList<string> cultureNames, IList<string> allowSuffixTermsForKeySuffixWithPlaceholders = null)
>```
><b>Summary:</b> Asserts the localization resources with missing translations or invalid keys with placeholders in value.
>
><b>Parameters:</b><br>
>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`assembly`&nbsp;&nbsp;-&nbsp;&nbsp;The assembly.<br />
>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`cultureNames`&nbsp;&nbsp;-&nbsp;&nbsp;The culture names.<br />
>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`allowSuffixTermsForKeySuffixWithPlaceholders`&nbsp;&nbsp;-&nbsp;&nbsp;The allow suffix terms for key suffix with placeholders.<br />
#### AssertLocalizationResourcesForInvalidKeysSuffixWithPlaceholders
>```csharp
>void AssertLocalizationResourcesForInvalidKeysSuffixWithPlaceholders(Assembly assembly, IList<string> cultureNames, IList<string> allowSuffixTermsForKeySuffixWithPlaceholders = null)
>```
><b>Summary:</b> Asserts the localization resources with invalid keys with placeholders in value.
>
><b>Parameters:</b><br>
>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`assembly`&nbsp;&nbsp;-&nbsp;&nbsp;The assembly.<br />
>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`cultureNames`&nbsp;&nbsp;-&nbsp;&nbsp;The culture names.<br />
>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`allowSuffixTermsForKeySuffixWithPlaceholders`&nbsp;&nbsp;-&nbsp;&nbsp;The allow suffix terms for key suffix with placeholders.<br />
#### AssertLocalizationResourcesForMissingTranslations
>```csharp
>void AssertLocalizationResourcesForMissingTranslations(Assembly assembly, IList<string> cultureNames)
>```
><b>Summary:</b> Asserts the localization resources with missing translations.
>
><b>Parameters:</b><br>
>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`assembly`&nbsp;&nbsp;-&nbsp;&nbsp;The assembly.<br />
>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`cultureNames`&nbsp;&nbsp;-&nbsp;&nbsp;The culture names.<br />
<br />
Expand Down Expand Up @@ -451,14 +480,18 @@ TestResultHelper.
>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`useFullName`&nbsp;&nbsp;-&nbsp;&nbsp;if set to true [use full name].<br />
#### AssertOnTestResultsFromMethodsWithWrongDefinitions
>```csharp
>void AssertOnTestResultsFromMethodsWithWrongDefinitions(string assemblyName, Dictionary<MethodInfo, string> methodsWithWrongNaming, bool useFullName = False)
>void AssertOnTestResultsFromMethodsWithWrongDefinitions(string assemblyName, IDictionary<MethodInfo, string> methodsWithWrongNaming, bool useFullName = False)
>```
><b>Summary:</b> Asserts the on test results from methods with wrong definitions.
>
><b>Parameters:</b><br>
>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`assemblyName`&nbsp;&nbsp;-&nbsp;&nbsp;Name of the assembly.<br />
>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`methodsWithWrongNaming`&nbsp;&nbsp;-&nbsp;&nbsp;The methods with wrong naming.<br />
>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`useFullName`&nbsp;&nbsp;-&nbsp;&nbsp;if set to true [use full name].<br />
#### AssertOnTestResultsFromMissingTranslationsAndInvalidKeysSuffixWithPlaceholders
>```csharp
>void AssertOnTestResultsFromMissingTranslationsAndInvalidKeysSuffixWithPlaceholders(string assemblyName, IDictionary<string, Dictionary<string, List<string>>> missingTranslations, IDictionary<string, Dictionary<string, List<string>>> invalidKeysSuffixWithPlaceholders)
>```
#### ToExcelTestResultsFromMethodsWithMissingTests
>```csharp
>void ToExcelTestResultsFromMethodsWithMissingTests(DirectoryInfo reportDirectory, string assemblyName, MethodInfo[] methodsWithMissingTests)
Expand Down
6 changes: 5 additions & 1 deletion docs/CodeDoc/Atc.XUnit/IndexExtended.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
- Static Methods
- AssertExportedTypesWithWrongDefinitions(Assembly assembly, List&lt;Type&gt; excludeTypes = null, bool useFullName = False)
- AssertExportedTypesWithWrongDefinitions(Type type, bool useFullName = False)
- AssertLocalizationResources(Assembly assembly, IList&lt;string&gt; cultureNames, IList&lt;string&gt; allowSuffixTermsForKeySuffixWithPlaceholders = null)
- AssertLocalizationResourcesForInvalidKeysSuffixWithPlaceholders(Assembly assembly, IList&lt;string&gt; cultureNames, IList&lt;string&gt; allowSuffixTermsForKeySuffixWithPlaceholders = null)
- AssertLocalizationResourcesForMissingTranslations(Assembly assembly, IList&lt;string&gt; cultureNames)
- [CodeComplianceTestHelper](Atc.XUnit.md#codecompliancetesthelper)
- Static Methods
- AssertExportedMethodsWithMissingTests(DecompilerType decompilerType, Assembly sourceAssembly, Assembly testAssembly, List&lt;Type&gt; excludeSourceTypes = null, bool useFullName = False)
Expand Down Expand Up @@ -51,7 +54,8 @@
- Static Methods
- AssertOnTestResults(IReadOnlyCollection&lt;TestResult&gt; testResults)
- AssertOnTestResultsFromMethodsWithMissingTests(string assemblyName, MethodInfo[] methodsWithMissingTests, bool useFullName = False)
- AssertOnTestResultsFromMethodsWithWrongDefinitions(string assemblyName, Dictionary&lt;MethodInfo, string&gt; methodsWithWrongNaming, bool useFullName = False)
- AssertOnTestResultsFromMethodsWithWrongDefinitions(string assemblyName, IDictionary&lt;MethodInfo, string&gt; methodsWithWrongNaming, bool useFullName = False)
- AssertOnTestResultsFromMissingTranslationsAndInvalidKeysSuffixWithPlaceholders(string assemblyName, IDictionary&lt;string, Dictionary&lt;string, List&lt;string&gt;&gt;&gt; missingTranslations, IDictionary&lt;string, Dictionary&lt;string, List&lt;string&gt;&gt;&gt; invalidKeysSuffixWithPlaceholders)
- ToExcelTestResultsFromMethodsWithMissingTests(DirectoryInfo reportDirectory, string assemblyName, MethodInfo[] methodsWithMissingTests)
- [Traits](Atc.XUnit.md#traits)
- Static Fields
Expand Down
4 changes: 4 additions & 0 deletions src/Atc.XUnit/Atc.XUnit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@
<ProjectReference Include="..\Atc\Atc.csproj" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="Atc.XUnit.Tests" />
</ItemGroup>

</Project>
82 changes: 82 additions & 0 deletions src/Atc.XUnit/CodeComplianceHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,86 @@ public static void AssertExportedTypesWithWrongDefinitions(
methodsWithWrongNaming,
useFullName);
}

/// <summary>
/// Asserts the localization resources with missing translations or invalid keys with placeholders in value.
/// </summary>
/// <param name="assembly">The assembly.</param>
/// <param name="cultureNames">The culture names.</param>
/// <param name="allowSuffixTermsForKeySuffixWithPlaceholders">The allow suffix terms for key suffix with placeholders.</param>
public static void AssertLocalizationResources(
Assembly assembly,
IList<string> cultureNames,
IList<string>? allowSuffixTermsForKeySuffixWithPlaceholders = null)
{
if (assembly is null)
{
throw new ArgumentNullException(nameof(assembly));
}

var missingTranslations = AssemblyLocalizationResourcesHelper.CollectMissingTranslations(
assembly,
cultureNames);

var invalidKeysSuffixWithPlaceholders = AssemblyLocalizationResourcesHelper.CollectInvalidKeySuffixWithPlaceholders(
assembly,
cultureNames,
allowSuffixTermsForKeySuffixWithPlaceholders);

TestResultHelper.AssertOnTestResultsFromMissingTranslationsAndInvalidKeysSuffixWithPlaceholders(
assembly.GetName().Name,
missingTranslations,
invalidKeysSuffixWithPlaceholders);
}

/// <summary>
/// Asserts the localization resources with missing translations.
/// </summary>
/// <param name="assembly">The assembly.</param>
/// <param name="cultureNames">The culture names.</param>
public static void AssertLocalizationResourcesForMissingTranslations(
Assembly assembly,
IList<string> cultureNames)
{
if (assembly is null)
{
throw new ArgumentNullException(nameof(assembly));
}

var missingTranslations = AssemblyLocalizationResourcesHelper.CollectMissingTranslations(
assembly,
cultureNames);

TestResultHelper.AssertOnTestResultsFromMissingTranslationsAndInvalidKeysSuffixWithPlaceholders(
assembly.GetName().Name,
missingTranslations,
invalidKeysSuffixWithPlaceholders: null);
}

/// <summary>
/// Asserts the localization resources with invalid keys with placeholders in value.
/// </summary>
/// <param name="assembly">The assembly.</param>
/// <param name="cultureNames">The culture names.</param>
/// <param name="allowSuffixTermsForKeySuffixWithPlaceholders">The allow suffix terms for key suffix with placeholders.</param>
public static void AssertLocalizationResourcesForInvalidKeysSuffixWithPlaceholders(
Assembly assembly,
IList<string> cultureNames,
IList<string>? allowSuffixTermsForKeySuffixWithPlaceholders = null)
{
if (assembly is null)
{
throw new ArgumentNullException(nameof(assembly));
}

var invalidKeysSuffixWithPlaceholders = AssemblyLocalizationResourcesHelper.CollectInvalidKeySuffixWithPlaceholders(
assembly,
cultureNames,
allowSuffixTermsForKeySuffixWithPlaceholders);

TestResultHelper.AssertOnTestResultsFromMissingTranslationsAndInvalidKeysSuffixWithPlaceholders(
assembly.GetName().Name,
missingTranslations: null,
invalidKeysSuffixWithPlaceholders);
}
}
3 changes: 3 additions & 0 deletions src/Atc.XUnit/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
global using System.Collections;
global using System.Diagnostics;
global using System.Diagnostics.CodeAnalysis;
global using System.Globalization;
global using System.Reflection;
global using System.Resources;
global using System.Runtime.CompilerServices;
global using System.Runtime.InteropServices;
global using System.Text;
Expand Down
Loading

0 comments on commit 6e66f97

Please sign in to comment.