Exemple #1
0
        private async Task BlazorWasmHostedTemplate_IndividualAuth_Works(BrowserKind browserKind, bool useLocalDb)
        {
            var project = await ProjectFactory.GetOrCreateProject("blazorhostedindividual" + browserKind + (useLocalDb ? "uld" : ""), Output);

            var serverProject = GetSubProject(project, "Server", $"{project.ProjectName}.Server");

            await BuildAndRunTest(project.ProjectName, serverProject, browserKind, usesAuth : true);

            UpdatePublishedSettings(serverProject);

            if (BrowserManager.IsAvailable(browserKind))
            {
                using var aspNetProcess = serverProject.StartPublishedProjectAsync();

                Assert.False(
                    aspNetProcess.Process.HasExited,
                    ErrorMessages.GetFailedProcessMessageOrEmpty("Run published project", serverProject, aspNetProcess.Process));

                await aspNetProcess.AssertStatusCode("/", HttpStatusCode.OK, "text/html");

                await using var browser = await BrowserManager.GetBrowserInstance(browserKind, BrowserContextInfo);

                var page = await browser.NewPageAsync();

                await aspNetProcess.VisitInBrowserAsync(page);
                await TestBasicNavigation(project.ProjectName, page, usesAuth : true);

                await page.CloseAsync();
            }
            else
            {
                EnsureBrowserAvailable(browserKind);
            }
        }
Exemple #2
0
        protected async Task BuildAndRunTest(string appName, Project project, BrowserKind browserKind, bool usesAuth = false)
        {
            using var aspNetProcess = project.StartBuiltProjectAsync();

            Assert.False(
                aspNetProcess.Process.HasExited,
                ErrorMessages.GetFailedProcessMessageOrEmpty("Run built project", project, aspNetProcess.Process));

            await aspNetProcess.AssertStatusCode("/", HttpStatusCode.OK, "text/html");

            if (BrowserManager.IsAvailable(browserKind))
            {
                await using var browser = await BrowserManager.GetBrowserInstance(browserKind, BrowserContextInfo);

                var page = await browser.NewPageAsync();

                await aspNetProcess.VisitInBrowserAsync(page);
                await TestBasicNavigation(appName, page, usesAuth);

                await page.CloseAsync();
            }
            else
            {
                EnsureBrowserAvailable(browserKind);
            }
        }
Exemple #3
0
        public async Task BlazorWasmHostedTemplate_Works(BrowserKind browserKind)
        {
            var project = await ProjectFactory.GetOrCreateProject("blazorhosted" + browserKind, Output);

            var serverProject = GetSubProject(project, "Server", $"{project.ProjectName}.Server");

            await BuildAndRunTest(project.ProjectName, serverProject, browserKind);

            using var aspNetProcess = serverProject.StartPublishedProjectAsync();

            Assert.False(
                aspNetProcess.Process.HasExited,
                ErrorMessages.GetFailedProcessMessageOrEmpty("Run published project", serverProject, aspNetProcess.Process));

            await aspNetProcess.AssertStatusCode("/", HttpStatusCode.OK, "text/html");

            await AssertCompressionFormat(aspNetProcess, "br");

            if (BrowserManager.IsAvailable(browserKind))
            {
                await using var browser = await BrowserManager.GetBrowserInstance(browserKind, BrowserContextInfo);

                var page = await browser.NewPageAsync();

                await aspNetProcess.VisitInBrowserAsync(page);
                await TestBasicNavigation(project.ProjectName, page);
            }
            else
            {
                EnsureBrowserAvailable(browserKind);
            }
        }
        public async Task BlazorWasmStandaloneTemplate_IndividualAuth_Works(BrowserKind browserKind)
        {
            var project = await CreateBuildPublishAsync("blazorstandaloneindividual" + browserKind, args : new[] {
                "-au",
                "Individual",
                "--authority",
                "https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration",
                "--client-id",
                "sample-client-id"
            });

            // We don't want to test the auth flow as we don't have the required settings to talk to a third-party IdP
            // but we want to make sure that we are able to run the app without errors.
            // That will at least test that we are able to initialize and retrieve the configuration from the IdP
            // for that, we use the common microsoft tenant.
            await BuildAndRunTest(project.ProjectName, project, browserKind, usesAuth : false);

            var(serveProcess, listeningUri) = RunPublishedStandaloneBlazorProject(project);
            using (serveProcess)
            {
                Output.WriteLine($"Opening browser at {listeningUri}...");
                await using var browser = await BrowserManager.GetBrowserInstance(browserKind, BrowserContextInfo);

                var page = await NavigateToPage(browser, listeningUri);
                await TestBasicNavigation(project.ProjectName, page);

                await page.CloseAsync();
            }
        }
        public async Task BlazorWasmStandaloneTemplate_Works(BrowserKind browserKind)
        {
            var project = await CreateBuildPublishAsync("blazorstandalone" + browserKind);

            // The service worker assets manifest isn't generated for non-PWA projects
            var publishDir = Path.Combine(project.TemplatePublishDir, "wwwroot");

            Assert.False(File.Exists(Path.Combine(publishDir, "service-worker-assets.js")), "Non-PWA templates should not produce service-worker-assets.js");

            await BuildAndRunTest(project.ProjectName, project, browserKind);

            var(serveProcess, listeningUri) = RunPublishedStandaloneBlazorProject(project);
            using (serveProcess)
            {
                Output.WriteLine($"Opening browser at {listeningUri}...");
                if (BrowserManager.IsAvailable(browserKind))
                {
                    await using var browser = await BrowserManager.GetBrowserInstance(browserKind, BrowserContextInfo);

                    var page = await NavigateToPage(browser, listeningUri);
                    await TestBasicNavigation(project.ProjectName, page);
                }
                else
                {
                    EnsureBrowserAvailable(browserKind);
                }
            }
        }
Exemple #6
0
        protected override async Task InitializeCoreAsync(TestContext context)
        {
            await base.InitializeCoreAsync(context);

            // Default to Chrome
            var browserKind = BrowserKind.Chromium;

            // Check if a different browser is requested
            var browserKindArgument = context.MethodArguments.FirstOrDefault();

            if (browserKindArgument != null &&
                browserKindArgument.GetType() == typeof(BrowserKind))
            {
                browserKind = (BrowserKind)browserKindArgument;
            }

            if (ShouldSkip(browserKind))
            {
                var avail = String.Join(",", BrowserManager.GetAvailableBrowsers());
                var error = $"Skipping browser: {browserKind}: Available: {avail}";
                Output.WriteLine(error);
                return;
            }

            TestBrowser = await BrowserManager.GetBrowserInstance(browserKind, BrowserContextInfo);

            TestPage = await TestBrowser.NewPageAsync();

            var response = await TestPage.GoToAsync(MountUri);

            Assert.True(response.Ok, $"Got: {response.StatusText} from: {MountUri}");
            Output.WriteLine($"Loaded MountUri: {MountUri}");

            await MountTestComponentAsync(TestPage);
        }
        public async Task BlazorWasmStandalonePwaTemplate_Works(BrowserKind browserKind)
        {
            var project = await CreateBuildPublishAsync("blazorstandalonepwa", args: new[] { "--pwa" });

            await BuildAndRunTest(project.ProjectName, project, browserKind);

            ValidatePublishedServiceWorker(project);

            if (BrowserManager.IsAvailable(browserKind))
            {
                var (serveProcess, listeningUri) = RunPublishedStandaloneBlazorProject(project);
                await using var browser = await BrowserManager.GetBrowserInstance(browserKind, BrowserContextInfo);
                Output.WriteLine($"Opening browser at {listeningUri}...");
                var page = await NavigateToPage(browser, listeningUri);
                using (serveProcess)
                {
                    await TestBasicNavigation(project.ProjectName, page);
                }

                // The PWA template supports offline use. By now, the browser should have cached everything it needs,
                // so we can continue working even without the server.
                await page.GoToAsync("about:blank");
                await browser.SetOfflineAsync(true);
                await page.GoToAsync(listeningUri);
                await TestBasicNavigation(project.ProjectName, page, skipFetchData: true);
                await page.CloseAsync();
            }
            else
            {
                EnsureBrowserAvailable(browserKind);
            }
        }
Exemple #8
0
        public async Task CanSendAndReceiveBytes()
        {
            if (BrowserManager.IsAvailable(BrowserKind.Chromium))
            {
                await using var browser = await BrowserManager.GetBrowserInstance(BrowserKind.Chromium, BrowserContextInfo);

                var page = await browser.NewPageAsync();

                await page.GoToAsync(_devHostServerFixture.RootUri + "/subdir/api/data");

/*                var socket = BrowserContextInfo.Pages[page].WebSockets.SingleOrDefault() ??
 *                  (await page.WaitForEventAsync(PageEvent.WebSocket)).WebSocket;
 *
 *              // Receive render batch
 *              await socket.WaitForEventAsync(WebSocketEvent.FrameReceived);
 *              await socket.WaitForEventAsync(WebSocketEvent.FrameSent);
 *
 *              // JS interop call to intercept navigation
 *              await socket.WaitForEventAsync(WebSocketEvent.FrameReceived);
 *              await socket.WaitForEventAsync(WebSocketEvent.FrameSent);
 *
 *              await page.WaitForSelectorAsync("ul");*/

                await page.CloseAsync();
            }


            //IssueRequest("/subdir/api/data");
            //Assert.Equal("OK", _responseStatus.Text);
            //Assert.Equal("OK", _responseStatusText.Text);
            //Assert.Equal("", _testOutcome.Text);
        }
Exemple #9
0
        public async Task BlazorServerTemplateWorks_NoAuth(BrowserKind browserKind)
        {
            var project = await ProjectFactory.GetOrCreateProject("blazorservernoauth" + browserKind, Output);

            await using var browser = BrowserManager.IsAvailable(browserKind) ?
                                      await BrowserManager.GetBrowserInstance(browserKind, BrowserContextInfo) :
                                      null;

            using (var aspNetProcess = project.StartBuiltProjectAsync())
            {
                Assert.False(
                    aspNetProcess.Process.HasExited,
                    ErrorMessages.GetFailedProcessMessageOrEmpty("Run built project", project, aspNetProcess.Process));

                await aspNetProcess.AssertStatusCode("/", HttpStatusCode.OK, "text/html");

                if (BrowserManager.IsAvailable(browserKind))
                {
                    var page = await browser.NewPageAsync();

                    await aspNetProcess.VisitInBrowserAsync(page);
                    await TestBasicNavigation(project, page);

                    await page.CloseAsync();
                }
                else
                {
                    EnsureBrowserAvailable(browserKind);
                }
            }

            using (var aspNetProcess = project.StartPublishedProjectAsync())
            {
                Assert.False(
                    aspNetProcess.Process.HasExited,
                    ErrorMessages.GetFailedProcessMessageOrEmpty("Run published project", project, aspNetProcess.Process));

                await aspNetProcess.AssertStatusCode("/", HttpStatusCode.OK, "text/html");

                if (BrowserManager.IsAvailable(browserKind))
                {
                    var page = await browser.NewPageAsync();

                    await aspNetProcess.VisitInBrowserAsync(page);
                    await TestBasicNavigation(project, page);

                    await page.CloseAsync();
                }
                else
                {
                    EnsureBrowserAvailable(browserKind);
                }
            }
        }
Exemple #10
0
    public async Task BlazorServerTemplateWorks_IndividualAuth(BrowserKind browserKind, bool useLocalDB)
    {
        var project = await CreateBuildPublishAsync("blazorserverindividual" + browserKind + (useLocalDB ? "uld" : ""));

        var browser = !BrowserManager.IsAvailable(browserKind) ?
                      null :
                      await BrowserManager.GetBrowserInstance(browserKind, BrowserContextInfo);

        using (var aspNetProcess = project.StartBuiltProjectAsync())
        {
            Assert.False(
                aspNetProcess.Process.HasExited,
                ErrorMessages.GetFailedProcessMessageOrEmpty("Run built project", project, aspNetProcess.Process));

            await aspNetProcess.AssertStatusCode("/", HttpStatusCode.OK, "text/html");

            if (BrowserManager.IsAvailable(browserKind))
            {
                var page = await browser.NewPageAsync();

                await aspNetProcess.VisitInBrowserAsync(page);
                await TestBasicNavigation(page);

                await page.CloseAsync();
            }
            else
            {
                EnsureBrowserAvailable(browserKind);
            }
        }

        using (var aspNetProcess = project.StartPublishedProjectAsync())
        {
            Assert.False(
                aspNetProcess.Process.HasExited,
                ErrorMessages.GetFailedProcessMessageOrEmpty("Run published project", project, aspNetProcess.Process));

            await aspNetProcess.AssertStatusCode("/", HttpStatusCode.OK, "text/html");

            if (BrowserManager.IsAvailable(browserKind))
            {
                var page = await browser.NewPageAsync();

                await aspNetProcess.VisitInBrowserAsync(page);
                await TestBasicNavigation(page);

                await page.CloseAsync();
            }
            else
            {
                EnsureBrowserAvailable(browserKind);
            }
        }
    }
Exemple #11
0
        public async Task BlazorWasmHostedPwaTemplate_Works(BrowserKind browserKind)
        {
            var project = await ProjectFactory.GetOrCreateProject("blazorhostedpwa", Output);

            var serverProject = GetSubProject(project, "Server", $"{project.ProjectName}.Server");

            await BuildAndRunTest(project.ProjectName, serverProject, browserKind);

            ValidatePublishedServiceWorker(serverProject);

            string listeningUri = null;

            if (BrowserManager.IsAvailable(browserKind))
            {
                await using var browser = await BrowserManager.GetBrowserInstance(browserKind, BrowserContextInfo);

                IPage page = null;
                using (var aspNetProcess = serverProject.StartPublishedProjectAsync())
                {
                    Assert.False(
                        aspNetProcess.Process.HasExited,
                        ErrorMessages.GetFailedProcessMessageOrEmpty("Run published project", serverProject, aspNetProcess.Process));

                    await aspNetProcess.AssertStatusCode("/", HttpStatusCode.OK, "text/html");

                    page = await browser.NewPageAsync();

                    await aspNetProcess.VisitInBrowserAsync(page);
                    await TestBasicNavigation(project.ProjectName, page);

                    // Note: we don't want to use aspNetProcess.ListeningUri because that isn't necessarily the HTTPS URI
                    listeningUri = new Uri(page.Url).GetLeftPart(UriPartial.Authority);
                }

                // The PWA template supports offline use. By now, the browser should have cached everything it needs,
                // so we can continue working even without the server.
                // Since this is the hosted project, backend APIs won't work offline, so we need to skip "fetchdata"
                await page.GoToAsync("about:blank");

                await browser.SetOfflineAsync(true);

                await page.GoToAsync(listeningUri);
                await TestBasicNavigation(project.ProjectName, page, skipFetchData : true);

                await page.CloseAsync();
            }
            else
            {
                EnsureBrowserAvailable(browserKind);
            }
        }
Exemple #12
0
        public async Task BlazorWasmStandaloneTemplate_Works(BrowserKind browserKind)
        {
            var project = await ProjectFactory.GetOrCreateProject("blazorstandalone" + browserKind, Output);

            await BuildAndRunTest(project.ProjectName, project, browserKind);

            var(serveProcess, listeningUri) = RunPublishedStandaloneBlazorProject(project);
            using (serveProcess)
            {
                Output.WriteLine($"Opening browser at {listeningUri}...");
                if (BrowserManager.IsAvailable(browserKind))
                {
                    await using var browser = await BrowserManager.GetBrowserInstance(browserKind, BrowserContextInfo);

                    var page = await NavigateToPage(browser, listeningUri);
                    await TestBasicNavigation(project.ProjectName, page);
                }
                else
                {
                    EnsureBrowserAvailable(browserKind);
                }
            }
        }