PacktPublishing / Architecting-ASP.NET-Core-Applications-3E

Architecting ASP.NET Core Applications, 3E_published by Packt
MIT License
39 stars 15 forks source link

About the class design #3

Open sheng0321 opened 1 month ago

sheng0321 commented 1 month ago

Architecting-ASP.NET-Core-Applications-3E/C02/test/MyApp.IntegrationTests/Controllers /HelloWorldControllerTest.cs In the file. the inner class is inherited from its outer class. This may lead to confusion and maintenance challenges. how about using an abstract class instead of the outer class?

Carl-Hugo commented 1 month ago

Hi @sheng0321,

Thanks for opening this issue. Can you please describe the maintenance challenges you are referring to?

Meanwhile, inheriting from the HelloWorldControllerTest class enables subclasses to access the non-static members of the superclass, like the _httpClient field. This setup also allows arranging base dependencies (or an HTTP client in this case) once for all test cases. This is a very useful pattern for pushing plumbing code up the inheritance stack, initializing mocks once, etc.