bUnit-dev / bUnit

bUnit is a testing library for Blazor components that make tests look, feel, and runs like regular unit tests. bUnit makes it easy to render and control a component under test’s life-cycle, pass parameter and inject services into it, trigger event handlers, and verify the rendered markup from the component using a built-in semantic HTML comparer.
https://bunit.dev
MIT License
1.14k stars 105 forks source link

updating past release 6.4.0, lose AddTestAuthorization & System.MissingFieldException: Field not found: 'Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame.FrameType'. #1554

Closed NTC-THSTO closed 1 month ago

NTC-THSTO commented 1 month ago

using Bunit

Example: Testing this component:

Trying to update the project to .net 8

Finding that with latest release:

    <PackageReference Include="Verify.Bunit" Version="11.0.0" />

makes our tests reference unresolvable:

    ctx.Services.AddTestAuthorization(); // Cannot resolve symbol 'AddTestAuthorization'

trial and error shows that we lose that reference between 6.4.0 & 6.5.0.

Using 6.4.0 we get:

System.MissingFieldException: Field not found: 'Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame.FrameType'.

System.MissingFieldException
Field not found: 'Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame.FrameType'.
   at Bunit.Rendering.TestRenderer.GetComponent[TComponent](Int32 rootComponentId)
   at Bunit.Rendering.TestRenderer.FindComponent[TComponent](Int32 parentComponentId)
   at Bunit.Rendering.TestRenderer.RenderComponent[TComponent](IEnumerable`1 parameters)
   at Bunit.TestContext.RenderComponent[TComponent](Action`1 parameterBuilder)
   at Tdt.Web.Tests.IndexTests.Index_UnauthorisedUser_ComponentRendersCorrectly() in C:\work\repos\DCC\New folder (3) - Copy\src\TestDataTool\Web\Tdt.Web.Tests\IndexTests.cs:line 45
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

using the following versioning:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <IsPackable>false</IsPackable>
    <SonarQubeTestProject>True</SonarQubeTestProject>
  </PropertyGroup>
  <ItemGroup>
    <Compile Remove="StartupTests.cs" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="DNTCaptcha.Core" Version="3.6.0" />
    <PackageReference Include="Microsoft.Extensions.Identity.Core" Version="8.0.8" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
    <PackageReference Include="Moq" Version="4.16.0" />
    <PackageReference Include="RichardSzalay.MockHttp" Version="6.0.0" />
    <PackageReference Include="Serilog.AspNetCore" Version="3.4.0" />
    <PackageReference Include="Verify.Blazor" Version="11.0.0" />
    <PackageReference Include="Verify.Bunit" Version="6.4.0" />
    <PackageReference Include="xunit" Version="2.9.0" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="coverlet.collector" Version="3.0.2">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\Tdt.Web\Tdt.Web.csproj" />
  </ItemGroup>
</Project>

Which I have noticed has been reported before on this github section I am no C# wizard. If this is a developer error, I apologise though any suggestions would be greatly appreciated.

linkdotnet commented 1 month ago

Hey @NTC-THSTO

Verify-bUnit is a package maintained by @SimonCropp - you might want to head over to the Verify-bUnit github repository and ask there.

linkdotnet commented 1 month ago

As this is a 3rd party related issue, I will close the issue. See: https://github.com/VerifyTests/Verify.Bunit/issues/29