7 Comparing objects
This chapter covers
- Implementing the GetCustomerByName method
- Viewing methods through the lens of lambda calculus
- Using nullable types
- Using custom Exceptions
- Operator overloading and custom equality comparisons
In the previous chapter, we implemented the CustomerRepository where we can add a customer to the database. We also learned how to use dependency injection to write testable code. This is a splendid start, but we are not done yet. We can add a Customer instance to the database, but how about retrieving one?
Figure 7.1 In this chapter, we continue the implementation of the CustomerRepository we started in chapter 6. This is the first step in implementing all the repositories for the Flying Dutchman Airlines service.
In this chapter, we create the GetCustomerByName method that returns an appropriate Customer object when given a string containing the customer’s name. Implementing this method allows us to touch on some technical concepts we may have missed otherwise. As before, we use Test-Driven Development “Lite” to ensure our code quality is adequate.
7.1 The GetCustomerByName method
To get started, let’s create a new unit test that does absolutely nothing besides an attempt to call our new (not yet created) method:
[TestMethod]
public async Task GetCustomerByName_Success() {
Customer customer =
[CA] await _repository.GetCustomerByName("Linus Torvalds");
}