Skip to content

API in .NET 8 with unit tests, automation tests, CI

Notifications You must be signed in to change notification settings

jeffdev7/products-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Products API

A simple API with all the CRUD operations with In-Memory database.

API Documentation

Endpoints

api-endpoints

/api/product

GET

  • Retrieve All Products
    • Description: Retrieves a list of all products.
    • Response:
      • Status: 200 OK
      • Body: An array of ProductViewModel objects.

Example:

OK

get-products

POST

  • Creates a new product.
    • Description: Creates a new product.
    • Response:The created ProductViewModel object with a unique id.
      • Status: 201 Created if successful.
      • Status: 400 Bad Request with problem details.
      • Body: A ProductViewModel object with the product details.

Example:

Created

add-product-201

Bad Requesterror-add-product

/api/product/{id}

GET

  • Retrieves a product.
    • Description: Retrieves the details of a specific product by its ID.
    • Response: The created ProductViewModel object with a unique id.
    • Parameter: id - The unique identifier of the product.
      • Status: 200 OK.
      • Status: 404 Not Found.

Example:

OK

get-product-by-id

Not Founderror-get-product-by-id

PUT

  • Updates a product.
    • Description: Updates the details of an existing product.
    • Request: A ProductViewModel object .
    • Parameter: id - The unique identifier of the product.
    • Response: 200 Ok if successful.
      • Status: 200 OK.
      • Status: 400 Bad Request with problems details.

Example:

OK

image

Bad Request

image

Bad Request

image

DELETE

  • Deletes a product.
    • Description: Removes an existing product by its ID.
    • Parameter: id - The unique identifier of the product.
    • Response: 204 No Content.

Example:

No Content

delete-product

Continuous Integration Pipeline

Purpose

This pipeline is designed for practicing CI/CD by automatically building and testing the project using xUnit. It triggers on pushes to the main branch and runs a series of steps to ensure the code is successfully built and passes all unit tests.

Trigger

  • Push: The pipeline runs whenever there is a push to the main branch.

Environment Variables

  • DOTNET_VERSION: Set to 8.0.x, specifying the .NET version used in the pipeline.

Pipeline Stages

  1. Checkout Code
    • Action: Uses actions/checkout@v4 to pull the latest code from the main branch.
  2. Setup .NET
    • Action: Uses actions/setup-dotnet@v4 to install .NET SDK version specified by DOTNET_VERSION.
  3. Install Dependencies
    • Command: dotnet restore installs all project dependencies.
  4. Build Project
    • Command: dotnet build --configuration Release --no-restore builds the code in Release mode. The --no-restore flag skips the dependency restore step, as it has already been completed.
  5. Run Unit Tests
    • Command: dotnet test --configuration Release --no-build runs the tests in Release mode, using xUnit as the test framework. The --no-build flag skips the build step, as it has already been completed.

About

API in .NET 8 with unit tests, automation tests, CI

Resources

Stars

Watchers

Forks

Releases

No releases published