Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void AddPersonToPeopleList(List<PersonModel> people, PersonModel person)
- {
- CheckWhiteSpace(person.FirstName, "FirstName");
- CheckWhiteSpace(person.LastName, "LastName");
- people.Add(person);
- }
- public static void CheckWhiteSpace(string name, string paramName) {
- if (string.IsNullOrWhiteSpace(name)) {
- throw new ArgumentException("You passed in an invalid parameter", paramName);
- }
- }
- [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));
- }
- public static class StringExtensions{
- public static void CheckWhiteSpace(this string name, string paramName){
- if(string.IsNullOrWhiteSpace(name)
- throw new ArgumentException("You passed in an invalid parameter", paramName);
- }
- }
- person.FirstName.CheckWhiteSpace("FirstName")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement