mardi 22 décembre 2015

unit test code for lambda expression when null (For null check code coverage)

I have a method or code like below where I am initializing the object obj which is input parameter as null for my rhino mock testing, and it throws error in the FirstOrDefault method that value can't be null.

private MTS Discount(IEnumerable<Type> obj)
        {
            var type = new MTS ();
            D_Type limit = obj.FirstOrDefault(x => x.Value.Value.Code == "NX" || x.Marry.Value.Name == "Once");
            if (limit != null)
            {
                type.Value = limit.Value;
                type.Name= limit.Name;
            }
            return type;
        }

How should I write the unit test for this. I am initializing obj as null but it throws error. I want for "NULL" check condition.

Aucun commentaire:

Enregistrer un commentaire