I have a list of object like below
public class Person
{
public string Name {get; set;}
public int Age {get; set;}
}
public class SomeClass
{
public int DoSomething ()
{
int result;
List<Person> personList = new List<Person>();
personList.Add(new Person { //with 1 object, just to keep simple
Name = "Someone",
Age = 18});
Person eighteenYearsOld = _checkAge.FindEighteenYearsOld (personList);
int index = personList.IndexOf (eighteenYearsOld);
//do something
return result;
}
}
[TestMethod]
public void DoSomething_Test()
{
//Given:
//When: I call SomeClass object
Person eightnneYears = new Person {
Name = "Someone",
Age = 18};
_mockCheckAge.Setup (x => x.FindEighteenYearsOld(It.IsAny<List<Person>>())).Returns(eightnneYears);
_someClass = new SomeClass (_mockCheckAge.Object);
int result = _someClass.DoSomething();
//Then:
}
As I have mocked the FindEighteenYearsOld
method it returns a Person
object with same states which is presents in the personList
. But when personList.IndexOf()
executes it returns index -1, which is suppose to be 0. What should I do.