SetParametersAndRender will breaks with .NET 8
See original GitHub issueDescribe the bug The extension function SetParametersAndRender throws a NullPointerException since the ComponentState.SetDirectParameters methods vilisbility is changed to internal in .NET 8.0 Preview 4.
The exception is raised here: https://github.com/bUnit-dev/bUnit/blob/e654d6d21b269e1e7a15a812968532a17795caff/src/bunit.core/Rendering/TestRenderer.cs#L211-L213
Example: Testing this component:
<div>
@Test
</div>
@code {
[Parameter]
public string? Test { get; set; }
}
With this test:
// Arrange
var test = "Hello";
var nextTest = "World";
// Act
var cut = RenderComponent<ExampleComponent>(p => p.Add(x => x.Test, test));
cut.SetParametersAndRender(p => p.Add(x => x.Test, nextTest));
// Assert
cut.MarkupMatches($"<div>{nextTest}</div>");
Results in this output:
Message:
System.NullReferenceException : Object reference not set to an instance of an object.
Stack Trace:
<>c__DisplayClass32_0.<SetDirectParameters>b__0() line 213
<>c.<InvokeAsync>b__8_0(Object state)
--- End of stack trace from previous location ---
TestRenderer.AssertNoUnhandledExceptions() line 582
TestRenderer.SetDirectParameters(IRenderedFragmentBase renderedComponent, ParameterView parameters) line 232
RenderedComponentRenderExtensions.SetParametersAndRender[TComponent](IRenderedComponentBase`1 renderedComponent, ParameterView parameters) line 33
RenderedComponentRenderExtensions.SetParametersAndRender[TComponent](IRenderedComponentBase`1 renderedComponent, Action`1 parameterBuilder) line 68
Tests.UpdatesCorrectly() line 39
RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
Version info:
- bUnit version: 1.22.19
- .NET Runtime and Blazor version: 8.0.0-preview.6.23329.11
Additional context:
Related changes in dotnet/aspnetcore:
Issue Analytics
- State:
- Created 2 months ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
bUnit/CHANGELOG.md at main
Calling MarkupMatches(RenderFragment) from a lambda passed to e.g. WaitForAssertion could lead to a deadlock in certain circumstances. Fixed by @linkdotnet.
Read more >Building Web Applications in .NET 6 and Beyond
Of course, this would break every existing C# application out there, ... in Listing 8-22, where we use the SetParametersAndRender method.
Read more >Triggering a render life cycle on a component
With a IRenderedComponent<TComponent>, it is possible to cause the component to render again directly through the Render() method or one of the ...
Read more >ASP.NET Core updates in .NET 5 Preview 8
NET 5 Preview 8 is now available and is ready for evaluation. ... See also the full list of breaking changes in ASP.NET...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@egil: I have a PR ready when I get back from the holidays (tomorrow evening). I have a new laptop and my ssh settings and stuff are not ported - therefore I want to set this up tomorrow for signed commits and stuff
SetParametersAndRender is working as expected. I will continue playing around with .NET 8 Blazor (but WASM only) you may hear from me.
Thanks for the quick fix guys!