10 Reflection and mocks

 

This chapter covers

  • A refresher on using the repository/service pattern and views
  • Testing with mocks using the Moq library
  • Detecting coupling in multilayered testing architectures
  • Using preprocessor directives
  • Using reflection to retrieve assembly information at run time

In chapters 6 through 9, we implemented the repository layer of our FlyingDutchmanAirlinesNextGen project. In this chapter, we’ll refresh our knowledge of the repository/service pattern and implement (partially) two of the four following required service classes:

  • CustomerService (implemented in this chapter)
  • BookingService (implemented in this chapter and chapter 11)
  • AirportService (implemented in chapter 12)
  • FlightService (implemented in chapter 12)

Figure 10.1 shows where we are in the scheme of the book.

Figure 10.1 This chapter is the start of the service layer implementation. We’ll implement CustomerService and BookingService in this chapter. In the following chapters, we’ll implement AirportService and FlightService.

As you may have guessed, as with the repository classes, we want one service class per database entity. We’ll discuss why in section 10.1, followed by the CustomerService implementation in section 10.2 and the start of the BookingService implementation in section 10.3.

10.1 The repository/service pattern revisited

10.1.1 What is the use of a service class?

Exercises

10.2 Implementing the CustomerService

10.2.1 Setting up for success: Creating skeleton classes

10.2.2 How to delete your own code

Exercises