Skip to content

robert-shattock/Pets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview of Solution

This solution is intended to solve the requirements of the AGL developer test as per http://agl-developer-test.azurewebsites.net/ but in summary is a simple example of a website consuming a web service, manipulating the data and displaying it. The idea is to showcase some best practices and to follow common design principles like separation of concerns.

The focus of the solution is on the backend with just a simple frontend to show the output.

The solution is split into three projects:

  • Pets.UI - Front end with basic MVC template
  • Pets.Application - Contains back end PeopleService for retrieving a list of people and their pets from an external API.
  • Pets.Test - Contains tests for the solution. Only contains tests for the UI read service because the service in the application layer that retrieves data has an external dependency and doesn't actually have any business logic so there isn't much point testing it.

The technology chosen is as follows:

  • Pets.UI project targets .NET Core 3.1 and uses ASP.NET Core 3.1 (TODO terminology might need some work here... target vs framework vs metapackage vs project template)
  • Pets.Application targets .NET Standard 2.0 for maximum compatability with other projects
  • Pets.Test targets .NET Core 3.1 as it is testing functionality in the Pets.UI project which targets .NET Core 3.1

The CI/CD and hosting is as follows:

  • Azure DevOps - Used for CI/CD - every commit to master triggers the CI (build, run unit tests and package) and CD (deploy to Azure)
  • Azure App Service - https://petswebsite.azurewebsites.net/ (Resource group in Azure, containing an App Service Plan and App Service)

Details of considerations while developing each layer:

Pets.UI project

Startup.cs

HomeController.cs

CatsReadService.cs

  • GetCatOwnersViewModel retrieves the data for and constructs the view model for the HomeController Index action. It keeps the logic out of the controller and doesn't reside in the Pets.Application project because it has view related concerns.
  • For readability the LINQ query is split into two queries.
  • While gender order was not specified in the requirements everything should have a defined and reproduceable order, so the assumption I've gone with is to list genders alphabetically.

Pets.Application project

PeopleService.cs

  • TODO Probably just leave the interface in the application layer and the implementation in new Infrastructure layer since there is no actual business logic - just a straight retrieval of people.

Pets.Test project

  • NUnit used as testing framework - solid framework that's been around. Could have also considered XUnit among others.
  • Moq was used for mocking of the PeopleService during testing
  • The PeopleService had no logic and so isn't being tested, just the CatsReadService.
  • The main thing to test is that the requirements are being met i.e. how the data is being filtered, grouped and ordered, and how cases like no data are handled etc.
  • TODO For readability could have considered a library like Shouldly or Fluent Assertions to get more natural sounding assertion statements.
  • TODO Add some links to unit testing best practice

Further considerations:

  • Integration tests for PeopleService perhaps.
  • Polly to give more robustness to HTTP requests (timeout handling, retries etc).
  • etc.

Azure DevOps

  • There are plenty of options for dev ops and CI/CD e.g. Azure DevOps, TeamCity, Jenkins, GitHub Actions etc. but I've chosen Azure DevOps to keep as much in the Microsoft stack as possible, making for easier integrations between source code (GitHub), dev ops (Azure DevOps) and deployment (Azure App Service). https://docs.microsoft.com/en-us/azure/devops/learn/what-is-devops
  • Regardless of tools used, setting up CI/CD even for a small project helps ensures code quality by automatically running a build and tests for every checkin and saves time and money by automating the deployments (and rollbacks if required) whether they be manually or automatically triggered. https://nevercode.io/blog/what-is-continuous-integration-and-how-to-benefit-from-it/
  • The Azure DevOps pipelines for build and release setup for this project have been built with standard pipeline tasks https://docs.microsoft.com/en-au/azure/devops/pipelines/ecosystems/dotnet-core?view=azure-devops.
  • The build pipeline is triggered by any commit into master branch of the GitHub repository. The process has been simplified - for any production system I'd following something like GitFlow or GitHub Flow (depending on complexity of system and versioning requirements etc) https://nvie.com/posts/a-successful-git-branching-model/ https://guides.github.com/introduction/flow/. The main thing is that any change should have a pull request ideally associated with it to maintain code quality.
  • The automated tests are run in the CI via the Visual Studio Tests task "VSTest@2". I had to make two changes to get this working correctly 1) set it to target the .NET Core 3.1 framework via otherConsoleOptions (it is meant to pick up the target framework of the test project but for some reason this wasn't working) and get it to explicity target the test project DLL (the default DLLs were too broad and it was trying to run tests on non-test DLLs).
  • The release pipeline is triggered by any successful build pipeline completing (it uses the zip file build artificat from the build pipeline) and deploys to a website hosted in Azure as an App Service.

Azure App Service

  • Azure Service Plan - I've used a Windows host for the Azure Service Plan hosting the App Service but could have chosen Linux to probably save some money without any major issues given we're using .NET Core.
  • Azure App Seervice - https://petswebsite.azurewebsites.net/ (Resource group in Azure, containing an App Service Plan and App Service)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published