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

Implement Unit & Behaviour Tests For Main Library #53

Merged
merged 25 commits into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
34a67c9
Added MocaleBuilder Tests
Axemasta Feb 25, 2025
f8d8f78
Added MocaleBuilderExtension Tests
Axemasta Feb 26, 2025
6d7d84a
Add Initialize & Locator Tests
Axemasta Feb 26, 2025
00ca6bb
Test cases for enum functionality
Axemasta Feb 26, 2025
2ec6ce6
Internal Provider Tests
Axemasta Feb 26, 2025
3de36d3
UriExtension tests
Axemasta Feb 26, 2025
9f9b8b7
Removed DateTime Wrapper
Axemasta Feb 26, 2025
052dffa
Unhide nuget packages
Axemasta Feb 26, 2025
1af6847
Work In Progress BindableObjectExtensions
Axemasta Feb 28, 2025
83784c1
Implement binding extensions for TranslateBinding
Axemasta Feb 28, 2025
a12bd70
Added tests for enum binding extensions
Axemasta Feb 28, 2025
6a49e24
Localize Extension Tested & Refined
Axemasta Feb 28, 2025
998273c
Test LocalizeBinding + Binding Extension Base Class
Axemasta Feb 28, 2025
a49b74d
Implemented LocalizeBinding Converter Tests
Axemasta Mar 1, 2025
503f399
Implement LocalizeEnumExtension Tests
Axemasta Mar 2, 2025
47e7957
Implement LocalizeMultiBindingExtension Tests
Axemasta Mar 2, 2025
ba09267
Localize multi now casts binded values to string
Axemasta Mar 3, 2025
0e46af9
Coverage
Axemasta Mar 3, 2025
54106a6
Added MultiBinding Code Extension + Tests
Axemasta Mar 3, 2025
63530aa
Reduce warnings & translator manager tests
Axemasta Mar 3, 2025
5444926
Implemented Translation Resolver Tests
Axemasta Mar 3, 2025
570f6d3
Fix locale switching when external fails
Axemasta Mar 3, 2025
475a77f
Fix tests
Axemasta Mar 3, 2025
e47c099
Set thread culture
Axemasta Mar 3, 2025
5c38ea8
Fix LocalizationManager Dispose
Axemasta Mar 4, 2025
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
1 change: 1 addition & 0 deletions .resxpress/namespace-mapping.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"TestResources.fr-FR":"Mocale.UnitTests.Resources"}
27 changes: 2 additions & 25 deletions samples/Mocale.Samples/Pages/ParameterPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,16 @@
VerticalOptions="Start">

<Label Text="{mocale:Localize Key={x:Static keys:TranslationKeys.ParameterPageHeading}}" />

<Label Text="This feature is experimental and not yet mature, use at your own discretion!" />


<Border Padding="20">
<VerticalStackLayout Spacing="10">

<Label FontSize="Title" Text="{mocale:Localize Key={x:Static keys:TranslationKeys.ParameterPageSectionOneHeading}}" />
<Label Margin="0,0,0,10" Text="{mocale:Localize Key={x:Static keys:TranslationKeys.ParameterPageSectionOneSubHeading}}" />

<Label FontAttributes="Bold" Text="{mocale:Localize Key={x:Static keys:TranslationKeys.ParameterPageBasicStringFormatLabel}}" />
<Label Margin="0,0,0,10" Text="{mocale:Localize Key={x:Static keys:TranslationKeys.ParameterPageBasicStringFormat}, Parameters='W O R L D!'}" />

<Label FontAttributes="Bold" Text="{mocale:Localize Key={x:Static keys:TranslationKeys.ParameterPageLargeStringFormatLabel}}" />
<Label Margin="0,0,0,10" Text="{mocale:Localize Key={x:Static keys:TranslationKeys.ParameterPageLargeStringFormat}, Parameters='World|23-07-2024|23'}" />

<Label FontAttributes="Bold" Text="{mocale:Localize Key={x:Static keys:TranslationKeys.ParameterPageMultipleFormatsSameValueLabel}}" />
<Label Text="{mocale:Localize Key={x:Static keys:TranslationKeys.ParameterPageMultipleFormatsSameValue}, Parameters='mate'}" />

</VerticalStackLayout>
</Border>

<Border Padding="20">
<VerticalStackLayout Spacing="10">

<Label FontSize="Title" Text="{mocale:Localize Key={x:Static keys:TranslationKeys.ParameterPageSectionTwoHeading}}" />
<Label Margin="0,0,0,10" Text="{mocale:Localize Key={x:Static keys:TranslationKeys.ParameterPageSectionTwoSubHeading}}" />
<Label FontSize="Title" Text="{mocale:Localize Key={x:Static keys:TranslationKeys.ParameterPageSectionHeading}}" />
<Label Margin="0,0,0,10" Text="{mocale:Localize Key={x:Static keys:TranslationKeys.ParameterPageSectionSubHeading}}" />

<Label FontAttributes="Bold" Text="{mocale:Localize Key={x:Static keys:TranslationKeys.ParameterPageBasicStringFormatLabel}}" />
<Label Margin="0,0,0,10" Text="{mocale:LocalizeBinding Name, TranslationKey={x:Static keys:TranslationKeys.ParameterPageBasicStringFormat}}" />

<Label FontAttributes="Bold" Text="{mocale:Localize Key={x:Static keys:TranslationKeys.ParameterPageLargeStringFormatLabel}}" />
<!--<Label Margin="0,0,0,10" Text="{mocale:Localize Key={x:Static keys:TranslationKeys.ParameterPageLargeStringFormat}}" />-->
<Label Margin="0,0,0,10">
<Label.Text>
<mocale:LocalizeMultiBinding TranslationKey="{x:Static keys:TranslationKeys.ParameterPageLargeStringFormat}">
Expand Down
8 changes: 3 additions & 5 deletions samples/Mocale.Samples/Resources/Locales/en-GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@
"BindingPage_CodeBehind_Heading": "In this example we have a label whos translation will be set via code behind using the SetTranslation method.",
"BindingPage_CodeBehind_LabelKey": "This translation was set in c# code, not xaml!",
"ParameterPage_Title": "Parameters",
"ParameterPage_Heading": "Here we can see examples of string formatting using Mocale. Use the normal .NET string format notation ({0}, {1}) and provide these values to localize the formats",
"ParameterPage_SectionOne_Heading": "Static Localizations",
"ParameterPage_SectionOne_SubHeading": "All of the following values have been localized using static xaml.",
"ParameterPage_Heading": "Here we can see examples of string formatting using Mocale. Use the normal .NET string format notation ({0}, {1}) and provide these values to localize the formats.\r\nThese can be bound to any property, for single Bindings use LocalizeBinding and for multiple use LocalizeMultiBinding",
"ParameterPage_Section_Heading": "Parameterized Localizations",
"ParameterPage_Section_SubHeading": "All of the following values have been localized using both translation keys and the value they are bound to.",
"ParameterPage_BasicStringFormat_Label": "A basic string format",
"ParameterPage_BasicStringFormat": "Hello {0}",
"ParameterPage_LargeStringFormat_Label": "A larger string format",
"ParameterPage_LargeStringFormat": "Hello {0}, todays date is {1} and the weather is {2}°C",
"ParameterPage_MultipleFormatsSameValue_Label": "A string format with the same value multiple times",
"ParameterPage_MultipleFormatsSameValue": "Hello {0}, Hello {0}, Hello {0}",
"ParameterPage_SectionTwo_Heading": "Binded Localizations",
"ParameterPage_SectionTwo_SubHeading": "All of the following values have been localized using bindings. If the binded values update the strings will update accordingly",
"CodePage_Title": "Code",
"CodePage_Heading": "This page is built entirely through code behind, you can see examples of everything Mocale has to offer when not using xaml!"
}
8 changes: 3 additions & 5 deletions samples/Mocale.Samples/Resources/Locales/fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@
"BindingPage_CodeBehind_Heading": "Dans cet exemple, nous avons une étiquette dont la traduction sera définie via le code derrière en utilisant la méthode SetTranslation.",
"BindingPage_CodeBehind_LabelKey": "Cette traduction a été définie dans du code C#, pas en Xaml !",
"ParameterPage_Title": "Paramètres",
"ParameterPage_Heading": "Ici, nous pouvons voir des exemples de formatage de chaîne à l'aide de Mocale. Utilisez la notation normale de format de chaîne .NET ({0}, {1}) et fournissez ces valeurs pour localiser les formats",
"ParameterPage_SectionOne_Heading": "Localisations statiques",
"ParameterPage_SectionOne_SubHeading": "Toutes les valeurs suivantes ont été localisées à l'aide de XML statique.",
"ParameterPage_Heading": "Ici, nous pouvons voir des exemples de formatage de chaîne à l'aide de Mocale. Utilisez la notation normale du format de chaîne .NET ({0}, {1}) et fournissez ces valeurs pour localiser les formats.\r\nCeux-ci peuvent être liés à n'importe quelle propriété, pour des liaisons uniques, utilisez LocalizeBinding et pour une utilisation multiple LocalizeMultiBinding",
"ParameterPage_Section_Heading": "Localisations paramétrées",
"ParameterPage_Section_SubHeading": "Toutes les valeurs suivantes ont été localisées à l'aide des clés de traduction et de la valeur à laquelle elles sont liées.",
"ParameterPage_BasicStringFormat_Label": "Un format de chaîne de base",
"ParameterPage_BasicStringFormat": "Bonjour {0}",
"ParameterPage_LargeStringFormat_Label": "Un format de chaîne plus grand",
"ParameterPage_LargeStringFormat": "Bonjour {0}, la date d'aujourd'hui est {1} et la météo est {2}°C",
"ParameterPage_MultipleFormatsSameValue_Label": "Un format de chaîne avec la même valeur plusieurs fois",
"ParameterPage_MultipleFormatsSameValue": "Bonjour {0}, Bonjour {0}, Bonjour {0}",
"ParameterPage_SectionTwo_Heading": "Localisations liées",
"ParameterPage_SectionTwo_SubHeading": "Toutes les valeurs suivantes ont été localisées à l'aide de liaisons. Si les valeurs liées sont mises à jour, les chaînes seront mises à jour en conséquence",
"CodePage_Title": "Code",
"CodePage_Heading": "Cette page est entièrement construite grâce au code derrière, vous pouvez voir des exemples de tout ce que Mocale a à offrir lorsque vous n'utilisez pas xaml!"
}
14 changes: 7 additions & 7 deletions src/Mocale.Cache.SQLite/Managers/SqlCacheUpdateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ namespace Mocale.Cache.SQLite.Managers;
internal class SqlCacheUpdateManager : ICacheUpdateManager
{
private readonly ICacheRepository cacheRepository;
private readonly IDateTime dateTime;
private readonly ILogger logger;

private readonly ISqliteConfig sqliteConfig;
private readonly TimeProvider timeProvider;

public SqlCacheUpdateManager(
ICacheRepository cacheRepository,
IDateTime dateTime,
ILogger<SqlCacheUpdateManager> logger,
IConfigurationManager<ISqliteConfig> sqliteConfigurationManager)
IConfigurationManager<ISqliteConfig> sqliteConfigurationManager,
TimeProvider timeProvider)
{
this.dateTime = Guard.Against.Null(dateTime, nameof(dateTime));
this.logger = Guard.Against.Null(logger, nameof(logger));
this.cacheRepository = Guard.Against.Null(cacheRepository, nameof(cacheRepository));
this.logger = Guard.Against.Null(logger, nameof(logger));
this.timeProvider = Guard.Against.Null(timeProvider, nameof(timeProvider));

sqliteConfigurationManager = Guard.Against.Null(sqliteConfigurationManager, nameof(sqliteConfigurationManager));
this.sqliteConfig = sqliteConfigurationManager.Configuration;
Expand All @@ -40,13 +40,13 @@ public bool CanUpdateCache(CultureInfo cultureInfo)

var nextUpdateWindow = updateItem.LastUpdated.Add(sqliteConfig.UpdateInterval);

return nextUpdateWindow < dateTime.UtcNow;
return nextUpdateWindow < timeProvider.GetUtcNow();
}

/// <inheritdoc/>
public bool SetCacheUpdated(CultureInfo cultureInfo)
{
return cacheRepository.AddOrUpdateItem(cultureInfo, dateTime.UtcNow);
return cacheRepository.AddOrUpdateItem(cultureInfo, timeProvider.GetUtcNow().DateTime);
}

/// <inheritdoc/>
Expand Down
1 change: 1 addition & 0 deletions src/Mocale/Abstractions/ICacheUpdateManager.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
namespace Mocale.Abstractions;

Expand All @@ -13,23 +14,23 @@
/// </summary>
/// <param name="cultureInfo">The culture to check whether updates can occur</param>
/// <returns>True if external provider should be used (cache expired / no localizations for culture)</returns>
bool CanUpdateCache(CultureInfo cultureInfo);

Check warning on line 17 in src/Mocale/Abstractions/ICacheUpdateManager.cs

View workflow job for this annotation

GitHub Actions / test

Accessibility modifiers required (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0040)

/// <summary>
/// Sets when the cache has been updated for the given culture
/// </summary>
/// <param name="cultureInfo">The culture that has just been updated</param>
/// <returns>Success</returns>
bool SetCacheUpdated(CultureInfo cultureInfo);

Check warning on line 24 in src/Mocale/Abstractions/ICacheUpdateManager.cs

View workflow job for this annotation

GitHub Actions / test

Accessibility modifiers required (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0040)

/// <summary>
/// Clear the cache for a specific culture
/// </summary>
/// <param name="cultureInfo">Culture to clear cache for</param>
void ClearCache(CultureInfo cultureInfo);

Check warning on line 30 in src/Mocale/Abstractions/ICacheUpdateManager.cs

View workflow job for this annotation

GitHub Actions / test

Accessibility modifiers required (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0040)

/// <summary>
/// Clear the cache for all cultures
/// </summary>
void ClearCache();

Check warning on line 35 in src/Mocale/Abstractions/ICacheUpdateManager.cs

View workflow job for this annotation

GitHub Actions / test

Accessibility modifiers required (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0040)
}
2 changes: 1 addition & 1 deletion src/Mocale/Abstractions/IConfigurationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/// <summary>
/// The configuration for the given area
/// </summary>
TConfig Configuration { get; set; }
TConfig Configuration { get; }

Check warning on line 12 in src/Mocale/Abstractions/IConfigurationManager.cs

View workflow job for this annotation

GitHub Actions / test

Accessibility modifiers required (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0040)
}

/// <summary>
Expand Down
12 changes: 0 additions & 12 deletions src/Mocale/Abstractions/IDateTime.cs

This file was deleted.

14 changes: 0 additions & 14 deletions src/Mocale/Abstractions/IParameterTranslatorManager.cs

This file was deleted.

3 changes: 1 addition & 2 deletions src/Mocale/AppBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Mocale.Exceptions;
using Mocale.Managers;
using Mocale.Providers;
using Mocale.Wrappers;
namespace Mocale;

/// <summary>
Expand Down Expand Up @@ -35,7 +34,7 @@ public static MauiAppBuilder UseMocale(
// - Maui Dependencies
mauiAppBuilder.Services.AddSingleton(Preferences.Default);
mauiAppBuilder.Services.AddSingleton(FileSystem.Current);
mauiAppBuilder.Services.AddTransient<IDateTime, DateTimeWrapper>();
mauiAppBuilder.Services.AddSingleton(TimeProvider.System);

// - Localization
mauiAppBuilder.Services.AddSingleton<IConfigurationManager<IMocaleConfiguration>>(mocaleBuilder.ConfigurationManager);
Expand Down
Loading
Loading