chapter ten
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 multi-layered testing architectures
- Using the
InternalsVisibleTomethod attribute - Using preprocessor directives
- Using reflection to retrieve assembly information at runtime
In chapters 6 through 9, we implemented the repository layer of our FlyingDutchmanAirlinesNextGen project. In this chapter, we refresh our knowledge of the Repository/Service pattern and implement (partially) two of the four required service classes:
CustomerService(implemented in this chapter)BookingService(implemented in this chapter and chapter 11)AirportService(implemented in chapter 12)FlightService(implemented chapter 12)
Figure 10.1 This chapter is the start of the Service layer implementation. We implement CustomerService and BookingService in this chapter. In the following chapters, we implement AirportService and FlightService.
As you may have guessed, as with the repository classes, we want one service class per database entity. We 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.