using Microsoft.Extensions.DependencyInjection; using NSubstitute; using NSubstitute.Extensions; using Semver; using StabilityMatrix.Avalonia; using StabilityMatrix.Avalonia.ViewModels.Dialogs; using StabilityMatrix.Core.Helper; using StabilityMatrix.Core.Models.Update; using StabilityMatrix.Core.Services; using StabilityMatrix.Core.Updater; using StabilityMatrix.UITests; [assembly: AvaloniaTestApplication(typeof(TestAppBuilder))] namespace StabilityMatrix.UITests; public static class TestAppBuilder { public static AppBuilder BuildAvaloniaApp() { ConfigureGlobals(); Program.SetupAvaloniaApp(); App.BeforeBuildServiceProvider += (_, x) => ConfigureAppServices(x); return AppBuilder .Configure() .UseSkia() .UseHeadless(new AvaloniaHeadlessPlatformOptions { UseHeadlessDrawing = false }); } private static void ConfigureGlobals() { var tempDir = TempDirFixture.ModuleTempDir; var globalSettings = Path.Combine(tempDir, "AppDataHome"); Compat.SetAppDataHome(globalSettings); } private static void ConfigureAppServices(IServiceCollection serviceCollection) { // ISettingsManager var settingsManager = Substitute.ForPartsOf(); serviceCollection.AddSingleton(settingsManager); // IUpdateHelper var mockUpdateInfo = new UpdateInfo( SemVersion.Parse("2.999.0"), DateTimeOffset.UnixEpoch, UpdateChannel.Stable, UpdateType.Normal, "https://example.org", "https://example.org", "46e11a5216c55d4c9d3c54385f62f3e1022537ae191615237f05e06d6f8690d0", "IX5/CCXWJQG0oGkYWVnuF34gTqF/dJSrDrUd6fuNMYnncL39G3HSvkXrjvJvR18MA2rQNB5z13h3/qBSf9c7DA==" ); var updateHelper = Substitute.For(); updateHelper .Configure() .StartCheckingForUpdates() .Returns(Task.CompletedTask) .AndDoes(_ => EventManager.Instance.OnUpdateAvailable(mockUpdateInfo)); serviceCollection.AddSingleton(updateHelper); // UpdateViewModel var updateViewModel = Substitute.ForPartsOf( settingsManager, null, updateHelper ); updateViewModel.Configure().GetReleaseNotes("").Returns("Test"); serviceCollection.AddSingleton(updateViewModel); } }