I have a method:
public static void AddPersonToPeopleList(List<PersonModel> people, PersonModel person)
{
CheckWhiteSpace(person.FirstName, "FirstName");
CheckWhiteSpace(person.LastName, "LastName");
people.Add(person);
}
That calls the helper methdod:
public static void CheckWhiteSpace(string name, string paramName) {
if (string.IsNullOrWhiteSpace(name)) {
throw new ArgumentException("You passed in an invalid parameter", paramName);
}
}
Which simply checks for null or white space in my string with the parameter name, and throws an exception if it does.
[Theory]
[InlineData("Mick", "", "LastName")]
[InlineData("", "Adams", "FirstName")]
public void AddPersonToPeopleList_ShouldFail(string firstName, string lastName, string param)
{
PersonModel newPerson = new PersonModel { FirstName = firstName, LastName = lastName };
List<PersonModel> people = new List<PersonModel>();
Assert.Throws<ArgumentException>(param, () => DataAccess.AddPersonToPeopleList(people, newPerson));
}
My test is designed to simply make sure an exception is thrown if either the first name or second name is empty.
My question is whether I need to also make a test for the helper method I used (CheckWhiteSpace) or whether the test I've made takes care of testing the functionality of that helper method and my original method?
Aucun commentaire:
Enregistrer un commentaire