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

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

            app.CreateBuilder().Build(app);

            Assert.NotNull(app.Services);
        }
示例#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);
        }
示例#4
0
        public void CanGetStaticApp()
        {
            var app = new AppStub();

            app.CreateBuilder().Build(app);

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

            app.CreateBuilder();

            var handlerContext = MauiApp.Current.Context;

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

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

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

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

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

            app.CreateBuilder().Build(app);

            var handlerContext = MauiApp.Current.Context;

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

            app.CreateBuilder().Build(app);

            var handlerContext = MauiApp.Current.Context;

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

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