diff --git a/FwLiteOnly.slnf b/FwLiteOnly.slnf index 042128013a..8e38cfad8f 100644 --- a/FwLiteOnly.slnf +++ b/FwLiteOnly.slnf @@ -5,6 +5,7 @@ "backend\\FwLite\\FwDataMiniLcmBridge.Tests\\FwDataMiniLcmBridge.Tests.csproj", "backend\\FwLite\\FwDataMiniLcmBridge\\FwDataMiniLcmBridge.csproj", "backend\\FwLite\\FwLiteMaui\\FwLiteMaui.csproj", + "backend\\FwLite\\FwLiteMaui.Tests\\FwLiteMaui.Tests.csproj", "backend\\FwLite\\FwLiteProjectSync.Tests\\FwLiteProjectSync.Tests.csproj", "backend\\FwLite\\FwLiteProjectSync\\FwLiteProjectSync.csproj", "backend\\FwLite\\FwLiteShared\\FwLiteShared.csproj", @@ -18,4 +19,4 @@ "backend\\harmony\\src\\SIL.Harmony\\SIL.Harmony.csproj" ] } -} \ No newline at end of file +} diff --git a/LexBox.sln b/LexBox.sln index b1dd20410c..00cf46cbdc 100644 --- a/LexBox.sln +++ b/LexBox.sln @@ -1,5 +1,6 @@ - + Microsoft Visual Studio Solution File, Format Version 12.00 +# Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SyncReverseProxy", "backend\SyncReverseProxy\SyncReverseProxy.csproj", "{5C589976-854A-4CE8-A661-A2E256AC2FC4}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LexBoxApi", "backend\LexBoxApi\LexBoxApi.csproj", "{A95FC2AC-2B31-4B40-B4DA-6B951ECE3E28}" @@ -21,8 +22,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testing", "backend\Testing\ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FixFwData", "backend\FixFwData\FixFwData.csproj", "{D7FC8B93-15A1-4D0B-9EAB-45596DB147F4}" EndProject - Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "FwLite", "FwLite", "{7B6E21C4-5AF4-4505-B7D9-59A3886C5090}" - EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "FwLite", "FwLite", "{7B6E21C4-5AF4-4505-B7D9-59A3886C5090}" +EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LfClassicData", "backend\LfClassicData\LfClassicData.csproj", "{E8BB768B-C3DC-4BE6-9B9F-82319E05AF86}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MiniLcm", "backend\FwLite\MiniLcm\MiniLcm.csproj", "{6D4062DC-1B1A-4A24-9C61-0F6A18A39882}" @@ -57,6 +58,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FwLiteShared", "backend\FwL EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebServiceDefaults", "backend\WebServiceDefaults\WebServiceDefaults.csproj", "{9B71BEF9-6017-4E30-81E0-EB8126B2CF02}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FwLiteMaui.Tests", "backend\FwLite\FwLiteMaui.Tests\FwLiteMaui.Tests.csproj", "{5A277FCE-454F-4956-8C33-7D9726C4E409}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -157,6 +160,10 @@ Global {9B71BEF9-6017-4E30-81E0-EB8126B2CF02}.Debug|Any CPU.Build.0 = Debug|Any CPU {9B71BEF9-6017-4E30-81E0-EB8126B2CF02}.Release|Any CPU.ActiveCfg = Release|Any CPU {9B71BEF9-6017-4E30-81E0-EB8126B2CF02}.Release|Any CPU.Build.0 = Release|Any CPU + {5A277FCE-454F-4956-8C33-7D9726C4E409}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5A277FCE-454F-4956-8C33-7D9726C4E409}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5A277FCE-454F-4956-8C33-7D9726C4E409}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5A277FCE-454F-4956-8C33-7D9726C4E409}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -178,6 +185,7 @@ Global {00AE5440-0E36-4488-935B-5B11301BA57D} = {7B6E21C4-5AF4-4505-B7D9-59A3886C5090} {ECBA46AB-AF87-4D4D-9716-FD77264B817F} = {7B6E21C4-5AF4-4505-B7D9-59A3886C5090} {73DC604C-C501-410D-B56B-0544AD6EF1C2} = {7B6E21C4-5AF4-4505-B7D9-59A3886C5090} + {5A277FCE-454F-4956-8C33-7D9726C4E409} = {7B6E21C4-5AF4-4505-B7D9-59A3886C5090} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {440AE83C-6DB0-4F18-B2C1-BCD33F0645B6} diff --git a/backend/FwLite/FwLiteMaui.Tests/AutoUpdateTests.cs b/backend/FwLite/FwLiteMaui.Tests/AutoUpdateTests.cs new file mode 100644 index 0000000000..70a1230ab9 --- /dev/null +++ b/backend/FwLite/FwLiteMaui.Tests/AutoUpdateTests.cs @@ -0,0 +1,36 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; +using Moq; + +namespace FwLiteMaui.Tests; + +using FwLiteMaui; +#if WINDOWS +public class AutoUpdateTests +{ + private readonly AppUpdateService _appUpdateService; + + public AutoUpdateTests() + { + var services = new ServiceCollection() + .AddFwLiteMauiServices(new ConfigurationManager(), Mock.Of()) + .AddSingleton(Mock.Of()) + .AddSingleton(Mock.Of()) + .AddSingleton() + .BuildServiceProvider(); + _appUpdateService = services.GetRequiredService(); + } + + [Theory] + [InlineData(1, false)] + [InlineData(15, false)] + [InlineData(22, true)] + [InlineData(26, true)] + [InlineData(36, true)] + [InlineData(46, true)] + public void ShouldCheckForUpdateAfterThreshold(int hoursInThefuture, bool shouldCheckForUpdate) + { + + } +} +#endif diff --git a/backend/FwLite/FwLiteMaui.Tests/FwLiteMaui.Tests.csproj b/backend/FwLite/FwLiteMaui.Tests/FwLiteMaui.Tests.csproj new file mode 100644 index 0000000000..98d470b170 --- /dev/null +++ b/backend/FwLite/FwLiteMaui.Tests/FwLiteMaui.Tests.csproj @@ -0,0 +1,41 @@ + + + + false + true + + + net9.0-android;net9.0-ios;net9.0-maccatalyst + $(TargetFrameworks);net9.0-windows10.0.19041.0 + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + + diff --git a/backend/FwLite/FwLiteMaui/FwLiteMaui.csproj b/backend/FwLite/FwLiteMaui/FwLiteMaui.csproj index 1e0308a51e..51c3a985c4 100644 --- a/backend/FwLite/FwLiteMaui/FwLiteMaui.csproj +++ b/backend/FwLite/FwLiteMaui/FwLiteMaui.csproj @@ -83,4 +83,9 @@ + + + + + diff --git a/backend/FwLite/FwLiteMaui/FwLiteMauiKernel.cs b/backend/FwLite/FwLiteMaui/FwLiteMauiKernel.cs index 3efffeb309..9ecdb8a53f 100644 --- a/backend/FwLite/FwLiteMaui/FwLiteMauiKernel.cs +++ b/backend/FwLite/FwLiteMaui/FwLiteMauiKernel.cs @@ -16,7 +16,7 @@ namespace FwLiteMaui; public static class FwLiteMauiKernel { - public static void AddFwLiteMauiServices(this IServiceCollection services, + public static IServiceCollection AddFwLiteMauiServices(this IServiceCollection services, ConfigurationManager configuration, ILoggingBuilder logging) { @@ -116,14 +116,17 @@ public static void AddFwLiteMauiServices(this IServiceCollection services, }); logging.AddFile(fwLiteMauiConfig.AppLogFilePath); - services.AddSingleton(Preferences.Default); - services.AddSingleton(VersionTracking.Default); - services.AddSingleton(Connectivity.Current); + //using callback otherwise tests try to evaluate the default/current property during setup. + //by using a callback, we can delay the evaluation until after the test setup, which lets us mock the service + services.AddSingleton(_ => Preferences.Default); + services.AddSingleton(_ => VersionTracking.Default); + services.AddSingleton(_ => Connectivity.Current); services.AddSingleton(); logging.AddConsole(); #if DEBUG logging.AddDebug(); #endif + return services; } #if WINDOWS diff --git a/backend/FwLite/FwLiteMaui/Platforms/Windows/AppUpdateService.cs b/backend/FwLite/FwLiteMaui/Platforms/Windows/AppUpdateService.cs index 6931fce33c..250b3c9549 100644 --- a/backend/FwLite/FwLiteMaui/Platforms/Windows/AppUpdateService.cs +++ b/backend/FwLite/FwLiteMaui/Platforms/Windows/AppUpdateService.cs @@ -199,7 +199,7 @@ private async Task ShouldUpdate() } } - private bool ShouldCheckForUpdate() + internal bool ShouldCheckForUpdate() { if (ValidPositiveEnvVarValues.Contains(Environment.GetEnvironmentVariable(ForceUpdateCheckEnvVar) ?? "")) {