المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : VS 2008 Unit Testing Null Exception Error



C# Programming
04-02-2009, 06:07 AM
Hi,

I am attempting to unit test some code i have written. Unfortunately I am having an issue when using a generic list of an object type I have defined. I'm basically checking to see that this list is equal to 0 and if it is return false. However when the check is performed I get a null exception error. Below is an example (not exact code) of the code I'm trying to test and the bold and underline is where i'm receiving the error. Thanks in advance to all that reply.

private Car _car = new Car();

//constructor
public CarValidation(Car carDetails)
{
if (carDetails == null)
throw new ArgumentNullException();
else
_car = carDetails;
}

public bool CheckForValues()
{
bool valid = true;

if(_car.OilPressure == null)
valid = false;

if (_car.TirePressure == null)
valid = false;

if (_car.GasAmount == null)
valid = false;

if (_car.Mp3SongsLoaded.Count == 0)
valid = false;

return valid;
}