How to combine PropertyData and AutoNSubstituteData attributes in xunit/autofixture?

后端 未结 3 1694
孤城傲影
孤城傲影 2021-01-05 08:47

I am using the [AutoNSubstituteData] attribute, which was posted here:

AutoFixture, xUnit.net, and Auto Mocking

I would like to combine this wit

3条回答
  •  醉话见心
    2021-01-05 09:02

    I have implemented an AutoPropertyDataAttribute that combines xUnit's PropertyDataAttribute with AutoFixture's AutoDataAttribute. I posted it as an answer here.

    In your case you will need to inherit from the attribute in the same way as you would from an AutoDataAttribute, with the exception that you pass a fixture creation function instead of an instance:

    public class AutoNSubPropertyDataAttribute : AutoPropertyDataAttribute
    {
        public AutoNSubPropertyDataAttribute(string propertyName)
            : base(propertyName, () => new Fixture().Customize(new AutoNSubstituteCustomization()))
        {
        }
    }
    

提交回复
热议问题