Esempio n. 1
0
        public Task SwitchToAnotherAppPackage()
        {
            var assemblyService = DependencyService.Get <IAssemblyService>();

            //For ApplicationStore test, trying to Add alternate project package to the Store
            //Then we load it and wait 5 seconds
            //Then we load the regular app
            //Then we remove the alternate project from disk

            string regularApp   = "Package.BlazorMobile.InteropBlazorApp.zip";
            string alternateApp = "Package.BlazorMobile.InteropBlazorApp.AnotherApp.zip";

            Assembly packageAssembly = assemblyService.GetAppPackageAssembly();
            Stream   fakeHttpPackage = packageAssembly.GetManifestResourceStream($"{packageAssembly.GetName().Name}.{alternateApp}");

            string packageStoreName = "alternate_package.zip";

            if (WebApplicationFactory.ListPackages().Contains(packageStoreName))
            {
                WebApplicationFactory.RemovePackage(packageStoreName);
            }

            bool addPackageSuccess = WebApplicationFactory.AddPackage(packageStoreName, fakeHttpPackage);

            //For debug inspection
            var packageResults = WebApplicationFactory.ListPackages().ToList();

            bool loadPackageSuccess = WebApplicationFactory.LoadPackage(packageStoreName);

            Task.Run(async() =>
            {
                await Task.Delay(10000);
                Device.BeginInvokeOnMainThread(() =>
                {
                    //Reload regular package
                    WebApplicationFactory.LoadPackageFromAssembly(assemblyService.GetAppPackageAssembly(), regularApp);
                    WebApplicationFactory.RemovePackage(packageStoreName);

                    //alternate_package.zip should not be present
                    var packageResultsAfterRemove = WebApplicationFactory.ListPackages().ToList();
                });
            });

            return(Task.CompletedTask);
        }