Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

Unit and integration testing #140

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
tests-results/

# NUnit
*.VisualState.xml
Expand Down
Binary file modified DockerfileSolutionRestore.txt
Binary file not shown.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,30 @@ Note that it will take a little while to start all containers. eShopOnDapr inclu

When all microservices are healthy, you can navigate to http://localhost:5104 to view the eShopOnDapr UI.

#### Unit and integration testing

The tests in eShopOnDapr are structured in the following structure, per type:

- Tests per microservice

- Unit Tests
- Functional/Integration Tests

To run the tests per microservice from the CLI, run the following command from the root folder:

```terminal
docker compose -f docker-compose-tests.yml -f docker-compose-tests.override.yml up
```

- Global application tests
- Microservices Functional/Integration Tests across the whole application

To run the global application test from the CLI, run the following command from the root folder:

```terminal
docker compose -f docker-compose-integration-tests.yml -f docker-compose-integration-tests.override.yml up
```

### Attributions

Model photo by [Angelo Pantazis](https://unsplash.com/@angelopantazis?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText) on [Unsplash](https://unsplash.com/?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText)
27 changes: 27 additions & 0 deletions dapr/components-test/eshop-email.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: sendmail
namespace: eshop
spec:
type: bindings.smtp
version: v1
metadata:
- name: host
value: maildev-test
- name: port
value: 1025
- name: user
secretKeyRef:
name: Smtp:User
key: Smtp:User
- name: password
secretKeyRef:
name: Smtp:Password
key: Smtp:Password
- name: skipTLSVerify
value: true
auth:
secretStore: eshopondapr-secretstore
scopes:
- ordering-api-test
21 changes: 21 additions & 0 deletions dapr/components-test/eshop-pubsub.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: eshopondapr-pubsub
namespace: eshop
spec:
type: pubsub.rabbitmq
version: v1
metadata:
- name: host
value: "amqp://rabbitmq-test:5672"
- name: durable
value: "false"
- name: deletedWhenUnused
value: "false"
- name: autoAck
value: "false"
- name: reconnectWait
value: "0"
- name: concurrency
value: parallel
14 changes: 14 additions & 0 deletions dapr/components-test/eshop-secrets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"ConnectionStrings": {
"CatalogDB": "Server=sqldata-test;Database=Microsoft.eShopOnDapr.Services.CatalogDb;User Id=sa;Password=Pass@word;TrustServerCertificate=true",
"IdentityDB": "Server=sqldata-test;Database=Microsoft.eShopOnDapr.Service.IdentityDb;User Id=sa;Password=Pass@word;TrustServerCertificate=true",
"OrderingDB": "Server=sqldata-test;Database=Microsoft.eShopOnDapr.Services.OrderingDb;User Id=sa;Password=Pass@word;TrustServerCertificate=true"
},
"Smtp": {
"User": "_username",
"Password": "_password"
},
"State": {
"RedisPassword": ""
}
}
13 changes: 13 additions & 0 deletions dapr/components-test/eshop-secretstore.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: eshopondapr-secretstore
namespace: eshop
spec:
type: secretstores.local.file
version: v1
metadata:
- name: secretsFile
value: /components/eshop-secrets.json
- name: nestedSeparator
value: ":"
22 changes: 22 additions & 0 deletions dapr/components-test/eshop-statestore.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: eshopondapr-statestore
namespace: eshop
spec:
type: state.redis
version: v1
metadata:
- name: redisHost
value: redis-test:6379
- name: redisPassword
secretKeyRef:
name: State:RedisPassword
key: State:RedisPassword
- name: actorStateStore
value: "true"
auth:
secretStore: eshopondapr-secretstore
scopes:
- basket-api-test
- ordering-api-test
84 changes: 84 additions & 0 deletions docker-compose-integration-tests.override.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
version: '3.4'

services:
maildev-test:
ports:
- "5500:1080"
- "1025:1025"

rabbitmq-test:
ports:
- "5672:5672"

redis-test:
ports:
- "5379:6379"

sqldata-test:
environment:
- SA_PASSWORD=Pass@word
- ACCEPT_EULA=Y
ports:
- "5433:1433"

integration-test:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_BASKET_URLS=http://0.0.0.0:81
- ASPNETCORE_BASKET_DAPR_HTTP_ENDPOINT=http://127.0.0.1:3501
- ASPNETCORE_BASKET_DAPR_GRPC_ENDPOINT=http://127.0.0.1:50002
- ASPNETCORE_ORDERING_URLS=http://0.0.0.0:82
- ASPNETCORE_ORDERING_DAPR_HTTP_ENDPOINT=http://127.0.0.1:3502
- ASPNETCORE_ORDERING_DAPR_GRPC_ENDPOINT=http://127.0.0.1:50003
- SeqServerUrl=http://seq-test
- RetryMigrations=true
- IssuerUrl=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5105
- BlazorClientUrlExternal=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5104
- BasketApiUrlExternal=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5103
- OrderingApiUrlExternal=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5102
- ShoppingAggregatorApiUrlExternal=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5121
- IdentityUrl=http://identity-api-test
- Serilog__MinimumLevel__Override__Microsoft=Information
entrypoint:
- dotnet
- test
- --logger
- trx;LogFileName=/tests/integration-test-results.xml

basket-api-dapr-integration-test:
command: ["./daprd",
"-app-id", "basket-api-test",
"-app-port", "81",
"-dapr-http-port", "3501",
"-dapr-grpc-port", "50002",
"-metrics-port", "9091",
"-log-level", "debug",
"--enable-api-logging",
"-components-path", "/components",
"-config", "/configuration/eshop-config.yaml"
]
volumes:
- "./dapr/components-test/:/components"
- "./dapr/configuration/:/configuration"

ordering-api-dapr-integration-test:
command: ["./daprd",
"-app-id", "ordering-api-test",
"-app-port", "82",
"-dapr-http-port", "3502",
"-dapr-grpc-port", "50003",
"-metrics-port", "9092",
"-log-level", "debug",
"--enable-api-logging",
"-placement-host-address", "dapr-placement-test:50000",
"-components-path", "/components",
"-config", "/configuration/eshop-config.yaml"
]
volumes:
- "./dapr/components-test/:/components"
- "./dapr/configuration/:/configuration"

dapr-placement-test:
command: ["./placement", "-port", "50000", "-log-level", "debug"]
ports:
- "50000:50000"
40 changes: 40 additions & 0 deletions docker-compose-integration-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
version: '3.4'

services:
maildev-test:
image: maildev/maildev:latest

rabbitmq-test:
image: rabbitmq:3-management-alpine

redis-test:
image: redis:alpine

sqldata-test:
image: mcr.microsoft.com/azure-sql-edge

integration-test:
image: ${REGISTRY:-eshopdapr}/integration-test:${TAG:-latest}
build:
context: .
dockerfile: src/Tests/Services/Application.FunctionalTests/Dockerfile
depends_on:
- sqldata-test
- redis-test
volumes:
- ${BUILD_ARTIFACTSTAGINGDIRECTORY:-./tests-results/}:/tests

basket-api-dapr-integration-test:
image: "daprio/daprd:1.9.4"
network_mode: "service:integration-test"
depends_on:
- integration-test

ordering-api-dapr-integration-test:
image: "daprio/daprd:1.9.4"
network_mode: "service:integration-test"
depends_on:
- integration-test

dapr-placement-test:
image: "daprio/dapr:1.9.4"
117 changes: 117 additions & 0 deletions docker-compose-tests.override.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
version: '3.4'

services:
rabbitmq-test:
ports:
- "5672:5672"

redis-test:
ports:
- "5379:6379"

sqldata-test:
environment:
- SA_PASSWORD=Pass@word
- ACCEPT_EULA=Y
ports:
- "5433:1433"

basket-api-functional-test:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=http://0.0.0.0:80
- IdentityUrl=http://identity-api-test
- IdentityUrlExternal=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5105
- SeqServerUrl=http://seq-test
- SuppressCheckForUnhandledSecurityMetadata=true
- IsTest=true
entrypoint:
- dotnet
- test
- --logger
- trx;LogFileName=/tests/basket-api-functional-test-results.xml

basket-api-dapr-test:
command: ["./daprd",
"-app-id", "basket-api-test",
"-app-port", "80",
"-log-level", "debug",
"-components-path", "/components",
"-config", "/configuration/eshop-config.yaml"
]
volumes:
- "./dapr/components-test/:/components"
- "./dapr/configuration/:/configuration"

basket-api-unit-test:
entrypoint:
- dotnet
- test
- --logger
- trx;LogFileName=/tests/basket-api-unit-test-results.xml

catalog-api-functional-test:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=http://0.0.0.0:80
- RetryMigrations=true
- SeqServerUrl=http://seq-test
entrypoint:
- dotnet
- test
- --logger
- trx;LogFileName=/tests/catalog-api-functional-test-results.xml

catalog-api-dapr-test:
command: ["./daprd",
"-app-id", "catalog-api-test",
"-app-port", "80",
"-log-level", "debug",
"-components-path", "/components",
"-config", "/configuration/eshop-config.yaml"
]
volumes:
- "./dapr/components-test/:/components"
- "./dapr/configuration/:/configuration"

catalog-api-unit-test:
entrypoint:
- dotnet
- test
- --logger
- trx;LogFileName=/tests/catalog-api-unit-test-results.xml

ordering-api-functional-test:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=http://0.0.0.0:80
- IdentityUrl=http://identity-api-test
- IdentityUrlExternal=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5105
- RetryMigrations=true
- SeqServerUrl=http://seq-test
- SuppressCheckForUnhandledSecurityMetadata=true
- IsTest=true
entrypoint:
- dotnet
- test
- --logger
- trx;LogFileName=/tests/ordering-api-functional-test-results.xml

ordering-api-dapr-test:
command: ["./daprd",
"-app-id", "ordering-api-test",
"-app-port", "80",
"-log-level", "debug",
"-components-path", "/components",
"-config", "/configuration/eshop-config.yaml"
]
volumes:
- "./dapr/components-test/:/components"
- "./dapr/configuration/:/configuration"

ordering-api-unit-test:
entrypoint:
- dotnet
- test
- --logger
- trx;LogFileName=/tests/ordering-api-unit-test-results.xml
Loading