Building a ProductMicroservice project and intergate it with some new technologies.
- Integration of GraphQL in this project
- Running unit test and watching code coverage
You need to install some require external packages for GraphQL as the following:
To getting started with GraphQL in ASP .NET Core, visit the GraphQL ASP.NET Core Tutorial
To test our GraphQL API, we are going to use the GraphQL.UI.Playground tool. So, let's first start our server application and then navigate to the http://localhost:60809/ui/playground address.
Excellent, we see that everything is working just as it supposed to. As soon as we send our query with id, name, and price of products (which must match the query name we created in the AppQuery file), we get the required result.
You need to some require external nuget packages. Install Converlet and FluentAssertions for your project using the following cli commands.
- dotnet add package coverlet.msbuild --version 2.7.0
- dotnet add package FluentAssertions --version 5.0.0
To get converlet to collect code coverage for your codebase, we need just to run the following command at the repository root.
dotnet test ProductMicroservice.UnitTests.csproj /p:CollectCoverage=true /p:CoverletOutputFormat=\"opencover\" /p:CoverletOutput=BuildReports\Coverage\
The result will be collected in a coverage.coverlet.xml file in the ProductMicroservice.UnitTests directory.
If you want to generate report, you can also install the following command.
- dotnet tool install -g dotnet-reportgenerator-globaltool
- dotnet test ProductMicroservice.UnitTests.csproj /p:CollectCoverage=true /p:CoverletOutputFormat=\"opencover\" /p:CoverletOutput=BuildReports\Coverage\
- reportgenerator "-reports:BuildReports\Coverage\coverage.opencover.xml" "-targetdir:BuildReports\Coverage" -reporttypes:HTML;HTMLSummary
Once you run commands is completed then open index.html file in BuildReports\Coverage will display as image below.