I have created an integration test project to mock API with WireMock.Net library. My application is a Blazor WebAssembly with ASP.NET Core Hosted. However, when I try to debug my test case I get this exception error: "Could not load type 'WebAssembly.JSInterop.JSCallInfo' assembly 'Microsoft.JSInterop.WebAssembly, Version=7.0.2.0". What could be the cause of this error?
Here is my integration test project looks like
public class ContactControllerTests : IClassFixture<WebApplicationFactory<Program>>
{
public ContactControllerTests(WebApplicationFactory<Program> applicationFactory)
{
_httpClient = applicationFactory.CreateDefaultClient();
}
[Fact]
public async Task GetContacts_WhenGetAll_ThenReturnAllContacts()
{
}
}
And in the same project, I have a 'Program.cs' file that has this configuration
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using System.Net.Http.Headers;
....//some other usings
var builder = WebAssemblyHostBuilder.CreateDefault(args); //Here is where it throws the exception
builder.RootComponents.Add<App>("#app");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
await builder.Build().RunAsync();
public partial class Program { }
With the above configuration, it looks like I am not able to create an in-memory test server that is hosting WebAssembly. I would appreciate any help or feedback.
It could be that the required assembly is not being included in your test project. Verifying that the assembly is referenced in your project's dependencies, and that its Copy Local property is set to
True.It's also possible that the version of the assembly you are referencing in your test project is different from the version that your Blazor WebAssembly application is using. Try updating your test project's
Microsoft.JSInterop.WebAssemblypackage to match the version used by your Blazor WebAssembly application. You can also try specifying the specific version of the package in your test project's dependencies to ensure that the correct version is being used. This specificity of the package can be done from the.csprojfile of your project.lets see if any of these help. if not you may want to perhaps use the WebAssemblyHostBuilder to create an in-memory test server that is hosting WebAssembly.