Monday, April 23, 2018

ASP.Net Core 2 with Postgresql on Linux Part 8: The Controller Layer

In Part I, I discussed the rationale for porting a ASP.Net Core 2 app to my Linux system replacing SQL Server with Postgresql and place it on Heroku. 

With Part II, we transferred the SQL Server data to Postgres.


In Part III, I create the ASP.Net MVC Core 2.x app, from which we will proceed, and get Entity Framework Core installed.


Then in Part IV, I look at the configuration differences between the ASP.Net MVC app that uses SQL Server and the new app, in preparation of porting the old app to use Postgresql.

Part V, we compared the differences in both the projects' structures and ported the existing project code, starting with the data model layer, to the new project. In addition to this, we got the jquery.countdown jquery plugin installed, that is used to implement a JavaScript timer. More on that in a later article. Finally, we used the dotnet ef dbcontext scaffold command that builds a DbContext and entity types for out Postgresql database. And, oh yes, we added the project to github, which frankly should have been done day one.


In Part VI, we got the NUnit testing framework in place 
in order to test both the new and future code.


In Part VIIwe got the Service layer setup along with its unit tests.

In this post, we will import the Controller classes from the existing app and setup unit tests for them.

Here is look at the existing and new Controller folders from Beyond Compare:



First, I copied the existing Controller classes to the new app and then updated the namespace settings as well as adjusted other dependencies. With that done, the Controller classes are moved.


Then, I created unit tests for the main Controller methods. Instead of displaying the code in a screen shot, go to the unit tests github repository to see them all. Moreover, to see the corresponder Controller classes go here to the github repo.

With that done, the next post, Part IX, will detail the migration of the Razor (*.cshtml) files as well as the associated JavaScript, Cascading Style Sheet (CSS), and image files from the existing ASP.Net MVC app to the new app.




No comments: