1

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.

Mert Ekinci
  • 352
  • 2
  • 13
Riley Christian
  • 149
  • 1
  • 13
  • You could follow this doc related with testing Blazor:https://learn.microsoft.com/en-us/aspnet/core/blazor/test?view=aspnetcore-7.0 – Ruikai Feng Apr 18 '23 at 07:15
  • My goal is not really unit testing, it is rather integration testing with MockWire.Net. Thank you for your feedback buddy. – Riley Christian Apr 18 '23 at 11:00

1 Answers1

0

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.WebAssembly package 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 .csproj file 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.

mw509
  • 1,957
  • 1
  • 19
  • 25