C# • Retrieve Customer Rows

Listing 4. This test ensures that you can retrieve a list of Customer rows from the database and that they are mapped correctly into customer domain objects. It makes use of new features in Visual Studio 2005 that can run automated unit tests from within the IDE.

[Test]
        public void ShouldBeAbleToGetAllCustomers()
        {
                using (new TransactionScope())
                        {
                        TestDatabaseGateway gateway = new 
                                TestDatabaseGateway();

                //Get a count of existing customers in the database 
                int existingCustomerRows = 
                        gateway.GetRowCountFor("Customers");

// insert a new customer row into the database
                string sql = "INSERT INTO Customers 
                        VALUES('BOODH','Boodhoos Beverages','Jean-Paul 
                        Boodhoo','Sales Representative','Fauntleroy 
                        Circus','Canada',NULL,'EC2 5NT','UK','(171) 555-
                        1212',NULL)";
                        gateway.ExecuteStatement(sql);

                IList<Customer> customers = new 
                        CustomerMapper().GetAllCustomers();

//ensure that we get all the customers as well as the one just inserted
         Assert.AreEqual(existingCustomerRows + 1, customers.Count);
                }
        }