Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to .NET Core v3.1 (and many, many other things!) #17

Merged
merged 45 commits into from
Jul 27, 2020
Merged

Conversation

maacpiash
Copy link
Owner

  • Add proper CI/CD
  • Add E2E tests
  • Add mocks for tests
  • Improve test coverage
  • Add docs
  • Add scripts for tests and coverage
  • Add logging for ReST API controllers
  • Refactor, formatting, linting

Ahad Chowdhury and others added 30 commits January 9, 2020 03:44
Difference from `v3.1-lts` branch: in this branch the structure will not
change much. The app will remain monolithic (hence the branch name) with
typical Razor pages. There will be two Blazor components in two pages.

WIP.
Prior to this change, comparison elements in `Inputs` page were
hard-coded for each criterionm, along with the IDs of the elements.

This change leverages the goodness of Razor syntax by looping through
the criteria and generating HTML elements for each of them.
- Gitignore is fixed: unnecessary lines are removed.
- Stickers for build status (GitHub Actions) in readme are added.
- SDK version is updated in readme, global.json files and CI/CD configs.
- Some packages in csproj file of the test project have been upgraded.
- Branches are specified.
- Codecov support is added.
- Travis and AppVeyor files are removed.
TODO: fix e2e tests for ReST API endpoints
- Update end year in footer of page layout
- Add relevant badges and remove unnecessary ones in Readme
Also, formatting is fixed in two test files.
From now on, with every push of commits, CI/CD will run on Travis (on
Ubuntu and macOS) and AppVeyor (on Windows). Each pipeline will build
both projects and run unit tests. After that, Travis will deploy the app
on Heroku; and AppVeyor will collect unit test coverage and upload it on
Codecov, and then deploy the app on Azure App Service.

GitHub Actions are removed, since running more than two CI/CD pipelines
seem unnecessary.
It was also removed from its implementations.
- Configurations of helper scripts for VS Code have been added.
- Version of .NET Core SDK has been upgraded for both projects.
Prior to this change, in order to access the browser session, page
models directly called `HttpContext.Session.Get[type]()` methods.

This change adds dependency injection of `HttpContextAccessor` from
Startup to the three main page models to achieve the same result.
However, this is more streamlined, and easier to test by mocking.
Moq library was used to mock IHttpContextAccessor. A mock session class,
`MockSession`, was used as the drop-in session property of the mocked
object.

This commit also enables the tests that used to be skipped on CI/CD.
- `SchoolService` is excluded from coverage (by filename).
- 'Analysis' and 'Error' pages are included in E2E (page load) test.
- Badges for Docker pulls and .NET Core SDK version are removed.
- A badge linking to the Docker image on Docker Hub is added.
- Code Climate maintainability (percentage) badge is added,
- For each badge link, `target="_blank"` is added.
Prior to this change, the responsibility of accessing the database was
carried out by a Node.js application deployed as a ReST API on Heroku
(see my project `konschool-mlab-host` on GitHub). It was set up in this
way due to issues with the old MongoDB driver and/or mLab. With this set
up, `SchoolService` would make a GET request to that app to get all the
details of the schools (responses were parsed with `Newtonsoft.Json`).

This change implements `SchoolService` with MongoDB driver, so that this
app can connect directly with MongoDB Atlas (switched from mLab), with a
few environment variables.

This commit undoes part of what 50f8f8e had done.
- Mock classes are now in a separate folder with a separate namespace.
- Mock objects are now injected in unit/e2e tests when necessary.
- Conditional DI of ISchoolService in Startup is removed.
The `.env` file should be at the root directory with the `sln` file.

Also, logger is added via DI for logging info and errors.
ApiControllerTests were failing due to e537857.
The research paper is added. The areas of optimization will be added to
and explained in the readme file later.
- Link to docs directory is fixed.
- Badge for Travis CI is shortened.
These tests check whether the values are set according to inputs.
The script runs the unit tests via OpenCover, which also generates a
report in XML format. Then some HTML files are generated by parsing the
XML file, which are then served by `dotnet serve` tool.

The script is pretty self-explanatory. It depends on a few CLI tools:
xUnit, OpenCover (portable), codecov. These are available on Chocolatey.
It also requires a .NET Core global tool (which can be installed via
.NET Core CLI): `dotnet-reportgenerator-globaltool`. These are explained
in the script in the comments at the top.

The script is, unfortunately, for Windows only. This is due to OpenCover
being available only for Windows. I have tried some cross-platform
coverage tools (for example, @coverlet-coverage), but was not satisfied.
The problem with Coverlet is that after generating coverage for tests
covering multiple namespaces, it calculates the coverage by calculating
the simple arithmetic mean — not a weighted arithmetic mean, which would
take the number of LOC of each namespace into account.
This is due to OpenCover generating inconsistent reports: some LOCs were
shown not covered by tests, despite actually being covered. For example,
some edge cases in Models were covered by 0846e27 — but the coverage did
not go up for some unknown reason(s).

The global CLI tool, `coverlet.console`, has been used for this project.

There are now separate scripts for generating reports and uploading test
coverage — for Windows and Unix-like platforms.
Also, linting/formatting CI/CD yml files.
@codecov
Copy link

codecov bot commented Jul 27, 2020

Codecov Report

Merging #17 into master will increase coverage by 34.10%.
The diff coverage is 97.43%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master      #17       +/-   ##
===========================================
+ Coverage   61.06%   95.17%   +34.10%     
===========================================
  Files          31       29        -2     
  Lines         637      622       -15     
  Branches      127      103       -24     
===========================================
+ Hits          389      592      +203     
+ Misses        235       19      -216     
+ Partials       13       11        -2     
Impacted Files Coverage Δ
src/Pages/About.cshtml.cs 100.00% <ø> (+100.00%) ⬆️
src/Pages/Contact.cshtml.cs 100.00% <ø> (+100.00%) ⬆️
src/Pages/Error.cshtml.cs 80.00% <ø> (+80.00%) ⬆️
src/Pages/Privacy.cshtml.cs 100.00% <ø> (+100.00%) ⬆️
src/Pages/Shared/_Layout.cshtml 33.33% <ø> (+33.33%) ⬆️
src/Program.cs 62.50% <83.33%> (+62.50%) ⬆️
src/Startup.cs 74.41% <86.66%> (+74.41%) ⬆️
src/ApiControllers/FAHPController.cs 100.00% <100.00%> (ø)
src/ApiControllers/SchoolsController.cs 100.00% <100.00%> (ø)
src/Models/Inference.cs 100.00% <100.00%> (+4.34%) ⬆️
... and 28 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9bc6d38...8546eea. Read the comment docs.

@maacpiash maacpiash merged commit 3c3f441 into master Jul 27, 2020
@maacpiash maacpiash deleted the v3.1-mono branch July 27, 2020 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant