public void FindCustomersTestBlankString() { // Arrange CustomerRepository target = new CustomerRepository {new Customer() { CustomerId = 1, FirstName="Rosie", LastName = "Cotton", EmailAddress = "*****@*****.**"}, new Customer() { CustomerId = 2, FirstName="Bilbo", LastName = "Baggins", EmailAddress = "*****@*****.**"}, new Customer() { CustomerId = 3, FirstName="Frodo", LastName = "Baggins", EmailAddress = "*****@*****.**"}}; string customerName = " "; List<Customer> expected = null; // Act var actual = target.FindCustomers(customerName); // Assert Assert.AreEqual(expected, actual); }
public void FindCustomersTestValidString() { // Arrange CustomerRepository target = new CustomerRepository {new Customer() { CustomerId = 1, FirstName="Rosie", LastName = "Cotton", EmailAddress = "*****@*****.**"}, new Customer() { CustomerId = 2, FirstName="Bilbo", LastName = "Baggins", EmailAddress = "*****@*****.**"}, new Customer() { CustomerId = 3, FirstName="Frodo", LastName = "Baggins", EmailAddress = "*****@*****.**"}}; string searchString = "agg"; List<Customer> expected = new List<Customer> {new Customer() { CustomerId = 2, FirstName="Bilbo", LastName = "Baggins", EmailAddress = "*****@*****.**"}, new Customer() { CustomerId = 3, FirstName="Frodo", LastName = "Baggins", EmailAddress = "*****@*****.**"}}; // Act var actual = target.FindCustomers(searchString); // Assert TestContext.WriteLine(searchString); Debug.WriteLine("Using Debug: " + searchString); Assert.AreEqual(expected.Count, actual.Count); foreach (Customer item in actual) { TestContext.WriteLine(item.ToString()); // Find the item in the expected list Customer expectedItem = expected.FirstOrDefault(c => c.CustomerId == item.CustomerId); Assert.AreEqual(expectedItem.LastName, item.LastName); Assert.AreEqual(expectedItem.FirstName, item.FirstName); Assert.AreEqual(expectedItem.EmailAddress, item.EmailAddress); } }