Skip to content

Commit

Permalink
Merge pull request #53 from Axemasta/testing
Browse files Browse the repository at this point in the history
Implement Unit & Behaviour Tests For Main Library
  • Loading branch information
Axemasta authored Mar 4, 2025
2 parents e009498 + 5c38ea8 commit 491847e
Show file tree
Hide file tree
Showing 67 changed files with 5,684 additions and 553 deletions.
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 Down
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 @@ public interface IConfigurationManager<TConfig>
/// <summary>
/// The configuration for the given area
/// </summary>
TConfig Configuration { get; set; }
TConfig Configuration { get; }
}

/// <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

0 comments on commit 491847e

Please sign in to comment.