Exemple #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);
        }
Exemple #2
0
        private async Task PackageTest()
        {
            //Test for store download

            var _httpClient = new HttpClient {
                Timeout = TimeSpan.FromSeconds(15)
            };

            try
            {
                using (var httpResponse = await _httpClient.GetAsync("https://raw.githubusercontent.com/Daddoon/BlazorMobile/master/README.md"))
                {
                    if (httpResponse.StatusCode == HttpStatusCode.OK)
                    {
                        contentStream = new MemoryStream();
                        var result = await httpResponse.Content.ReadAsStreamAsync();

                        result.CopyTo(contentStream);
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            WebApplicationFactory.AddPackage("testpackage", contentStream);

                            //This Stream was initialized outside the "using" scope as we wanted it through 2 differents thread
                            //So disposing it here now as we don't have to use it anymore
                            contentStream.Dispose();
                        });
                    }
                    else
                    {
                        //Url is Invalid
                        return;
                    }
                }
            }
            catch (Exception)
            {
                //Handle Exception
                return;
            }
        }