Hi everyone
was trying to do something like this:
public interface ICalculator
{
void Do(Person person);
}
public class Person
{
public int Age { get; set; }
}
[Test]
public async Task Test()
{
var calculator = Substitute.For<ICalculator>();
var person = new Person
{
Age = 1
};
calculator.Do(person);
person.Age = 2;
calculator.Do(person);
Received.InOrder(() =>
{
calculator.Received().Do(Arg.Is<Person>(x => x.Age == 1));
calculator.Received().Do(Arg.Is<Person>(x => x.Age == 2));
});
}
But this fails. It seems that: calculator.Received() remembers just last call, which is x.Age == 2
I know that can track the number and the values of the arguments myself, but was looking for a built-in functionality like this.
I know that NSub stores the references to the arguments. That's why it fails here - I am using the same Person object. For instance, the next one is working just fine:
[Test]
public void Tes()
{
var calculator = Substitute.For<ICalculator>();
var person = new Person
{
Age = 1
};
calculator.Do(person);
var person1 = new Person
{
Age = 2
};
calculator.Do(person1);
calculator.Received(2).Do(Arg.Any<Person>());
Received.InOrder(() =>
{
calculator.Received().Do(Arg.Is<Person>(x => x.Age == 1));
calculator.Received().Do(Arg.Is<Person>(x => x.Age == 2));
});
}
So I guess it's not really possible, cause NSub does the check as a last step against stored arguments. Or is there a way?