Skip to content

Coding Standards

Eduardo Fonseca edited this page Oct 26, 2024 · 2 revisions

Coding Standards

Here you will find some documentation on the coding standards to follow for this specific project.

No harcoded values

We are actively trying to avoid the use of hardcoded values spread all around the code, instead, we have used the approach of a Constants class, in the Common project, any constant value needs to have a constant defined in some of the subclasses.

No member variables

As part of generating a differentiated code signature we are purposely avoiding having member variables prefixed with "_", instead class will have private properties named using PascalCase.

All class properties must be private.

Variables and properties names

The names of variables and properties must specify what the variable contents are: e.g. videosList, userVideos, etc.

API Endpoints

  • The methods must be named using a verb, e.g. "GetUserVideos"
  • The methods must always have the parameter CancellationToken cancellationToken, as the last parameter.
  • For small endpoints prfer using Minimal APIs.
  • The methods must always have the Http Verb Attribute, with "[action]", so that the endpoint is generated with the same name of the method:
    • [HttpPost("[action]")]
    • [HttpPut("[action]")]
    • [HttpDelete("[action]")]
    • [HttpGet("[action]")]

Accessing API Endpoints

  • use a ClientService class in the "{MainProject}.ClientServices" project, use the same prefix than the one used in the Controller for a name
  • Generate the client using Kiota.

Blazor Pages & components

  • Components that load data must have the "Loading" component so that the spinners are shown while data is being load.
  • Razor pages will have the following order
    • @page

    • @attribute

    • @implements

    • @using

    • @inject (of interfaces)

    • @inject (of classes)

    • Main html code

    • @code section

      Check FairPlayTube's Home Page

      image

SQL Tables

  • Tables must not contain more than 20 columns, if a table is about to reach that many columns, chances are many columns can be converted into an "AdditionalAttributes" kind of table.

Async Methods naming

  • All async methods( except the endpoints ) must be suffixed with Async
  • All aynsc methods must received a mandatory "CancellationToken cancellationToken" as the last parameter

Methods invocation

  • When invoking a method, used named parameters.

Testing Standards

  • No usage of mocking nor fakes libraries
  • Services tests classes will map 1 to 1, a test class for a test service
  • Services test methods will be named in the format "Test_{ServiceMethodName}"
  • Each test will create each of the required objects to pass to the service constructor
  • Each test will create all of the required data
  • Each Test class file will clean the test data through the [TestCleanup] methods
Clone this wiki locally