Skip to content

PedroHenriques/dotnet_toolkit

Repository files navigation

.Net Toolkit

The .Net Toolkit is split into multiple packages:

  • Base .Net Toolkit: Intended to be used in non Asp.Net application
  • Asp.Net Toolkit: Intended to be used in Asp.Net application

Main functionalities

  • Handles setting up the connections with MongoDb, Redis, Kafka and LaunchDarkly
  • Exposes functionality to perform most operations on this tech stack while abstracting the implementation details of each technology
  • Standardizes the interactions with this tech stack across all the applications that use this package
  • Reduces the cost of evolving the interaction with this tech stack across all the applications

Note: This package does not intend to completely abstract, from the application, the technology being used. The application will still need to interact with some data types from the underlying technologies.

Application Architecture

more information here

Technical information

For detailed information about each package look at:

Package Documentation
Base .Net Toolkit doc
Asp.Net Toolkit doc

Developer information

Requisites

To develop in this application you will need, at a minimum, to have installed in your system the following:

  • Docker with Compose
  • AVX support in your system alt text

Local development environment

This repository contains a local development environment, fully containerised, that can be used to run the application on your machine and test it.

The services available in the local development environment are configured at setup/local/docker-compose.yml and setup/local/docker-compose.elk.yml.
NOTE: Any service assigned with the profile only_if_not_cicd will not be started in a CICD environment.

NOTE: Use of a unix command line environment is recommended.

Run the local environment

To run the local environment follow these steps:

  1. From the root of the project run the command
sh cli/start.sh [flags] [services]

Where:

flags:
Any flag supported by the Docker compose up command.
For more information consult the official Docker documentation.
NOTE: Consider using the -d flag, which runs the Docker project in detached mode.

services:
Whitespace separated list of services to run.
The available services are declared in the local environment Docker compose project at setup/local/docker-compose.yml.
NOTE: If no services are provided, all services will be started.

This will run a Docker compose project and start several networked Docker containers will all the services and necessary tools to use the application.

The following services will be running in the containers:

  • 1 MongoDb instance
  • 1 Redis single node instances
  • Confluent community edition Kafka Broker
  • Confluent Schema Registry
  • A GUI for MongoDb
  • A GUI for Redis
  • A GUI for Kafka

There will also be a stopped container named db_init which sets up the MongoDb replica set and exits.

  1. [OPTIONAL] From the root of the project run the command
sh cli/start_elk.sh [services]

Where:

services:
Whitespace separated list of services to run.
The available services are declared in the local environment ELK Docker compose project at setup/local/docker-compose.elk.yml.
NOTE: If no services are provided, all services will be started.

This will run a Docker compose project and start several networked Docker containers will all the services and necessary tools to use an ELK stack.

The following services will be running in the containers:

  • 1 Elasticsearch instance
  • 1 Kibana instance
  • 1 OTEL Collector instance

NOTE: Elasticsearch takes a few minutes to start and be ready to receive information, which means if you send logs before it is ready then those logs will be lost.
In order to confirm if the ELK stack is ready run the command

docker ps -a

And check if the elasticsearch service is healthy.

  1. Interact with the local environment via the following URLs:

MongoDb GUI: http://localhost:9000 (user: appUser | pw: appPw)

Redis GUI: http://localhost:9001
NOTES:
Accept the T&C and submit to enter. alt text

Add the following databases:
redis://default@redis:6379

Kafka GUI: http://localhost:9002
NOTES:
Add a topic with the name myTestTopicJson with, at least, 1 partition. Register the myTestTopicJson-key and myTestTopicJson-value schemas, using the contents of the files setup/local/tester_kafka_json_schema_key.json and setup/local/tester_kafka_json_schema_value.json, respectively. Add a topic with the name myTestTopicAvro with, at least, 1 partition. Register the myTestTopicAvro-key and myTestTopicAvro-value schemas, using the contents of the files setup/local/tester_kafka_avro_schema_key.json and setup/local/tester_kafka_avro_schema_value.json, respectively.

Kibana: http://localhost:9003

Test API: http://localhost:10000

Test API Swagger UI: http://localhost:10000/swagger

Stop the local environment

From the root of the project run the command

sh cli/stop.sh

This will stop the Docker compose project and cleanup its resources.

Configure the local environment

To configure some of the parameters of the local environment follow these steps:

  1. Copy the file setup/local/.env.template to setup/local/.env
  2. Fill in the parameters you want to overwrite and delete the ones you want to keep the defaults
  3. Run the local environment

Testing the application

From the root of the project run the command

sh cli/test.sh [flags] [projects]

Where:

flags:

  • -w: Run the tests in watch mode (Requires at least 1 project to be specified)
  • --unit: Run only unit tests
  • --integration: Run only integration tests
  • --e2e: Run only end to end tests
  • --docker: Run the tests in a Docker container
  • --filter: Run only the tests that match the provided xunit filter
  • --coverage: Run the unit tests with coverage report using the coverlet collector

projects:
Whitespace separated list of test .csproj to run.

NOTES:

  • When running the tests with the flags --docker or --cicd, the tests will run inside a Docker container that will be in the myapp_shared network.
  • When running the script with the flags ``--integrationor--e2e` the flag `--docker` is assumed as well, which means the tests will run inside a Docker container.

Generating test coverage reports

To generate unit test coverage reports, including an HTML report, from the root of the project run the command

sh cli/coverage.sh [flags]

Where:

flags:

  • --docker Build the coverage report in a Docker container

Each test project's coverage report will be located inside a directory named TestResults, inside each test project's directory.

The HTML coverage report is located inside the directory ./coverageReport, which contains an index.html file.

Project dependencies update validations

To check for updates to the project dependencies and update them if needed, from the root of the project run the command

sh cli/dependencies_update.sh [flags]

Where:

flags:

  • -u | --update: Update all outdated dependencies. You will be prompted for each one for confirmation before updating
  • -y: Update all dependencies without prompting

If the update flag is not provided, the script will print the report with all the dependencies that are outdated, but will not update any of them.

Security & Compliance Notes

more information here

CI/CD

more information here

About

A .Net toolkit for interactions with common technologies.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •