public void Delete(Customer customer) { var command = new SqlCommand(CustomerRepoScript.Delete); command.Parameters.Add("@Email", SqlDbType.NVarChar, 100).Value = customer.Email; Execute(command, () => command.ExecuteNonQuery()); }
public void Save(Customer customer) { var command = new SqlCommand(CustomerRepoScript.Save); command.Parameters.Add("@Email", SqlDbType.NVarChar, 100).Value = customer.Email; command.Parameters.Add("@FirstName", SqlDbType.NVarChar, 100).Value = customer.FirstName; command.Parameters.Add("@LastName", SqlDbType.NVarChar, 100).Value = customer.LastName; Execute(command, () => command.ExecuteNonQuery()); }
public Customer GetWithEmail(string email) { var command = new SqlCommand(CustomerRepoScript.GetWithEmail); command.Parameters.Add("@Email", SqlDbType.NVarChar, 100).Value = email; Customer customer = null; Execute(command, () => ForEach(command.ExecuteReader(), (reader) => customer = new Customer(reader.GetString(0), reader.GetString(1), reader.GetString(2)))); return customer; }
public void Repos_should_patch_the_db_when_they_are_instantiated() { var repo = new CustomerRepo(TestConnectionString); var joe = new Customer("*****@*****.**", "joe", "blogs"); repo.Save(joe); var retrievedCustomer = repo.GetWithEmail("*****@*****.**"); Assert.IsTrue(joe.Email == retrievedCustomer.Email); retrievedCustomer = repo.GetWithFirstName("joe").SingleOrDefault(); Assert.IsTrue(joe.Email == retrievedCustomer.Email); retrievedCustomer = repo.GetWithLastName("blogs").SingleOrDefault(); Assert.IsTrue(joe.Email == retrievedCustomer.Email); retrievedCustomer = repo.GetWithLastName("nobody").SingleOrDefault(); Assert.IsNull(retrievedCustomer); }