Step 12- Enhancing and Testing the Customer Object
In this step you will enhance the Customer business object so it can retrieve Customer entities, and create a unit test for the class.
- In the Solution Explorer under the Customer node, click the Customer.Partial.cs file to open it for code editing.
- Add the following method below the HookConstructor() method:
/// <summary> /// Gets customers that match the partial customerID string /// </summary> /// <param name="customerID">Partial or full customerID string</param> /// <returns>List of Customer entities that match the search criteria</returns> public mmBindingList<CustomerEntity> GetCustomersLikeCustomerID(string customerID) { IQueryable<CustomerEntity> query = from customer in this.ObjectContext.CustomerEntities where customer.CustomerID.StartsWith(customerID) select customer; return this.GetEntityList(query); }
The LINQ statement in this method uses the String.StartsWith() method to find all customers whose CustomerID starts with specified characters. Behind the scenes, this LINQ query results in the following SQL statement that uses the LIKE operator (in this example, the letter "Q" is specified as the customerID parameter):
SELECT *
FROM dbo.Customers
WHERE CustomerID LIKE [Q%] - To test this method, add the following method to the OrderSystemTests class in the unit test project:
[TestMethod] public void TestGetCustomersLikeCustomerID() { Customer c = new Customer(); mmBindingList<CustomerEntity> CustomerList = c.GetCustomersLikeCustomerID("Q"); Assert.IsTrue(CustomerList.Count > 0); }
- Set a breakpoint in the first line of code in this method, then press F5 to rebuild your business object project. In the Test Explorer, right-click the TestGetCustomersLikeCustomerID method and select Debug Selected Tests from the shortcut menu. This should cause you to hit the breakpoint at the top of the method:

- Press F10 to instantiate the Customer business controller object, then press F10 again to return a strongly typed list of CustomerEntity objects. If you hover your mouse pointer over the CustomerList property then click the + sign on the popup you should see a list of entity objects that were returned:

- Press F5 to finish executing the method. This should add a green check mark next to the TestGetCustomersLikeCustomerID method in the Test Explorer.
© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 02/10/26
Comment or report problem with topic
