Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find fails with System.TypeLoadException: Method 'get_GivenNamespaceUri' from assembly 'AngleSharpWrappers does not have an implementation #1262

Closed
hhyyrylainen opened this issue Nov 9, 2023 · 2 comments · Fixed by #1286
Labels
bug Something isn't working needs design More design is needed before this issue should result in a feature being implemented.

Comments

@hhyyrylainen
Copy link

Describe the bug

After updating my nuget packages, my tests no longer pass. I suspect that this has something to do with my tests project now having a newer AngleSharp version. The issue seems to happen at least with both 1.0.5 and 1.0.4. I did not change any of the related test code (or the functionality the test tests) before the test started failing.

Example:
I can provide a component example but it kind of seems based on the exception that it is enough to have any anchor elements in the generated render fragment.

Both of these lines cause the exception to be thrown (after the first line which is just setup):

        var cut = RenderComponent<Login>();
        Assert.False(cut.Find("form button").HasAttribute("disabled"));
        Assert.Contains(cut.Find("form button").Attributes, i => i.Name == "disabled");

Results in this exception:

System.TypeLoadException: Method 'get_GivenNamespaceUri' in type 'AngleSharpWrappers.HtmlAnchorElementWrapper' from assembly 'AngleSharpWrappers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=fe9c6306bcc1ce6f' does not have an implementation.
   at Bunit.ElementWrapperFactory.Create(IElement element, IRenderedFragment renderedFragment, String cssSelector)
   at Bunit.RenderedFragmentExtensions.Find(IRenderedFragment renderedFragment, String cssSelector) in /_/src/bunit.web/Extensions/RenderedFragmentExtensions.cs:line 28
   at ThriveDevCenter.Client.Tests.Pages.Tests.LoginTests.LoginLocal_LoginButtonEnablesWhenTextInput() in /home/hhyyrylainen/Projects/ThriveDevCenter/Client.Tests/Pages.Tests/LoginTests.cs:line 84
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)

But for example a simpler check like this passes:

cut.FindIsNull("form button");

This is my full test that fails:

    [Fact]
    public void LoginLocal_LoginButtonEnablesWhenTextInput()
    {
        var mockCSRF = CSRFMockFactory.Create();

        var http = Services.AddMockHttpClient();
        http.When("/api/v1/Registration").RespondJson(false);
        http.When("/LoginController").RespondJson(new LoginOptions
        {
            Categories = new List<LoginCategory>
            {
                new()
                {
                    Name = "Local Account",
                    Options = new List<LoginOption>
                    {
                        new()
                        {
                            ReadableName = "Login using a local account",
                            InternalName = "local",
                            Active = true,
                            Local = true,
                        },
                    },
                },
            },
        });

        Services.AddSingleton(mockCSRF);
        var cut = RenderComponent<Login>();

        cut.WaitForAssertion(() => cut.FindIsNull(".spinner-border"));

        Assert.Contains(cut.Find("form button").Attributes, i => i.Name == "disabled");

        cut.Find("input[type=email]").Input("[email protected]");
        cut.Find("input[type=password]").Input("12345");

        Assert.DoesNotContain(cut.Find("form button").Attributes, i => i.Name == "disabled");
    }

Expected behavior:

I expected the Find method call to keep working. It seems that Find itself is not the problem but the required element wrapping that happens behind the scenes and tries to use a method in AngleSharp that no longer exists, or something like that?

Version info:

  • bUnit version: 1.24.10
  • .NET Runtime and Blazor version: Dotnet SDK 7.0.112 with Blazor WASM version: 7.0.13
  • OS type and version: Fedora 38
@egil
Copy link
Member

egil commented Nov 9, 2023

Yeah, you are probably right about the exception. bUnit wraps AngleSharps IElement types when returned by Find such that after a render the elements automatically update.

However, until we find a good alternative solution, you can drop using Find and instead use cut.Nodes.QuerySelector. You wont get auto-refreshing element references.

@egil egil added bug Something isn't working needs design More design is needed before this issue should result in a feature being implemented. labels Nov 9, 2023
@hhyyrylainen
Copy link
Author

Thanks for the alternative solution. I was able to use that to get my test passing for now.
I didn't even know that there was an auto-refresh feature so I was re-fetching the nodes anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs design More design is needed before this issue should result in a feature being implemented.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants