예제 #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]);
    }
예제 #2
0
    public async Task CanDisposeWebViewManagerWithAsyncDisposableServices()
    {
        // Arrange
        var services = RegisterTestServices()
                       .AddTestBlazorWebView()
                       .AddScoped <AsyncDisposableService>()
                       .BuildServiceProvider();
        var fileProvider   = new TestFileProvider();
        var webViewManager = new TestWebViewManager(services, fileProvider);
        await webViewManager.AddRootComponentAsync(typeof(MyComponentUsingScopedAsyncDisposableService), "#app", ParameterView.Empty);

        webViewManager.ReceiveAttachPageMessage();

        // Act
        await webViewManager.DisposeAsync();
    }
예제 #3
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));
    }