public static MauiApp CreateMauiApp() { var appBuilder = MauiApp.CreateBuilder(); appBuilder .ConfigureLifecycleEvents(life => { #if __ANDROID__ life.AddAndroid(android => { android.OnCreate((a, b) => Platform.Init(a)); }); #endif }) .ConfigureTests(new TestOptions { Assemblies = { typeof(MauiProgram).Assembly }, }) .UseHeadlessRunner(new HeadlessRunnerOptions { RequiresUIContext = true, }) .UseVisualRunner(); return(appBuilder.Build()); }
public static MauiApp CreateMauiApp() { var appBuilder = MauiApp.CreateBuilder(); #if WINDOWS Microsoft.Maui.Essentials.Platform.MapServiceToken = "RJHqIE53Onrqons5CNOx~FrDr3XhjDTyEXEjng-CRoA~Aj69MhNManYUKxo6QcwZ0wmXBtyva0zwuHB04rFYAPf7qqGJ5cHb03RCDw1jIW8l"; #endif appBuilder .ConfigureLifecycleEvents(lifecycle => { #if __IOS__ lifecycle .AddiOS(iOS => iOS .OpenUrl((app, url, options) => Microsoft.Maui.Essentials.Platform.OpenUrl(app, url, options)) .ContinueUserActivity((application, userActivity, completionHandler) => Microsoft.Maui.Essentials.Platform.ContinueUserActivity(application, userActivity, completionHandler)) .PerformActionForShortcutItem((application, shortcutItem, completionHandler) => Microsoft.Maui.Essentials.Platform.PerformActionForShortcutItem(application, shortcutItem, completionHandler))); #elif WINDOWS lifecycle .AddWindows(windows => windows .OnLaunched((app, e) => Microsoft.Maui.Essentials.Platform.OnLaunched(e))); #endif }) .UseMauiApp <App>(); return(appBuilder.Build()); }
public static MauiAppBuilder CreateMauiAppBuilder() { var builder = MauiApp.CreateBuilder(); builder .UseMauiApp <App>() .ConfigureMauiHandlers(handlers => { handlers.AddCompatibilityRenderers(AppDomain.CurrentDomain.GetAssemblies()); }) .ConfigureImageSources(sources => { sources.AddCompatibilityServices(AppDomain.CurrentDomain.GetAssemblies()); }) .ConfigureFonts(fonts => { fonts.AddCompatibilityFonts(new FontRegistrar(new EmbeddedFontLoader()), AppDomain.CurrentDomain.GetAssemblies()); }) .ConfigureEffects(effects => { effects.AddCompatibilityEffects(AppDomain.CurrentDomain.GetAssemblies()); }); DependencyService.Register(AppDomain.CurrentDomain.GetAssemblies()); return(builder); }
public void ConfigureAppConfigurationOverwritesValues() { var builder = MauiApp.CreateBuilder(); builder.Host .ConfigureAppConfiguration((_, builder) => { builder.AddInMemoryCollection(new Dictionary <string, string> { { "key 1", "value 1" }, { "key 2", "value 2" }, }); }) .ConfigureAppConfiguration((_, builder) => { builder.AddInMemoryCollection(new Dictionary <string, string> { { "key 1", "value a" }, }); }); var mauiApp = builder.Build(); var configuration = mauiApp.Services.GetRequiredService <IConfiguration>(); Assert.Equal("value a", configuration["key 1"]); Assert.Equal("value 2", configuration["key 2"]); }
IMauiContext GetContext() { return(new ContextStub(MauiApp .CreateBuilder() .Build() .Services)); }
public static MauiApp CreateMauiApp() { var builder = MauiApp.CreateBuilder(); builder .UseMauiApp <App>() .ConfigureFonts(fonts => { fonts.AddFont("Comfortaa/Comfortaa-VariableFont_wght.ttf", "Comfortaa"); fonts.AddFont("Akshar/Akshar-VariableFont_wght.ttf", "Akshar"); }); builder.Services.AddMauiBlazorWebView(); builder.Services.AddAuthorizationCore(); builder.Services.AddSingleton <MessageService>(); builder.Services.AddScoped <ApiAuthenticationStateProvider>(); builder.Services.AddScoped <AuthenticationStateProvider>(s => s.GetRequiredService <ApiAuthenticationStateProvider>()); builder.Services.AddScoped <IAuthService, AuthService>(); builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("https://lastweek.triggan.com") }); #if DEBUG builder.Services.AddBlazorWebViewDeveloperTools(); #endif return(builder.Build()); }
public static MauiAppBuilder CreateMauiAppBuilder() { #if !BlazorHybrid throw new InvalidOperationException("Please switch to blazor hybrid as described in readme.md"); #endif var builder = MauiApp.CreateBuilder(); var assembly = typeof(MauiProgram).GetTypeInfo().Assembly; builder .UseMauiApp <App>() .Configuration.AddJsonFile(new EmbeddedFileProvider(assembly), "appsettings.json", optional: false, false); var services = builder.Services; services.AddMauiBlazorWebView(); #if DEBUG services.AddBlazorWebViewDeveloperTools(); #endif services.AddTransient <IAuthTokenProvider, ClientSideAuthTokenProvider>(); services.AddTodoTemplateSharedServices(); services.AddTodoTemplateAppServices(); return(builder); }
public static MauiApp CreateMauiApp() { var x = MauiApp.CreateBuilder(); x.ConfigureLifecycleEvents(life => { #if ANDROID life.AddAndroid(android => { android.OnCreate((a, b) => CurrentContext = a); }); #elif WINDOWS life.AddWindows(windows => { windows.OnWindowCreated((w) => DefaultWindow = w); }); #endif }); x.ConfigureTests(new TestOptions { Assemblies = { typeof(MauiProgram).Assembly }, }) .UseHeadlessRunner(new HeadlessRunnerOptions { RequiresUIContext = true, }) .UseVisualRunner(); return(x.Build()); }
public static MauiApp CreateMauiApp() { var builder = MauiApp.CreateBuilder(); builder .RegisterBlazorMauiWebView() .UseMauiApp <App>(); builder.Services.AddBlazorWebView(); builder.Services.AddHttpClient <PodcastService>(client => { client.BaseAddress = new Uri(APIUrl); }); builder.Services.AddScoped <ThemeInterop>(); builder.Services.AddScoped <AudioInterop>(); builder.Services.AddScoped <LocalStorageInterop>(); builder.Services.AddScoped <ClipboardInterop>(); builder.Services.AddScoped <SubscriptionsService>(); builder.Services.AddScoped <ListenLaterService>(); builder.Services.AddSingleton <PlayerService>(); builder.Services.AddScoped <ListenTogetherHubClient>(_ => new ListenTogetherHubClient(ListenTogetherUrl)); builder.Services.AddScoped <ComponentStatePersistenceManager>(); builder.Services.AddScoped <PersistentComponentState>(sp => sp.GetRequiredService <ComponentStatePersistenceManager>().State); return(builder.Build()); }
public void ConfigureFontsRegistersFonts(string filename, string alias) { var root = Path.Combine(Path.GetTempPath(), "Microsoft.Maui.UnitTests", "ConfigureFontsRegistersFonts", Guid.NewGuid().ToString()); var builder = MauiApp .CreateBuilder() .ConfigureFonts(fonts => fonts.AddEmbeddedResourceFont(GetType().Assembly, filename, alias)); builder.Services.AddSingleton <IEmbeddedFontLoader>(_ => new FileSystemEmbeddedFontLoader(root)); var mauiApp = builder.Build(); var registrar = mauiApp.Services.GetRequiredService <IFontRegistrar>(); var path = registrar.GetFont(filename); Assert.NotNull(path); Assert.StartsWith(root, path); if (alias != null) { path = registrar.GetFont(alias); Assert.NotNull(path); Assert.StartsWith(root, path); } Assert.True(File.Exists(Path.Combine(root, filename))); Directory.Delete(root, true); }
public static MauiApp CreateMauiApp() => MauiApp .CreateBuilder() .ConfigureLifecycleEvents(life => { #if __ANDROID__ life.AddAndroid(android => { android.OnCreate((a, b) => CurrentContext = a); }); #endif }) .ConfigureTests(new TestOptions { Assemblies = { typeof(MauiProgram).Assembly }, }) .UseHeadlessRunner(new HeadlessRunnerOptions { RequiresUIContext = true, }) .UseVisualRunner() .Build();
public async Task GetDrawableAsyncWithCustomFont() { var mauiApp = MauiApp.CreateBuilder() .ConfigureFonts(fonts => { fonts.AddFont("dokdo_regular.ttf", "Dokdo"); }) .ConfigureImageSources() .Build(); var images = mauiApp.Services.GetRequiredService <IImageSourceServiceProvider>(); var service = images.GetRequiredImageSourceService <FontImageSourceStub>(); var imageSource = new FontImageSourceStub { Glyph = "X", Font = Font.OfSize("Dokdo", 24), Color = Colors.Red, }; using var result = await service.GetDrawableAsync(imageSource, MauiProgram.DefaultContext); var bitmapDrawable = Assert.IsType <BitmapDrawable>(result.Value); var bitmap = bitmapDrawable.Bitmap; bitmap.AssertContainsColor(Colors.Red.ToPlatform()); }
public static MauiAppBuilder CreateMauiAppBuilder() { var builder = MauiApp.CreateBuilder(); builder .UseMauiApp <App>() .UseMauiCompatibility() .ConfigureMauiHandlers(handlers => { handlers.AddCompatibilityRenderers(AppDomain.CurrentDomain.GetAssemblies()); }) .ConfigureImageSources(sources => { sources.AddCompatibilityServices(AppDomain.CurrentDomain.GetAssemblies()); }) .ConfigureFonts(fonts => { fonts.AddCompatibilityFonts(new FontRegistrar(new EmbeddedFontLoader()), AppDomain.CurrentDomain.GetAssemblies()); }) .ConfigureEffects(effects => { effects.AddCompatibilityEffects(AppDomain.CurrentDomain.GetAssemblies()); }); if (DeviceInfo.Platform == DevicePlatform.Tizen) { //Some controls still need to use legacy renderers on Tizen. builder.UseMauiCompatibility(); } DependencyService.Register(AppDomain.CurrentDomain.GetAssemblies()); return(builder); }
public static MauiAppBuilder CreateMauiAppBuilder() { var builder = MauiApp.CreateBuilder(); builder .UseMauiApp <App>() .ConfigureMauiHandlers(handlers => { handlers.AddCompatibilityRenderers(Device.GetAssemblies()); }) .ConfigureImageSources(sources => { sources.AddCompatibilityServices(Device.GetAssemblies()); }) .ConfigureFonts(fonts => { fonts.AddCompatibilityFonts(Device.GetAssemblies()); }) .ConfigureEffects(effects => { effects.AddCompatibilityEffects(Device.GetAssemblies()); }); DependencyService.Register(Device.GetAssemblies()); return(builder); }
public void CanBuildAHost() { var mauiApp = MauiApp.CreateBuilder() .Build(); Assert.NotNull(mauiApp.Services); }
public async Task GetDrawableAsync(string colorHex) { var expectedColor = Color.FromArgb(colorHex); var mauiApp = MauiApp.CreateBuilder() .ConfigureFonts() .ConfigureImageSources() .Build(); var images = mauiApp.Services.GetRequiredService <IImageSourceServiceProvider>(); var service = images.GetRequiredImageSourceService <FontImageSourceStub>(); var imageSource = new FontImageSourceStub { Glyph = "X", Font = Font.Default, Color = expectedColor, }; using var result = await service.GetDrawableAsync(imageSource, MauiProgram.DefaultContext); var bitmapDrawable = Assert.IsType <BitmapDrawable>(result.Value); var bitmap = bitmapDrawable.Bitmap; bitmap.AssertContainsColor(expectedColor.ToPlatform()); }
public static MauiApp CreateMauiApp() { var builder = MauiApp.CreateBuilder(); builder .UseMauiApp <App>() .UseSkiaSharp() .ConfigureFonts(fonts => { fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); fonts.AddFont("OriginTech-Regular.ttf", "OriginTechRegular"); }); var services = builder.Services; services.AddTransient <IAlertMessage, AlertMessage>(); services.AddTransient <BluetoothController>(); services.AddTransient <App>(); services.AddTransient <MainView>(); services.AddTransient <MainViewModel>(); return(builder.Build()); }
public void MultipleServicesAreRegisteredWithoutBuilder() { var builder = MauiApp.CreateBuilder(); builder.Services.AddSingleton(new MappingService("key 1", "value 1")); builder.Services.AddSingleton(new MappingService("key 2", "value 2")); var mauiApp = builder.Build(); var mappingServices = mauiApp.Services.GetServices <MappingService>().ToArray(); Assert.Equal(2, mappingServices.Length); Assert.NotEqual(mappingServices[0], mappingServices[1]); Assert.Equal(new[] { "value 1" }, Get("key 1")); Assert.Equal(new[] { "value 2" }, Get("key 2")); Assert.Empty(Get("key 3")); IEnumerable <string> Get(string key) { foreach (var service in mappingServices) { foreach (var value in service.Get(key)) { yield return(value); } } } }
public void CompatibilityExtensionsWorkUseCompatibility(bool useCompatibility) { MauiAppBuilderExtensions.ResetCompatibilityCheck(); bool handlersCalled = false; var builder = MauiApp.CreateBuilder().UseMauiApp <ApplicationStub>(); if (useCompatibility) { builder = builder.UseMauiCompatibility(); } var mauiApp = builder.ConfigureMauiHandlers(collection => { handlersCalled = true; if (useCompatibility) { collection.AddCompatibilityRenderer(typeof(Object), typeof(Object)); } else { Assert.Throws <InvalidOperationException>(() => collection.AddCompatibilityRenderer(typeof(Object), typeof(Object)) ); } }) .Build(); _ = mauiApp.Services.GetRequiredService <IMauiHandlersFactory>(); Assert.True(handlersCalled); }
public HandlerTestBase() { var appBuilder = MauiApp .CreateBuilder() .ConfigureMauiHandlers(handlers => { handlers.AddHandler(typeof(ButtonWithContainerStub), typeof(ButtonWithContainerStubHandler)); handlers.AddHandler(typeof(SliderStub), typeof(SliderHandler)); handlers.AddHandler(typeof(ButtonStub), typeof(ButtonHandler)); handlers.AddHandler(typeof(ElementStub), typeof(ElementHandlerStub)); }) .ConfigureImageSources(services => { services.AddService <ICountedImageSourceStub, CountedImageSourceServiceStub>(); }) .ConfigureFonts(fonts => { fonts.AddFont("dokdo_regular.ttf", "Dokdo"); fonts.AddFont("LobsterTwo-Regular.ttf", "Lobster Two"); fonts.AddFont("LobsterTwo-Bold.ttf", "Lobster Two Bold"); fonts.AddFont("LobsterTwo-Italic.ttf", "Lobster Two Italic"); fonts.AddFont("LobsterTwo-BoldItalic.ttf", "Lobster Two BoldItalic"); }); _mauiApp = appBuilder.Build(); _servicesProvider = _mauiApp.Services; _app = new ApplicationStub(); _context = new ContextStub(_servicesProvider); }
public void CanGetServices() { var builder = MauiApp.CreateBuilder(); var mauiApp = builder.Build(); Assert.NotNull(mauiApp.Services); }
public static MauiApp CreateMauiApp() { var builder = MauiApp.CreateBuilder(); builder .RegisterBlazorMauiWebView() .UseMauiApp <App>() .ConfigureFonts(fonts => { fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); }); builder.Services.AddBlazorWebView(); builder.Services.AddBlazorWeather("https://minimalweather20210428173256.azurewebsites.net/"); #if WINDOWS builder.Services.AddSingleton <ITrayService, WinUI.TrayService>(); builder.Services.AddSingleton <INotificationService, WinUI.NotificationService>(); #elif MACCATALYST builder.Services.AddSingleton <ITrayService, MacCatalyst.TrayService>(); builder.Services.AddSingleton <INotificationService, MacCatalyst.NotificationService>(); #endif return(builder.Build()); }
public async Task GetImageAsync(string colorHex) { var expectedColor = Color.FromArgb(colorHex); var mauiApp = MauiApp.CreateBuilder() .ConfigureFonts() .ConfigureImageSources() .Build(); var images = mauiApp.Services.GetRequiredService <IImageSourceServiceProvider>(); var service = images.GetRequiredImageSourceService <FontImageSourceStub>(); var imageSource = new FontImageSourceStub { Glyph = "X", Font = Font.Default.WithSize(30), Color = expectedColor, }; using var drawable = await InvokeOnMainThreadAsync(() => service.GetImageAsync(imageSource)); var uiimage = Assert.IsType <UIImage>(drawable.Value); uiimage.AssertContainsColor(expectedColor.ToNative()); }
public async Task GetImageAsyncWithCustomFont() { var mauiApp = MauiApp.CreateBuilder() .ConfigureFonts(fonts => { fonts.AddFont("dokdo_regular.ttf", "Dokdo"); }) .ConfigureImageSources() .Build(); var images = mauiApp.Services.GetRequiredService <IImageSourceServiceProvider>(); var service = images.GetRequiredImageSourceService <FontImageSourceStub>(); var imageSource = new FontImageSourceStub { Glyph = "X", Font = Font.OfSize("Dokdo", 24), Color = Colors.Red, }; using var drawable = await InvokeOnMainThreadAsync(() => service.GetImageAsync(imageSource)); var uiimage = Assert.IsType <UIImage>(drawable.Value); uiimage.AssertContainsColor(Colors.Red.ToNative()); }
public static MauiApp CreateMauiApp() { var builder = MauiApp.CreateBuilder(); builder .RegisterBlazorMauiWebView() .UseMauiApp <App>() .ConfigureFonts(fonts => { fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); }); builder.Services.AddBlazorWebView().ConfigureDI(); #if WINDOWS builder.Services.AddSingleton <ITrayService, WinUI.TrayService>(); builder.Services.AddSingleton <INotificationService, WinUI.NotificationService>(); #elif MACCATALYST builder.Services.AddSingleton <ITrayService, MacCatalyst.TrayService>(); builder.Services.AddSingleton <INotificationService, MacCatalyst.NotificationService>(); #endif System.Net.ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; return(builder.Build()); }
public void CreatesServiceProviderByDefault() { var builder = MauiApp.CreateBuilder(); var mauiApp = builder.Build(); Assert.IsType <ServiceProvider>(mauiApp.Services); }
public void NullAliasForEmbeddedFontDoesNotThrow() { var builder = MauiApp .CreateBuilder() .ConfigureFonts(fonts => fonts.AddEmbeddedResourceFont(GetType().Assembly, "test.ttf", null)); _ = builder.Build(); }
public static MauiApp CreateMauiApp() { var builder = MauiApp.CreateBuilder(); builder.UseMauiApp <App>(); return(builder.Build()); }
public MauiContextTests() { _mauiApp = MauiApp .CreateBuilder() .Build(); _mauiContext = new MauiContext(_mauiApp.Services, Platform.DefaultContext); }
public void WillRetrieveSameSingletonServices() { var builder = MauiApp.CreateBuilder(); builder.Services.AddSingleton <IFooService, FooService>(); var mauiApp = builder.Build(); AssertSingleton <IFooService, FooService>(mauiApp.Services); }