Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. public static void AddPersonToPeopleList(List<PersonModel> people, PersonModel person)
  2. {
  3. CheckWhiteSpace(person.FirstName, "FirstName");
  4. CheckWhiteSpace(person.LastName, "LastName");
  5.  
  6. people.Add(person);
  7. }
  8.  
  9. public static void CheckWhiteSpace(string name, string paramName) {
  10. if (string.IsNullOrWhiteSpace(name)) {
  11. throw new ArgumentException("You passed in an invalid parameter", paramName);
  12. }
  13. }
  14.  
  15. [Theory]
  16. [InlineData("Mick", "", "LastName")]
  17. [InlineData("", "Adams", "FirstName")]
  18. public void AddPersonToPeopleList_ShouldFail(string firstName, string lastName, string param)
  19. {
  20. PersonModel newPerson = new PersonModel { FirstName = firstName, LastName = lastName };
  21. List<PersonModel> people = new List<PersonModel>();
  22.  
  23. Assert.Throws<ArgumentException>(param, () => DataAccess.AddPersonToPeopleList(people, newPerson));
  24. }
  25.  
  26. public static class StringExtensions{
  27. public static void CheckWhiteSpace(this string name, string paramName){
  28. if(string.IsNullOrWhiteSpace(name)
  29. throw new ArgumentException("You passed in an invalid parameter", paramName);
  30. }
  31. }
  32.  
  33. person.FirstName.CheckWhiteSpace("FirstName")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement