MarcolinoPT/Xunit.Repeat

Repeat with automoq

Opened this issue · 2 comments

I was searching for a repeat attribute and I found yours very intereseting.

The thing is it only works for Fact tests.
I am using Autofixture with Moq and a AutomoqDataAttribute so all tests are magically Moq by the test. http://blog.nikosbaxevanis.com/2012/07/31/autofixture-xunit-net-and-auto-mocking/
The thing is, Repeat attribute does not care about the autofixture and only the first run fills the inline parameters.
I have tried to modify the code so it handles this but I was not able to do it.

I think that would be a very good upgrade.

Finally I did it like this:

`

public sealed class RepeatAttribute : AutoDataAttribute
{
    private readonly int _count;

    /// <summary>
    /// Initializes a new instance of the <see cref="RepeatAttribute"/> class.
    /// </summary>
    /// <param name="count">Count number. Number of times to repeat the test.</param>
    public RepeatAttribute(int count) : this(count, new Fixture())
    {
    }

    /// <summary>
    /// Initializes a new instance of the <see cref="RepeatAttribute"/> class.
    /// </summary>
    /// <param name="count">Count number. Number of times to repeat the test.</param>
    /// <param name="fixture">The fixture.</param>
    public RepeatAttribute(int count, IFixture fixture)
        : base(() => fixture
            .Customize(new AutoMoqCustomization { GenerateDelegates = true }))
    {
        const int minimumCount = 1;

        if (count < minimumCount)
        {
            throw new ArgumentOutOfRangeException(
                paramName: nameof(count),
                message: "Repeat count must be greater than 0."
            );
        }

        _count = count;
    }

    public override IEnumerable<object[]> GetData(MethodInfo testMethod)
    {
        foreach (var iterationNumber in Enumerable.Range(start: 1, count: _count))
        {
            var result = base.GetData(testMethod).ToArray();
            yield return result[0];
        }
    }
}

`

My only issue now is for frozen attributes, I have to take care in the test to reset them.

Hi @dilandau2001, sorry for the long delay on my reply, could you provide a PR for this feature?

I am currently busy and will only have time to look at this mid November.