public void Dispose() { _host.Dispose(); _host = null; _app.Dispose(); _app = null; }
public void CanGetServices() { var app = new AppStub(); app.CreateBuilder().Build(app); Assert.NotNull(app.Services); }
public void CanGetStaticServices() { var app = new AppStub(); app.CreateBuilder().Build(app); Assert.NotNull(MauiApp.Current.Services); Assert.Equal(app.Services, MauiApp.Current.Services); }
public void CanGetStaticApp() { var app = new AppStub(); app.CreateBuilder().Build(app); Assert.NotNull(MauiApp.Current); Assert.Equal(MauiApp.Current, app); }
public void HandlerContextNullBeforeBuild() { var app = new AppStub(); app.CreateBuilder(); var handlerContext = MauiApp.Current.Context; Assert.Null(handlerContext); }
public void WillRetrieveSameSingletonServices() { var app = new AppStub(); app.CreateBuilder() .ConfigureServices((ctx, services) => services.AddSingleton <IFooService, FooService>()) .Build(app); AssertSingleton <IFooService, FooService>(app); }
public void WillRetrieveDifferentTransientServices() { var app = new AppStub(); app.CreateBuilder() .ConfigureServices((ctx, services) => services.AddTransient <IFooService, FooService>()) .Build(app); AssertTransient <IFooService, FooService>(app); }
public void HandlerContextAfterBuild() { var app = new AppStub(); app.CreateBuilder().Build(app); var handlerContext = MauiApp.Current.Context; Assert.NotNull(handlerContext); }
public void CanHandlerProviderContext() { var app = new AppStub(); app.CreateBuilder().Build(app); var handlerContext = MauiApp.Current.Context; Assert.IsAssignableFrom <IMauiHandlersServiceProvider>(handlerContext.Handlers); }
public HandlerTestFixture() { _app = new AppStub(); _host = _app .CreateBuilder() .ConfigureFonts((ctx, fonts) => { fonts.AddFont("dokdo_regular.ttf", "Dokdo"); }) .Build(_app); }
public void DefaultHandlersAreRegistered() { var app = new AppStub(); app.CreateBuilder().Build(app); var handler = MauiApp.Current.Context.Handlers.GetHandler(typeof(IButton)); Assert.NotNull(handler); Assert.IsType <ButtonHandler>(handler); }
public void CanRegisterAndGetHandler() { var app = new AppStub(); app.CreateBuilder() .RegisterHandler <IViewStub, ViewHandlerStub>() .Build(app); var handler = MauiApp.Current.Context.Handlers.GetHandler(typeof(IViewStub)); Assert.NotNull(handler); Assert.IsType <ViewHandlerStub>(handler); }
static void AssertSingleton <TInterface, TConcrete>(AppStub app) { var service1 = app.Services.GetService <TInterface>(); Assert.NotNull(service1); Assert.IsType <TConcrete>(service1); var service2 = app.Services.GetService <TInterface>(); Assert.NotNull(service2); Assert.IsType <TConcrete>(service2); Assert.Equal(service1, service2); }
public void WillRetrieveMixedServices() { var app = new AppStub(); app.CreateBuilder() .ConfigureServices((ctx, services) => { services.AddSingleton <IFooService, FooService>(); services.AddTransient <IBarService, BarService>(); }) .Build(app); AssertSingleton <IFooService, FooService>(app); AssertTransient <IBarService, BarService>(app); }
public HandlerTestFixture() { _app = new AppStub(); _context = new ContextStub(_app); _host = _app .CreateBuilder() .ConfigureFonts((ctx, fonts) => { fonts.AddFont("dokdo_regular.ttf", "Dokdo"); }) .ConfigureServices((ctx, services) => { services.AddSingleton(_context); }) .Build(_app); }
public void CanRegisterAndGetHandlerWithDictionary() { var app = new AppStub(); app.CreateBuilder() .RegisterHandlers(new Dictionary <Type, Type> { { typeof(IViewStub), typeof(ViewHandlerStub) } }) .Build(app); var handler = MauiApp.Current.Context.Handlers.GetHandler(typeof(IViewStub)); Assert.NotNull(handler); Assert.IsType <ViewHandlerStub>(handler); }
public void CanSpecifyHandler() { var app = new AppStub(); app.CreateBuilder() .RegisterHandler <ButtonStub, ButtonHandlerStub>() .Build(app); var defaultHandler = MauiApp.Current.Context.Handlers.GetHandler(typeof(IButton)); var specificHandler = MauiApp.Current.Context.Handlers.GetHandler(typeof(ButtonStub)); Assert.NotNull(defaultHandler); Assert.NotNull(specificHandler); Assert.IsType <ButtonHandler>(defaultHandler); Assert.IsType <ButtonHandlerStub>(specificHandler); }
public void ShouldntCreateMultipleApp() { var app = new AppStub(); Assert.Throws <InvalidOperationException>(() => new AppStub()); }