'SW Card Game' is a simple application allowing user to compare two cards of specific definition based on selected property. Application displays the result of comparison of properties by they numeric value, declares winner and counts score.
Term | Description |
---|---|
Card definition | Defines properties available on cards (e.g. people card definition defines that on every card of this definition two properties are available: noOfHeads and noOfLegs). |
Card | Named group of properties and their values assigned to single definiton (e.g. spock card has properties noOfLegs = 1 and noOfHeads = 1) |
Deal | Single round in game. |
Game | Group of rounds for which scores are calculated. |
The application is made of ASP.NET Core based server and React based client. Server is using EntityFramework Core as an ORM and Postgres as a database.
Server code structure is inspired by Clean architecture and consists of following projects:
src/SWCardGame.Core
- responsible for application logic, domain objects and definiton of interfaces which applicaton logic uses to fulfill its usecases.src/SWCardGame.Persistance
- responsible for implementation of persistance interfaces defined in core.src/SWCardGame.WebApi
- provides RESTful api and is considered an entrypoint to the application. Currently api only allowes operations on Cards but handling of Card definitions could be easly added.
Client structure consist of following folders:
-
components
- the place where React components are defined. Each subfolder is representing screen in application and consists of React components which are the building blocks of this screen. There is also index.ts which exposes main component.Components can be divided into two groups:
Container
components - responsible for data fetching and logic and provision of those to presentational components.Presentational
components - responsible for defining how component should be presented.
-
api
- here is the code responsible for communication with the server (for now server address is harcoded and of course it shouldn't be but since this is just an demo app let it stay as it is).
To provide type safety code on client side is written in TypeScript.
Unit tests in this application are ment to show an approach not to provide full test coverage.
Server unit tests are located in tests
directory and are divided into projects matching server architecture. Test methods naming convention follows the rule that it should have information about whats being tested, under what conditions and with what result.
NUnit
is being used as a test framework and Nsubstitute
as a mock/stub library.
To run the tests use following command from inside of server
folder (requires .net core 3 sdk to be installed on the machine)
> dotnet test
Client unit test are located in *.test.tsx
files next to tested component.
Jest
and react-testing-library
are being used as test framework.
To run the tests use following command from inside of react-client
folder (requires nodejs with npm > 5.2.x to be installed on the machine)
> npx yarn install
> npx yarn test
e2e tests only work if the application is running locally. See
Deployment
section for more informations.
For end to end tests Cypress
framework is used. Tests are located in *.spec.js
files inside of react-client/e2e
directory.
To run the tests use following command from inside of 'react-client' folder (requirements are the same as for client unit tests)
> npx cypress open
or use docker if we dont care about cypress dashboard view
docker run --rm --network="host" -it -v $PWD:/e2e -w /e2e cypress/included:3.2.0
Api documentation can be viewed under http://<serverurl>/docs
endpoint.
It is created using Swagger
tools and Swashbuckle.AspNetCore
library.
Continous Integration pipeline is running on GitHub Actions. Currently there is one workflow defined:
Main CI
- builds and runs unit tests for server and client on every push to master branch.
Currently application is not deployed anywhere. To run it locally use docker (from root folder):
> docker-compose up
This sets up client, server and postgres containers. When containers are running following urls can be used to access application:
http://localhost:5500
- client applicationhttp://localhost:5000/api/v1
- web apihttp://localhost:5000/docs
- web api documentation
Before application can be used database must be prepared. For this use following endpoint:
GET http://localhost:5000/api/v1/seed