コード例 #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.IsAttachToDocumentMessage(m, 0, "#app"),
                              m => AssertHelpers.IsRenderBatch(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 AddRootComponentsWithExistingSelector_Throws()
        {
            // Arrange
            const string arbitraryComponentSelector = "some_selector";
            var          services       = RegisterTestServices().AddTestBlazorWebView().BuildServiceProvider();
            var          fileProvider   = new TestFileProvider();
            var          webViewManager = new TestWebViewManager(services, fileProvider);
            await webViewManager.AddRootComponentAsync(typeof(MyComponent), arbitraryComponentSelector, ParameterView.Empty);

            // Act & assert
            var ex = await Assert.ThrowsAsync <InvalidOperationException>(async() => await webViewManager.AddRootComponentAsync(typeof(MyComponent), arbitraryComponentSelector, ParameterView.Empty));

            Assert.Equal($"There is already a root component with selector '{arbitraryComponentSelector}'.", ex.Message);
        }
コード例 #3
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();
        }
コード例 #4
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.IsAttachToDocumentMessage(m, 0, "#app"),
                              m => AssertHelpers.IsRenderBatch(m));
        }