concept Customer in category c#

This is an excerpt from Manning's book Code like a Pro in C#.
Looking at figure 3.9, the
FlightandBookingtables are the only entities with foreign key relationships (two each). In theFlighttable,Flight.Originties toAirport.AirportID, and so doesFlight.Destination. In the Booking table,Booking.FlightNumberties toFlight.FlightNumber, andBooking.CustomerIDties toCustomer.CustomerID. Then, finally, there are theAirportandCustomertables, who have no outgoing foreign key relationships (they both have one incoming foreign key relationship). All four tables in the schema have a Primary Key, as denoted by the upright key icon.
In the previous chapter, we implemented the
CustomerRepositorywhere 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 aCustomerinstance 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
GetCustomerByNamemethod that returns an appropriateCustomerobject when given a string containing the customer’s name. As before, we use Test-Driven Development to ensure our code quality is adequate.
The returned Customerinstance is not null.The Customerinstance has valid data for theCustomerId, Name, andBookingfields.Those should be fairly simple assertions to write. Let’s assert that the returned
Customerinstance is not null:[TestMethod] public void GetCustomerByName_Success() { Customer customer = ➥await repository.GetCustomerByName("Linus Torvalds"); Assert.IsNotNull(customer); }Since C# is an explicitly typed language, when we request a
Customerinstance fromGetCustomerByName, the method likely throws an exception ifcustomeris null becausenullis not the expected type. Nevertheless, we should be on the safe side and check for it.