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" />
4
  • Have you tried making AutoMoqDataAttribute public? Jun 28, 2016 at 7:45
  • Yes same result. I tried to remove PrBatchEndorseBroker, add it back.. Always the same error
    – Seb
    Jun 28, 2016 at 7:49
  • 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. Jun 28, 2016 at 7:59
  • I have added packages
    – Seb
    Jun 28, 2016 at 8:06

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.