Exemplo n.º 1
0
    public async Task AttachingToNewPage_DisposesExistingScopeAsync()
    {
        // Arrange
        var services       = RegisterTestServices().AddTestBlazorWebView().BuildServiceProvider();
        var fileProvider   = new TestFileProvider();
        var webViewManager = new TestWebViewManager(services, fileProvider);
        await webViewManager.AddRootComponentAsync(typeof(MyComponent), "#app", ParameterView.Empty);

        var singleton = services.GetRequiredService <SingletonService>();

        // Act
        Assert.Empty(webViewManager.SentIpcMessages);
        webViewManager.ReceiveAttachPageMessage();
        webViewManager.ReceiveAttachPageMessage();

        // Assert
        Assert.Collection(webViewManager.SentIpcMessages,
                          m => AssertHelpers.IsAttachWebRendererInteropMessage(m),
                          m => AssertHelpers.IsAttachToDocumentMessage(m, 0, "#app"),
                          m => AssertHelpers.IsRenderBatch(m),
                          m => AssertHelpers.IsAttachWebRendererInteropMessage(m),
                          m => AssertHelpers.IsAttachToDocumentMessage(m, 0, "#app"),
                          m => AssertHelpers.IsRenderBatch(m));

        Assert.Equal(2, singleton.Services.Count);
        Assert.NotSame(singleton.Services[0], singleton.Services[1]);
    }
Exemplo n.º 2
0
    public async Task CanRenderRootComponentAsync()
    {
        // Arrange
        var services       = RegisterTestServices().AddTestBlazorWebView().BuildServiceProvider();
        var fileProvider   = new TestFileProvider();
        var webViewManager = new TestWebViewManager(services, fileProvider);
        await webViewManager.AddRootComponentAsync(typeof(MyComponent), "#app", ParameterView.Empty);

        // Act
        Assert.Empty(webViewManager.SentIpcMessages);
        webViewManager.ReceiveAttachPageMessage();

        // Assert
        Assert.Collection(webViewManager.SentIpcMessages,
                          m => AssertHelpers.IsAttachWebRendererInteropMessage(m),
                          m => AssertHelpers.IsAttachToDocumentMessage(m, 0, "#app"),
                          m => AssertHelpers.IsRenderBatch(m));
    }