chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
I have a List<Car> cars that is a member of a Dealer class

the Dealer class has a GetCarsOrderedByMeanPrice():

public List<Car> GetCarsOrderedByMeanPrice()
{
return cars.OrderedBy(car=>car.MeanPrice).ToList();
}

I want to mock the MeanPrice property, but have it return a different value for each consecutive car as to get a sorted List<Car>.

How?
asked by aner (600 points)

1 Answer

0 votes
Hi aner,

Is Cars a field or a property? If it is a property you can replace it with an alternate list for the purpose of this test:

var underTest = new Dealer();
Isolate.WhenCalled(() => underTest.Cars).WillReturn(
       new List {new Car { MeanPrice = 20, Name = "a" }, new Car { MeanPrice = 10, Name = "b" }});

var result = underTest. GetCarsOrderedByMeanPrice();

Assert.AreEqual("b", result[0].Name);
Assert.AreEqual("a", result[1].Name);


Please let me know if this helps.

Thanks,
Doron
Typemock support
answered by doron (17.2k points)
...