jeudi 26 novembre 2015

Unit Test & try catch for method returning a list of objects c#

I have the following method in my WCF service. I need to do a unit test for it, but am unsure how to do this since it returns a list of objects Mountain.

The method takes in a grid reference e.g. NN - and searches the list mountslist for those mountains with grid reference starting with NN.

Also can anyone help me as to how I can do a try catch for this? I am confused as to what to return since it expects a Mountain object. (If not found return - mountain not in list for example).

    public IEnumerable<Mountain> GetMountainLoc(string mtloc)
{

IEnumerable<Mountain> resultMts = mountsList.Where(x => x.Grid_ref.Substring(0, 2) == mtloc).ToList();
return resultMts;

}

Aucun commentaire:

Enregistrer un commentaire