XUnit and AutoFixture Exception No Data found for (test name)
Asked Answered
S

1

8

I have a very simple test as shown below. I try to freeze my two dependencies using the AutoDataAttribute + AutoMoqCustomization.

class AutoMoqDataAttribute : AutoDataAttribute
{
    public AutoMoqDataAttribute()
        : base(new Fixture().Customize(new AutoMoqCustomization()))
    { }
}

public class PrBatchEndorseBrokerTest
{
    [Theory, AutoMoqData]
    public void Process_ValidContext_CallsK2Workflows(
        [Frozen]Mock<IK2Datasource> k2,
        [Frozen]Mock<IAppConfiguration> config,
        PrBatchEndorseBroker sut)
    {
        // Arrange
        var data = new Dictionary<string, object>
        {
            ["Workflow"] = @"KLPurchaseRequest\PR",
            ["Activity"] = "Endorser",
            ["ViewFormURL"] = "/Form/KLPurchaseRequestApproval.Form",
            ["PositiveOutcome"] = "Endorse",
            ["NegativeOutcome"] = "Reject"
        };

        // Act
        sut.Process();

        // Assert
        k2.Verify(x =>
            x.StartInstance(It.IsAny<string>(),
                            It.Is<Dictionary<string, object>>(d =>
                                data.Keys.All(k => d[k] == data[k])))
            , Times.Once());
    }
}

For some reasons, when i run this test, i'm getting the following error:

System.InvalidOperationException: No data found for BlackBox.Stakhanov.Broker.Test.PrBatchEndorseBrokerTest.Process_ValidContext_CallsK2Workflows

I tried many things and i can't make it work! I think i'm missing something big and probably obvious!

Packages I'm using:

<package id="AutoFixture" version="3.47.8" targetFramework="net452" />
<package id="AutoFixture.AutoMoq" version="3.47.8" targetFramework="net452" />
<package id="AutoFixture.Xunit" version="3.47.8" targetFramework="net461" />
<package id="Castle.Core" version="3.3.3" targetFramework="net461" />
<package id="Moq" version="4.5.10" targetFramework="net461" />
<package id="xunit" version="2.1.0" targetFramework="net461" />
<package id="xunit.abstractions" version="2.0.0" targetFramework="net452" />
<package id="xunit.assert" version="2.1.0" targetFramework="net461" />
<package id="xunit.core" version="2.1.0" targetFramework="net461" />
<package id="xunit.extensibility.core" version="2.1.0" targetFramework="net461" />
<package id="xunit.extensibility.execution" version="2.1.0" targetFramework="net461" />
<package id="xunit.extensions" version="1.9.0.1566" targetFramework="net461" />
Supereminent answered 28/6, 2016 at 7:5 Comment(4)
Have you tried making AutoMoqDataAttribute public?Kickapoo
Yes same result. I tried to remove PrBatchEndorseBroker, add it back.. Always the same errorSupereminent
Could you please list exactly which NuGet packages you're using? You can easily get a list with Get-Package from the NuGet Package Manager Console.Kickapoo
I have added packagesSupereminent
K
15

When using xUnit.net 2, you should use AutoFixture.Xunit2, not AutoFixture.Xunit.

You'll notice in your package list that you have xunit.extensions version 1.9.0.1566, which isn't compatible with xUnit.net 2.

Kickapoo answered 28/6, 2016 at 8:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.