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]); }
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); }
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(); }
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)); }