Пример #1
0
        public async Task LaunchApplication()
        {
            // The App class does this work in the actual client
            // including initializing the singleton-lifestyle LoginWorkflowController with Navigation
            // (see QTB3.Client.LabResultPatterns.Common/App.xaml.cs)

            // We overload the DI to
            // -- set up a test HttpClient to be used by the client application service
            // -- set up in-memory test services that runs the read and write services
            // -- set up a TestLrpNavigator that runs the page lifecycle OnAppearing calls
            //
            // Note that the ASP.NET Startup used for in this testbench alters
            // -- the rest basepath,
            // -- authorization
            //        -- use local JWT token generation rather than Azure AD B2C
            //        -- for now, bypass gathering credentials and just issue token
            // -- uses the in-memory Sqlite dB

            var builder = new ContainerBuilder();

            builder.RegisterModule <MainModule>();
            builder.RegisterModule <Services2Module>();
            builder.RegisterModule <TestFactorsModule>();
            var container = builder.Build();

            // the test token manager can be induced to ask for relogin as if the token has expired
            _jwtTokenManager = container.Resolve <IJwtTokenManager>() as TestJwtTokenManager;

            // get the MainPage from the container
            // and wrap it in a NavigationPage, just as the App does...
            _mainPage = container.Resolve <IMainPage>() as MainPage;
            var navMainPage = new NavigationPage(_mainPage);

            // assign the navigation proxy
            Navigation = new TestLrpNavigation(_mainPage.Navigation);

            _loginPageController = container.Resolve <ILoginPageController>
                                   (
                new NamedParameter("navigation", Navigation),
                new NamedParameter("mainPage", _mainPage)
                                   );

            var mainPageViewModel = container.Resolve <IMainPageViewModel>
                                    (
                new NamedParameter("pageTitle", LrpConstants.MainPageTitle)
                                    );

            _mainPage.BindingContext = mainPageViewModel;
            _mainPageController      = container.Resolve <IMainPageController>
                                       (
                new NamedParameter("mainPage", _mainPage),
                new NamedParameter("mainPageViewModel", mainPageViewModel),
                new NamedParameter("navigation", Navigation)
                                       );

            // launch the main page
            await _mainPage.OnAppearingAsync();
        }
Пример #2
0
        public App()
        {
            InitializeComponent();

            var builder = new ContainerBuilder();

            builder.RegisterModule <MainModule>();
            builder.RegisterModule <Services2Module>();
            builder.RegisterModule <LrpFactorsModule>();
            var container = builder.Build();

            // all of the following components are Autofac app-lifetime scope

            _tokenManager = container.Resolve <IJwtTokenManager>();

            var mp = container.Resolve <IMainPage>();

            MainPage = new NavigationPage(mp as ContentPage);

            var lrpNavigation = new LrpNavigation(MainPage.Navigation);

            // By passing the mainPage to the LoginPageController
            // before passing it to the MainPageController,
            // we ensure that the subscriptions to MainPage's
            // OnAppearingCalledEvent gives priority to the LoginPageController;
            _loginPageController = container.Resolve <ILoginPageController>
                                   (
                new NamedParameter("navigation", lrpNavigation),
                new NamedParameter("mainPage", mp)
                                   );

            var mainPageViewModel = container.Resolve <IMainPageViewModel>
                                    (
                new NamedParameter("pageTitle", LrpConstants.MainPageTitle)
                                    );

            mp.BindingContext   = mainPageViewModel;
            _mainPageController = container.Resolve <IMainPageController>
                                  (
                new NamedParameter("mainPage", mp),
                new NamedParameter("mainPageViewModel", mainPageViewModel),
                new NamedParameter("navigation", lrpNavigation)
                                  );
        }