Stats based battle simulator between Shadows.
- Examples of Results and Railway pattern in the FlyingShadow API and MockDataGenerator.
- Unit, Integration and System testing
- Console App execution on API build
- DTO and Domain object seperation in API layers (controller, service and repo).
- OpenAPI doc generator and Scalar for rendering / testing documents.
-
Navigate to
FlyingShadow.Apiproperties folder, create alaunchSettings.jsonfile with the contents copied fromlaunchSettings.template.json -
Flying Shadow can be configured to use mock data when running the API locally:
- Create an
appsettings.local.jsonin the same location as appsettings.json (if not already present) and configure the mock data flag with the dbServer node. For example
"dbServer": {
"isMock": true
}
- This configuration will replace the standard repositories with mock versions which read data from the generated json.
NOTE: By default, the FlyingShadow Api will use a postgres db for data. Please see setup postgres section
- Run the unit and integration tests either via IDE or via commandline (from the directory with the solution file) using
dotnet test. All tests including integration and openapi spec are configured to use Mock data.
launch the profile from 'launchSettings.json' or Select the FlyingShadown.Api https from the project dropdown and click Run
Navigate to the FlyingShadow.Api folder and enter dotnet run.
The Scalar UI can be accessed at http://localhost:<configured port>scalar/v1
The solution supports the generation of mock data to enable the testing of the Flying Shadow API without having to setup a database.
The mock data generation is handled by the FlyingShadow.Api.MockDataGenerator project.
-
This will generate the following data in the '_GeneratedData' folder
- Registered Users from backend
- Users for auth requests
- Kept seperate from Registered Users for security
- A copy of static Shadow characters and stealth metrics.
Generation is controlled by the GenerateMockData property in the
Directory.Build.propsfile.By default the
FlyingShadow.Api.MockDataGeneratoris executed when theFlyingShadow.Apiproject is built.- Mock Data is generated
- Scenario A - GenerateMockData is set to
trueAND the mock files do not exist.- This will be the case during the first build of the solution.
- Scenario B - GenerateMockData is set to
trueAND one of the mock files do not exist.
- Scenario A - GenerateMockData is set to
- Mock Data is not generated
- Scenario A - GenerateMockData is set to
false - Scenario B - GenerateMockData is not in the
Directory.Build.propsfile - Scenario C -
Directory.Build.propsfile is missing - Scenario D - GenerateMockData is set to
trueAND the mock files exist.
- Scenario A - GenerateMockData is set to
The Flying Shadow API can be configured to use Postgres as a datasource. A script has been included to create a database and populate with sample data.
- Postgres 10 or later
- admin access
- postgres service is running
- Navigate to the folder
FlyingShadowDbSetup - Run
psql -U <admin / superuser> -d postgres -f flyingshadow_setup.sql - Update the appsettings to include the relevant connection details to the db. For example:
"dbServer": {
"isMock": "false",
"host": "localhost",
"port": 5432,
"MinPoolSize": 10,
"MaxPoolSize": 10,
"database": "flyingshadow",
"username": "test_user"
},- Update your appsettings.local.json (ignored from git) with the user password
{ "dbServer": { "password": "" } }
The Flying Shadow open api spec will be generated here FlyingShadow.Api/OpenApi in json format.
To view the spec from the Scalar UI browse to <localhost with port>/openapi/FlyingShadow.Api.json
dotnet new tool-manifest
dotnet tool install Microsoft.OpenApi.Kiota
A build target in the FlyingShadow.Api.Spec.Test project will generate the assets pre-compilation of the test library. This means any breaking changes to the Open Api spec should reflect in the generatated assets and break consuming tests.
dotnet kiota generate \
-l CSharp \
-d ./openapi.json \
-c FlyingShadowClient \
-n FlyingShadow.Client \
-o ./_Generated/FlyingShadow.Client
The tests are built using
- Kiota generated a wrapper client and DTOs
- Microsoft.AspNetCore.Mvc.Testing which spins up the API, creates a httpclient for use in wrapper client.
NOTE - Error status codes throw a ProblemDetails (Kiota Api Exception).
The folder and spec may not regenerate if the build system thinks nothing has changed (normally when the folder has been manaully deleted)
dotnet build --no-incremental