Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Programmatically using the WebAssembly Host services in a test

$
0
0

We are currently working on a project consisting of a Blazor WebAssembly project and an ASP.NET Core Web API project. Since these are two separate systems and hosts, they each have their own logical C# hosts: the presentation layer has a WebAssemblyHost, while the Web API has a WebApplication with its respective builder.

For certain quality tests, I would like to obtain a reference to the services registered in the presentation host's service collection.

Specifically, I would like to verify that the Lamar configuration is valid with a test like this:

[Fact]public void LamarConfiguration_IsValid(){    var host = Frontend.Presentation.Program.Host;    host.Services.Should().BeOfType<Container>();    var actualContainer = (IContainer)host.Services;    actualContainer.AssertConfigurationIsValid();}

However, I'm facing challenges in accessing the services in the presentation layer:

When I attempt to build the WebAssembly host via WebAssemblyHostBuilder, I encounter a PlatformNotSupportedException and if I use another host builder, I don’t get Blazor-specific services like NavigationManager.I also tried setting up a test environment with Playwright, which we’re already using for end-to-end tests. However, even here, I can’t access the services in these tests, as we technically start the Web API project, which then serves the WebAssembly presentation project.

Is there any way to achieve this? After reviewing available documentation and online resources, I haven’t found a solution, but I might be overlooking something.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>