Using design patterns like Unit of work, repositories, database migrations, Dependency Injection, Unit testing using XUnit
-
The first step is change the connection string for sql server database. The steps for doing it are the following:
- Open the solution project with your favorite editor(I use for perform this API Visual Studio 2019 Community).
- You can find two projects inside => fundsAPI and XunitFundsAPI. Display fundsAPI and in the root you can finde the file called "appsettings.json". Deploy this file and open "appsettings.development.json".
- In this configuration file you need to change the property default of the connectionStrings with your own sql sever connection string.
-
If your are using Visual Studio
- Go to Tools -> Nuget administrator packages -> Package Manager Console and execute "Update-Database" without quotes. With this your setting up the table using Microsoft migrations.
- In case your are not able to do it or something fails. In the solution fundsAPI in the folder Migrations -> SqlScripts you can find the createDatabase.sql script in order to create the database.
-
Seed the Database
- In folder Migrations -> SqlScripts you can find two scripts AddFundData.sql and AddFundsValueData.sql please after the creation of the database, execute this scripts in order, first addfundsData and after finish addfundsValueData.
- This scripts has the funds data 10000 register every script and are in separated files for avoid problems with time execution.
-
Execute the Application
- For execute the app in a development environment please being sure you put fundsAPI as run project and not use IISExpress.
- For configure that in visual studio in the toolbar you can change to fundsAPI and click it.
-
Testing the app
- The app will start at the next route "https://localhost:5001" you can see the url in the console display after start the app.
- To help with the documentation the project has added swagger documentation. You can find it in the following route:
- If you prefer use postman you can find a exported postman collection in the root of the repository.
- You can launch the unit test for the app clickin with right mouse in the XunitFundsAPI and select Run tests.