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

Tests throw exception 'File not found' #221

Closed
bfmsoft opened this issue Sep 29, 2020 · 11 comments
Closed

Tests throw exception 'File not found' #221

bfmsoft opened this issue Sep 29, 2020 · 11 comments
Labels
input needed When an issue requires input or suggestions

Comments

@bfmsoft
Copy link

bfmsoft commented Sep 29, 2020

Just try to run tests and get "File not found". This is testing my component that basically processing enums to strings. This worked up till RC1 and beta 10. Did I do something wrong? I saw a note in RC1 that talks here that talks about binary issues but not source. Does this have something to do with it?

**Full error:
Test Name: BfmSoft.Web.BlazorUtil.Tests.RazorTestComponents.BfmEnumInputSelectTest.RazorTests
Test FullName: BfmSoft.Web.BlazorUtil.Tests.BfmSoft.Web.BlazorUtil.Tests.RazorTestComponents.BfmEnumInputSelectTest.BfmSoft.Web.BlazorUtil.Tests.RazorTestComponents.BfmEnumInputSelectTest.RazorTests
Test Source: : line -1
Test Outcome: Failed
Test Duration: 0:00:00

Test Name: BfmSoft.Web.BlazorUtil.Tests.RazorTestComponents.BfmEnumInputSelectTest.RazorTests
Test Outcome: Failed
Result Message:
System.InvalidOperationException : Exception thrown during razor test discovery on 'BfmSoft.Web.BlazorUtil.Tests.RazorTestComponents.BfmEnumInputSelectTest'.
Field not found: 'Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame.FrameType'.

Example:

@inherits TestComponentBase
@using BfmSoft.Web.BlazorUtil.Components

@code {
    private MockJSRuntimeInvokeHandler MockJsRuntime { get; set; } = default!;

    private Register Register { get; set; } = new Register();
    private EditContext EditContext { get; set; } = default!;

    private IInputSelectUtil InputSelectUtil { get; set; } = default!;

    private void Setup(Fixture fixture)
    {
        MockJsRuntime = fixture.Services.AddMockJSRuntime();
        EditContext = new EditContext(Register);

        Register.UserCountry = SecurePileEnums.Country.UnitedStates;
    }
}

<Fixture Setup="Setup" Test="BfmEnumInputSelectNoInitTest">
    <ComponentUnderTest>
        <EditForm Model="Register">
            <BfmEnumInputSelect Id="CountryId"
                                InputSelectUtil="@InputSelectUtil"
                                EnumTypeId="SecurePileEnums.EnumCountry"
                                @bind-Item="@Register.UserCountry"
                                ValidationFor="() => Register.UserCountry" />
        </EditForm>
    </ComponentUnderTest>
    <Fragment>
        <form>
            <div class="form-control-wrapper">
                <div>Loading, please wait...</div>
            </div>
        </form>
    </Fragment>

    @code {
        public void BfmEnumInputSelectNoInitTest(Fixture fixture)
        {
            InputSelectUtil = new InputSelectUtil();

            var cut = fixture.GetComponentUnderTest();

            cut.MarkupMatches(fixture.GetFragment());
        }
    }
</Fixture>

<Fixture Setup="Setup" Test="BfmEnumInputSelectDefaultTest">
    <ComponentUnderTest>
        <EditForm Model="Register">
            <BfmEnumInputSelect Id="CountryId"
                                InputSelectUtil="@InputSelectUtil"
                                EnumTypeId="SecurePileEnums.EnumCountry"
                                @bind-Item="@Register.UserCountry"
                                ValidationFor="() => Register.UserCountry" />
        </EditForm>
    </ComponentUnderTest>
    <Fragment>
        <form>
            <div class="form-control-wrapper">
                <select class="form-control " id="CountryId" onchange="OnChange">
                    <option value="128" selected="">- Select Item -</option>
                    <option value="129">United States</option>
                </select>
            </div>
        </form>
    </Fragment>

    @code {
        private void BfmEnumInputSelectDefaultTest(Fixture fixture)
        {
            var inputSelectUtil = new Moq.Mock<IInputSelectUtil>();
            inputSelectUtil.Setup(e => e.GetEnums<SecurePileEnums.Country>(SecurePileEnums.EnumCountry)).Returns(
                    new (int enumId, string enumText)[] {
                        ((int)SecurePileEnums.Country.Default, "- Select Item -"),
                        ((int)SecurePileEnums.Country.UnitedStates, "United States"),
                    }
                );
            InputSelectUtil = inputSelectUtil.Object;

            Register.UserCountry = SecurePileEnums.Country.Default;
            var cut = fixture.GetComponentUnderTest();
            cut.MarkupMatches(fixture.GetFragment());
        }
    }
</Fixture>

<Fixture Setup="Setup" Test="BfmEnumInputSelectUnitedStatesTest">
    <ComponentUnderTest>
        <EditForm Model="Register">
            <BfmEnumInputSelect Id="CountryId"
                                InputSelectUtil="@InputSelectUtil"
                                EnumTypeId="SecurePileEnums.EnumCountry"
                                @bind-Item="@Register.UserCountry"
                                ValidationFor="() => Register.UserCountry" />
        </EditForm>
    </ComponentUnderTest>
    <Fragment>
        <form>
            <div class="form-control-wrapper">
                <select class="form-control " id="CountryId" onchange="OnChange">
                    <option value="128">- Select Item -</option>
                    <option value="129" selected="">United States</option>
                </select>
            </div>
        </form>
    </Fragment>

    @code {
        private void BfmEnumInputSelectUnitedStatesTest(Fixture fixture)
        {
            var inputSelectUtil = new Moq.Mock<IInputSelectUtil>();
            inputSelectUtil.Setup(e => e.GetEnums<SecurePileEnums.Country>(SecurePileEnums.EnumCountry)).Returns(
                    new (int enumId, string enumText)[] {
                        ((int)SecurePileEnums.Country.Default, "- Select Item -"),
                        ((int)SecurePileEnums.Country.UnitedStates, "United States"),
                    }
                );
            InputSelectUtil = inputSelectUtil.Object;

            Register.UserCountry = SecurePileEnums.Country.UnitedStates;
            var cut = fixture.GetComponentUnderTest();
            cut.MarkupMatches(fixture.GetFragment());
        }
    }
</Fixture>

With this test:

Unit test in C# or Razor or Snapshot that fails.

Results in this output:

Test Name:	BfmSoft.Web.BlazorUtil.Tests.RazorTestComponents.BfmEnumInputSelectTest.RazorTests
Test FullName:	BfmSoft.Web.BlazorUtil.Tests.BfmSoft.Web.BlazorUtil.Tests.RazorTestComponents.BfmEnumInputSelectTest.BfmSoft.Web.BlazorUtil.Tests.RazorTestComponents.BfmEnumInputSelectTest.RazorTests
Test Source:	 : line -1
Test Outcome:	Failed
Test Duration:	0:00:00

Test Name:	BfmSoft.Web.BlazorUtil.Tests.RazorTestComponents.BfmEnumInputSelectTest.RazorTests
Test Outcome:	Failed
Result Message:	
System.InvalidOperationException : Exception thrown during razor test discovery on 'BfmSoft.Web.BlazorUtil.Tests.RazorTestComponents.BfmEnumInputSelectTest'.
Field not found: 'Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame.FrameType'.

Expected behavior:
Test should pass (it did before RC1 and beta 10)

Version info:

  • Library version: beta 10
  • .NET Core/Blazor version: 5.0 RC1
@egil
Copy link
Member

egil commented Sep 29, 2020

@bfmsoft I just created a quick sample project locally and cannot seem to reproduce. It is attached here, please download it see if you can get it to fail on your machine.

Rc1Test.zip

@bfmsoft
Copy link
Author

bfmsoft commented Sep 29, 2020

@egil ok that works. So looked and I had bunit package. I uninstalled and installed. bunit.web and bunit.xunit and it works.

@egil egil added the input needed When an issue requires input or suggestions label Sep 29, 2020
@bfmsoft
Copy link
Author

bfmsoft commented Sep 29, 2020

So the issue was I was using bunit package.

@egil
Copy link
Member

egil commented Sep 29, 2020

hmm that should not be an issue. let me investigate a bit.

@bfmsoft
Copy link
Author

bfmsoft commented Sep 29, 2020

Plus I am still having the issue that Visual Studio thinks this new version is newer because it does text sorting:
v1.0.0-beta-9 SORTS AFTER
v1.0.0-beta-10 because of the 1

So If I don't pay attention it will install the old package

@egil
Copy link
Member

egil commented Sep 29, 2020

Hmm nop, still works fine on my machine.

If I change the csproj to this, it still builds and runs fine:

<Project Sdk="Microsoft.NET.Sdk.Razor">

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="bunit" Version="1.0.0-beta-10" />
    <PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0-rc.1.20451.17" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
    <PackageReference Include="xunit" Version="2.4.1" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
  </ItemGroup>

</Project>

@bfmsoft
Copy link
Author

bfmsoft commented Sep 29, 2020

bunit is only beta9 on my version. That is the problem. The other ones have beta10. With the previous sorting issue.

@egil
Copy link
Member

egil commented Sep 29, 2020

Perhaps this is messing something up for you: https://twitter.com/egilhansen/status/1305992010508185606

@bfmsoft
Copy link
Author

bfmsoft commented Sep 29, 2020

Ah Azure Devops is causing it. Because of the sorting issue won't update the in its version. Keeps beta9 because it thinks it is newer. That is my issue.

@bfmsoft
Copy link
Author

bfmsoft commented Sep 29, 2020

I have to point directly to nuget.org and not the Devops server to update this package.

@egil
Copy link
Member

egil commented Sep 29, 2020

ok, yeah, sorry about the messed up version numbers. Ill close the issue then.

@egil egil closed this as completed Sep 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
input needed When an issue requires input or suggestions
Projects
None yet
Development

No branches or pull requests

1 participant