Example #1
0
        public void Dispose()
        {
            _host.Dispose();
            _host = null;

            _app.Dispose();
            _app = null;
        }
Example #2
0
        public void CanGetServices()
        {
            var app = new AppStub();

            app.CreateBuilder().Build(app);

            Assert.NotNull(app.Services);
        }
Example #3
0
        public void CanGetStaticServices()
        {
            var app = new AppStub();

            app.CreateBuilder().Build(app);

            Assert.NotNull(MauiApp.Current.Services);
            Assert.Equal(app.Services, MauiApp.Current.Services);
        }
Example #4
0
        public void CanGetStaticApp()
        {
            var app = new AppStub();

            app.CreateBuilder().Build(app);

            Assert.NotNull(MauiApp.Current);
            Assert.Equal(MauiApp.Current, app);
        }
Example #5
0
        public void HandlerContextNullBeforeBuild()
        {
            var app = new AppStub();

            app.CreateBuilder();

            var handlerContext = MauiApp.Current.Context;

            Assert.Null(handlerContext);
        }
Example #6
0
        public void WillRetrieveSameSingletonServices()
        {
            var app = new AppStub();

            app.CreateBuilder()
            .ConfigureServices((ctx, services) => services.AddSingleton <IFooService, FooService>())
            .Build(app);

            AssertSingleton <IFooService, FooService>(app);
        }
Example #7
0
        public void WillRetrieveDifferentTransientServices()
        {
            var app = new AppStub();

            app.CreateBuilder()
            .ConfigureServices((ctx, services) => services.AddTransient <IFooService, FooService>())
            .Build(app);

            AssertTransient <IFooService, FooService>(app);
        }
Example #8
0
        public void HandlerContextAfterBuild()
        {
            var app = new AppStub();

            app.CreateBuilder().Build(app);

            var handlerContext = MauiApp.Current.Context;

            Assert.NotNull(handlerContext);
        }
Example #9
0
        public void CanHandlerProviderContext()
        {
            var app = new AppStub();

            app.CreateBuilder().Build(app);

            var handlerContext = MauiApp.Current.Context;

            Assert.IsAssignableFrom <IMauiHandlersServiceProvider>(handlerContext.Handlers);
        }
Example #10
0
 public HandlerTestFixture()
 {
     _app  = new AppStub();
     _host = _app
             .CreateBuilder()
             .ConfigureFonts((ctx, fonts) =>
     {
         fonts.AddFont("dokdo_regular.ttf", "Dokdo");
     })
             .Build(_app);
 }
Example #11
0
        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);
        }
Example #12
0
        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);
        }
Example #13
0
        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);
        }
Example #14
0
        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);
        }
Example #15
0
 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);
 }
Example #16
0
        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);
        }
Example #17
0
        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);
        }
Example #18
0
        public void ShouldntCreateMultipleApp()
        {
            var app = new AppStub();

            Assert.Throws <InvalidOperationException>(() => new AppStub());
        }