Unit testing an unspecific order of method calls I cannot figure out how I am supposed to unit test the implementation of GetFilteredEntites(IEnumerable&lt;MyEntity&gt; myEntities).

public class MyEntity
{
    public int Rank { get; set; }
    public int Points { get; set; }
}

public interface IMyMethodClass
{
    ICollection&lt;MyEntity&gt; RemoveBadRanking(IEnumerable&lt;MyEntity&gt; myEntities);
    ICollection&lt;MyEntity&gt; RemoveLowPoints(IEnumerable&lt;MyEntity&gt; myEntities);
}

public class MyMethodClass : IMyMethodClass
{
    public ICollection&lt;MyEntity&gt; RemoveBadRanking(IEnumerable&lt;MyEntity&gt; myEntities)
    {
        return myEntities.Where(m =&gt; m.Rank &gt; 100).ToList();
    }

    public ICollection&lt;MyEntity&gt; RemoveLowPoints(IEnumerable&lt;MyEntity&gt; myEntities)
    {
        return myEntities.Where(m =&gt; m.Points &lt; 500).ToList();
    }
}

public class MyTargetClass
{
    private readonly IMyMethodClass _myMethodClass;

    public MyTargetClass(IMyMethodClass myMethodClass)
    {
        _myMethodClass = myMethodClass;
    }

    public ICollection&lt;MyEntity&gt; GetFilteredEntites(IEnumerable&lt;MyEntity&gt; myEntities)
    {
        var a = _myMethodClass.RemoveBadRanking(myEntities);
        var b = _myMethodClass.RemoveLowPoints(a);
        return b;
    }
}

public class MyTestClass
{
    [Fact]
    public void Gets_No_Bad_Ranking_And_No_Low_Points()
    {
        var myEntities = new List&lt;MyEntity&gt;();
        var myMethodClass = Substitute.For&lt;IMyMethodClass&gt;();
        var target = new MyTargetClass(myMethodClass);
        var a = new List&lt;MyEntity&gt;();
        myMethodClass.RemoveBadRanking(Arg.Is(myEntities)).Returns(a);
        var b = new List&lt;MyEntity&gt;();
        myMethodClass.RemoveLowPoints(Arg.Is(a)).Returns(b);

        var filteredEntites = target.GetFilteredEntites(myEntities);

        Assert.Same(b, filteredEntites);
    }
}


The above code tests and requires GetFilteredEntites(IEnumerable&lt;MyEntity&gt; myEntities) to be implemented in a correct way. The following implementation is just as correct as the first one:

public ICollection&lt;MyEntity&gt; GetFilteredEntites(IEnumerable&lt;MyEntity&gt; myEntities)
{
    var a = _myMethodClass.RemoveLowPoints(myEntities);
    var b = _myMethodClass.RemoveBadRanking(a);
    return b;
}


The unit test I have wrote above requires the method calls to be in the right order, but this is not needed for the implementation to be correct. The second implementation of GetFilteredEntites(IEnumerable&lt;MyEntity&gt; myEntities) (right above here) will not pass the unit test I wrote.

How would you change the unit test of GetFilteredEntites(IEnumerable&lt;MyEntity&gt; myEntities), so the order of the method calls is not required to be in a specific order?
You're right, the way you're mocking the methods is tightly coupling the sequence of events, even though you don't really care about the order.  What you really care about is that given a list, both methods are called, with the input/outputs chained and the overall output is the list without the filtered items.  You can achieve this by rewriting your test:

public void Gets_No_Bad_Ranking_And_No_Low_Points()
{
    // Create three entities, one to be removed by each of the filter functions
    // and one to be left over, since checking for an empty list isn't conclusive
    var badEntity = Substitute.For&lt;MyEntity&gt;();
    var lowEntity = Substitute.For&lt;MyEntity&gt;();
    var remainingEntity = Substitute.For&lt;MyEntity&gt;();

    // put all of the created entities into the initial list
    var myEntities = new List&lt;MyEntity&gt;() { badEntity, lowEntity, remainingEntity };
    var myMethodClass = Substitute.For&lt;IMyMethodClass&gt;();
    var target = new MyTargetClass(myMethodClass);

    // When RemoveBadRanking is called, we match against any parameter of the correct type,
    // then we filter the supplied list to exclude the badEntity
    myMethodClass.RemoveBadRanking(Arg.Any&lt;IEnumerable&lt;MyEntity&gt;&gt;())
        .Returns(args =&gt; ((List&lt;MyEntity&gt;)args[0]).Where(e =&gt; e != badEntity).ToList());

    // Do the same thing, but for lowEntity
    myMethodClass.RemoveLowPoints(Arg.Any&lt;IEnumerable&lt;MyEntity&gt;&gt;())
        .Returns(args =&gt; ((List&lt;MyEntity&gt;)args[0]).Where(e =&gt; e != lowEntity).ToList());

    var filteredEntites = target.GetFilteredEntites(myEntities);

    // If both substitutes have been called, then the returned list should only
    // have the remainingEntity in it.
    Assert.AreEqual(1, filteredEntites.Count);
    Assert.AreSame(remainingEntity, filteredEntites.First());
}


Whether or not this is an improvement is a bit subjective... it's trading the added complexity of the test for the looser coupling.