Skip to content

Tests In Browser|API|Marketplace #266

Tests In Browser|API|Marketplace

Tests In Browser|API|Marketplace #266

# This workflow will build and run In Browser Selenium Web Driver Tests
#
# For more samples to get started with GitHub Action workflows to deploy to Azure, refer to https://github.com/Azure/actions-workflow-samples
name: Test|In Browser|Marketplace
on:
#manually trigger deploy
workflow_dispatch:
# Trigger the workflow on push
#push:
# branches:
# - develop
# - main
#pull_request:
# branches:
# - develop
# - main
env:
# Flags that is set automatically to determine whether we
# are running on Github.com or within nektos/act (on Desktop).
ONGITHUB: true
# Main project path
MARKETPLACE_PROJECT_DIRECTORY: './api/CESMII.Marketplace.API/'
# Main project file name
MARKETPLACE_PROJECT_FILE: 'CESMII.Marketplace.API.csproj'
# Main project fqn
MARKETPLACE_PROJECT_FQDN: './api/CESMII.Marketplace.API/CESMII.Marketplace.API.csproj'
# Paths to Test 1 (In Browser)
TEST1_PROJECT_DIRECTORY: './api/Tests/CESMII.Marketplace.Tests.InBrowser/'
TEST1_PROJECT_FILE: 'CESMII.Marketplace.InBrowser.Tests.csproj'
TEST1_PROJECT_FQDN: './api/Tests/CESMII.Marketplace.Tests.InBrowser/CESMII.Marketplace.InBrowser.Tests.csproj'
TEST1_PROJECT_DLL: 'CESMII.Marketplace.InBrowser.Tests.dll'
# Paths to Test 2 (MongoDB)
TEST2_PROJECT_DIRECTORY: './api/Tests/CESMII.Marketplace.Tests.MongoDB/'
TEST2_PROJECT_FILE: 'CESMII.Marketplace.Tests.MongoDB.csproj'
TEST2_PROJECT_FQDN: './api/Tests/CESMII.Marketplace.Tests.MongoDB/CESMII.Marketplace.Tests.MongoDB.csproj'
TEST2_PROJECT_ABSOLUTE: '/src/api/Tests/CESMII.Marketplace.Tests.MongoDB/CESMII.Marketplace.Tests.MongoDB.csproj'
TEST2_PROJECT_DLL: 'CESMII.Marketplace.Tests.MongoDB.dll'
# Paths to Test 3 (RestApi)
TEST3_PROJECT_DIRECTORY: './api/Tests/CESMII.Marketplace.Tests.RestApi/'
TEST3_PROJECT_FILE: 'CESMII.Marketplace.Tests.RestApi.csproj'
TEST3_PROJECT_FQDN: './api/Tests/CESMII.Marketplace.Tests.RestApi/CESMII.Marketplace.Tests.RestApi.csproj'
TEST3_PROJECT_ABSOLUTE: '/src/api/Tests/CESMII.Marketplace.Tests.RestApi/CESMII.Marketplace.Tests.RestApi.csproj'
TEST3_PROJECT_DLL: 'CESMII.Marketplace.Tests.RestApi.dll'
# set this to the .NET core version to use
NETCORE_VERSION: "6.0.x"
# set this to the NODE JS version to use
NODEJS_VERSION: "16.17.0"
# set this to npm working directory
NPM_WORKING_DIRECTORY: 'frontend'
# Access to our MongoDB
MONGODB_DATABASE_NAME: "test"
MONGODB_LOCAL_CONNECTION: "mongodb://testuser:password@localhost:27017"
MONGODB_BRIDGE_CONNECTION: "mongodb://testuser:[email protected]:27017"
MARKETPLACE_BRIDGE_CONNECTION: "http://XX.XX.XX.XX"
MOUNT_SOURCE_GITHUB: '/home/runner/work/Marketplace/Marketplace/mongo-data'
MOUNT_SOURCE_DESKTOP: 'c:/CESMII.github/Marketplace/mongo-data'
jobs:
runner-job:
runs-on: ubuntu-latest
steps:
# Automating the setting of a flag that helps resolves
# differences between Github Actions on github.com and
# using nektos/act on Windows using Docker Desktop.
- name: 1__Github - Update ONGITHUB Flag
if: github.actor == 'nektos/act'
run: echo "ONGITHUB=false" >> $GITHUB_ENV
- name: 2__Marketplace API - Check out the repo
uses: actions/checkout@v3
with:
submodules: true
# Create bridge network for communication between containers
- name: 3__Docker - Set up networking
run: |
docker network remove --force mysubnet1 ;
docker network create mysubnet1 ;
# Initialize a Mongo DB database (on Github)
# Note: the "env" section seems not to work and so the -e switches are necessary
- name: 4__MongoDB - Create MongoDB Docker container (On Github)
if: env.ONGITHUB == 'true'
run: docker run -d -p 27017:27017 --name=MyMongoDB --network mysubnet1 -e MONGO_INIT_DATABASE=test -e MONGO_INITDB_ROOT_USERNAME=testuser -e MONGO_INITDB_ROOT_PASSWORD=password --mount src="${{env.MOUNT_SOURCE_GITHUB}}",target=/data,type=bind mongo:6.0
env:
MONGO_INIT_DATABASE: test
MONGO_INITDB_ROOT_USERNAME: testuser
MONGO_INITDB_ROOT_PASSWORD: password
# Initialize a Mongo DB database (on the Desktop)
- name: 4__MongoDB - Create MongoDB Docker container (On Desktop)
if: env.ONGITHUB == 'false'
run: docker run -d -p 27017:27017 --name=MyMongoDB --network mysubnet1 -e MONGO_INIT_DATABASE=test -e MONGO_INITDB_ROOT_USERNAME=testuser -e MONGO_INITDB_ROOT_PASSWORD=password --mount src="${{env.MOUNT_SOURCE_DESKTOP}}",target=/data,type=bind mongo:6.0
env:
MONGO_INIT_DATABASE: test
MONGO_INITDB_ROOT_USERNAME: testuser
MONGO_INITDB_ROOT_PASSWORD: password
- name: 5__MongoDB - Query Bridge Connection to MyMongoDB Container
run:
export TEMPIPVALUE=$(docker exec -i MyMongoDB hostname -i) ;
echo "MONGODB_BRIDGE_CONNECTION=mongodb://testuser:password@$TEMPIPVALUE:27017" >> $GITHUB_ENV
# Putting steps 6, 7 & 8 between "Create mongoDB container" and "Populate mongo database" seems to help the mongo container settle down
- name: 6__Marketplace API - Set up dotnet core ${{ env.NETCORE_VERSION }}
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.NETCORE_VERSION }}
# Publish the app and the tests
- name: 7__Marketplace - Publish Marketplace Api
run: |
dotnet publish --framework:net6.0 ${{env.MARKETPLACE_PROJECT_FQDN}} -c Release -o ./publish ;
dotnet publish ./DumpAppLog/DumpAppLog.csproj
# Create a Docker Container for Marketplace
- name: 8__Marketplace - Build Docker Image
run: docker build -f "./api/CESMII.Marketplace.API/Dockerfile" --force-rm -t cesmiimarketplaceapi:dev --target base --label "com.microsoft.created-by=visual-studio" --label "com.microsoft.visual-studio.project-name=CESMII.Marketplace.API" "./"
# Populate mongo database -
- name: 9__MongoDB - Populate mongo database
run: docker exec -i MyMongoDB mongoimport --authenticationDatabase=admin --collection=app_log --file=/data/app_log.json --uri="${{env.MONGODB_LOCAL_CONNECTION}}" ;
docker exec -i MyMongoDB mongoimport --authenticationDatabase=admin --collection=JobLog --file=/data/JobLog.json --uri="${{env.MONGODB_LOCAL_CONNECTION}}" ;
docker exec -i MyMongoDB mongoimport --authenticationDatabase=admin --collection=LookupItem --file=/data/LookupItem.json --uri="${{env.MONGODB_LOCAL_CONNECTION}}" ;
docker exec -i MyMongoDB mongoimport --authenticationDatabase=admin --collection=MarketplaceItem --file=/data/MarketplaceItem.json --uri="${{env.MONGODB_LOCAL_CONNECTION}}" ;
docker exec -i MyMongoDB mongoimport --authenticationDatabase=admin --collection=MarketplaceItemAnalytics --file=/data/MarketplaceItemAnalytics.json --uri="${{env.MONGODB_LOCAL_CONNECTION}}" ;
docker exec -i MyMongoDB mongoimport --authenticationDatabase=admin --collection=Organization --file=/data/Organization.json --uri="${{env.MONGODB_LOCAL_CONNECTION}}" ;
docker exec -i MyMongoDB mongoimport --authenticationDatabase=admin --collection=Permission --file=/data/Permission.json --uri="${{env.MONGODB_LOCAL_CONNECTION}}" ;
docker exec -i MyMongoDB mongoimport --authenticationDatabase=admin --collection=ProfileItem --file=/data/ProfileItem.json --uri="${{env.MONGODB_LOCAL_CONNECTION}}" ;
docker exec -i MyMongoDB mongoimport --authenticationDatabase=admin --collection=Publisher --file=/data/Publisher.json --uri="${{env.MONGODB_LOCAL_CONNECTION}}" ;
docker exec -i MyMongoDB mongoimport --authenticationDatabase=admin --collection=RequestInfo --file=/data/RequestInfo.json --uri="${{env.MONGODB_LOCAL_CONNECTION}}" ;
docker exec -i MyMongoDB mongoimport --authenticationDatabase=admin --collection=SearchKeyword --file=/data/SearchKeyword.json --uri="${{env.MONGODB_LOCAL_CONNECTION}}" ;
- name: 10__MongoDB - Test access to Mongo database
run: dotnet test ${{env.TEST2_PROJECT_DIRECTORY}}${{env.TEST2_PROJECT_FILE}}
env:
MARKETPLACE_MONGODB_CONNECTIONSTRING: ${{env.MONGODB_LOCAL_CONNECTION}}
MARKETPLACE_MONGODB_DATABASE: ${{env.MONGODB_DATABASE_NAME}}
# Start Marketplace Container (On Github)
- name: 11__Marketplace - Start the Container (On Github)
if: env.ONGITHUB == 'true'
env:
ASPNETCORE_ENVIRONMENT: Development
ASPNETCORE_URLS: http://+:80
ASPNETCORE_LOGGING__CONSOLE__DISABLECOLORS: true
DOTNET_RUNNING_IN_CONTAINER: true
DOTNET_USE_POLLING_FILE_WATCHER: 1
EnableCloudLibSearch: false
MARKETPLACE_GITHUB_WORKFLOW_COMMANDS: true
MARKETPLACE_MONGODB_CONNECTIONSTRING: ${{env.MONGODB_BRIDGE_CONNECTION}}
MARKETPLACE_MONGODB_DATABASE: test
run: |
docker run -dt --network mysubnet1 -v "/home/runner/work/Marketplace/Marketplace/api/CESMII.Marketplace.API:/app" -v "/home/runner/work/Marketplace/Marketplace:/src/" -e "ASPNETCORE_LOGGING__CONSOLE__DISABLECOLORS=true" -e "ASPNETCORE_ENVIRONMENT=Development" -e "DOTNET_USE_POLLING_FILE_WATCHER=1" -e "EnableCloudLibSearch=false" -e "ASPNETCORE_URLS=http://+:80" -p 5000:80 -p:5001:443 --name CESMII.Marketplace.API --entrypoint tail cesmiimarketplaceapi:dev -f /dev/null
# Start Marketplace Container (On Desktop)
- name: 11__Marketplace - Start the Container (On Desktop)
if: env.ONGITHUB == 'false'
env:
ASPNETCORE_ENVIRONMENT: Development
ASPNETCORE_URLS: http://+:80
ASPNETCORE_LOGGING__CONSOLE__DISABLECOLORS: true
DOTNET_RUNNING_IN_CONTAINER: true
DOTNET_USE_POLLING_FILE_WATCHER: 1
EnableCloudLibSearch: false
MARKETPLACE_GITHUB_WORKFLOW_COMMANDS: true
MARKETPLACE_MONGODB_CONNECTIONSTRING: ${{env.MONGODB_BRIDGE_CONNECTION}}
MARKETPLACE_MONGODB_DATABASE: test
run: |
docker run -dt --network mysubnet1 -v "C:\Users\paul\AppData\Roaming\Microsoft\UserSecrets:/root/.microsoft/usersecrets:ro" -v "C:\Users\paul\AppData\Roaming\ASP.NET\Https:/root/.aspnet/https:ro" -v "C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Sdks\Microsoft.Docker.Sdk\tools\TokenService.Proxy\linux-x64\net6.0:/TokenService.Proxy:ro" -v "C:\CESMII.github\Marketplace\api\CESMII.Marketplace.API:/app" -v "C:\CESMII.github\Marketplace:/src/" -v "C:\Users\paul\.nuget\packages\:/root/.nuget/fallbackpackages" -e "ASPNETCORE_LOGGING__CONSOLE__DISABLECOLORS=true" -e "ASPNETCORE_ENVIRONMENT=Development" -e "ASPNETCORE_URLS=http://+:80" -e "DOTNET_USE_POLLING_FILE_WATCHER=1" -e "NUGET_PACKAGES=/root/.nuget/fallbackpackages" -e "NUGET_FALLBACK_PACKAGES=/root/.nuget/fallbackpackages" -e "EnableCloudLibSearch=false" -p 5000:80 -p 5001:443 --name CESMII.Marketplace.API --entrypoint tail cesmiimarketplaceapi:dev -f /dev/null
- name: 12__CESMII.Marketplace.API - Query Bridge Connection to CESMII.Marketplace.API Container
run:
export TEMPIPVALUE=$(docker exec -i CESMII.Marketplace.API hostname -i) ;
echo "MARKETPLACE_BRIDGE_CONNECTION=http://$TEMPIPVALUE" >> $GITHUB_ENV
# Start the Main Dll in the Container (On Github)
## Github can accommodate "docker exec -i.... & ", ampersand at the end!!!)
## In Windows, docker exec -id works better
- name: 13__Marketplace - Start the Main Dll in the Container (Github)
if: env.ONGITHUB == 'true'
env:
ASPNETCORE_ENVIRONMENT: Development
ASPNETCORE_URLS: http://+:80
ASPNETCORE_LOGGING__CONSOLE__DISABLECOLORS: true
DOTNET_RUNNING_IN_CONTAINER: true
DOTNET_USE_POLLING_FILE_WATCHER: 1
EnableCloudLibSearch: false
MARKETPLACE_GITHUB_WORKFLOW_COMMANDS: true
MARKETPLACE_MONGODB_CONNECTIONSTRING: ${{env.MONGODB_BRIDGE_CONNECTION}}
MARKETPLACE_MONGODB_DATABASE: test
run: |
docker exec -i CESMII.Marketplace.API dotnet /src/publish/CESMII.Marketplace.API.dll &
# Start the Main Dll in the Container (On the Desktop)
- name: 13__Marketplace - Start the Main Dll in the Container (Desktop)
if: env.ONGITHUB == 'false'
env:
ASPNETCORE_ENVIRONMENT: Development
ASPNETCORE_URLS: http://+:80
ASPNETCORE_LOGGING__CONSOLE__DISABLECOLORS: true
DOTNET_RUNNING_IN_CONTAINER: true
DOTNET_USE_POLLING_FILE_WATCHER: 1
EnableCloudLibSearch: false
MARKETPLACE_GITHUB_WORKFLOW_COMMANDS: true
MARKETPLACE_MONGODB_CONNECTIONSTRING: ${{env.MONGODB_BRIDGE_CONNECTION}}
MARKETPLACE_MONGODB_DATABASE: test
run: |
docker exec -di CESMII.Marketplace.API dotnet /src/publish/CESMII.Marketplace.API.dll
# # # # Dotnet -- diagnostics
# # # - name: A__Diagnostic__DotNet - Diagnostics
# # # #run: docker exec -i MyMarketplace /usr/share/dotnet/dotnet --diagnostics
# # # run: docker exec -i CESMII.Marketplace.API /usr/share/dotnet/dotnet --diagnostics
# # # # Dotnet -- info
# # # - name: B__Diagnostic__DotNet - Info
# # # run: docker exec -i CESMII.Marketplace.API /usr/share/dotnet/dotnet --info
# # # # Dotnet -- list-runtimes
# # # - name: C__Diagnostic__DotNet - list-runtimes
# # # run: docker exec -i CESMII.Marketplace.API /usr/share/dotnet/dotnet --list-runtimes
# # # # Dotnet -- list-sdks
# # # - name: D__Diagnostic__DotNet - list-sdks
# # # run: docker exec -i CESMII.Marketplace.API /usr/share/dotnet/dotnet --list-sdks
# # # # Dotnet --version
# # # - name: E__Diagnostic__DotNet - Version
# # # run: docker exec -i CESMII.Marketplace.API /usr/share/dotnet/dotnet --version
# Peek at docker status
- name: H__Diagnostic__Docker - Peeking at docker status
run: docker container ls --all ;
docker network ls ;
docker network inspect mysubnet1 ;
docker container inspect CESMII.Marketplace.API ;
docker container inspect MyMongoDB ;
docker system info ;
docker port CESMII.Marketplace.API ;
- name: I__Diagnostic____MongoDB - Test access to Mongo database (Reprise - repeat with slower, more meaningful phrasing)
run: dotnet test ${{env.TEST2_PROJECT_FQDN}}
env:
MARKETPLACE_MONGODB_CONNECTIONSTRING: ${{env.MONGODB_LOCAL_CONNECTION}}
MARKETPLACE_MONGODB_DATABASE: ${{env.MONGODB_DATABASE_NAME}}
# Testing -- Call into Marketplace Rest Api (call from runner)`
- name: T_001__Tests - Calling RectApi
if: always()
env:
MARKETPLACE_URL1: "http://localhost/api"
run: dotnet test -e "MARKETPLACE_URL1=http://localhost/api" ${{env.TEST3_PROJECT_FQDN}}
- name: T_002__Tests - Calling RectApi
if: always()
env:
MARKETPLACE_URL1: "http://localhost:80/api"
run: dotnet test -e "MARKETPLACE_URL1=http://localhost:80/api" ${{env.TEST3_PROJECT_FQDN}}
- name: T_003__Tests - Calling RectApi
if: always()
env:
MARKETPLACE_URL1: "http://localhost:5000/api"
run: dotnet test -e "MARKETPLACE_URL1=http://localhost:5000/api" ${{env.TEST3_PROJECT_FQDN}}
- name: T_004__Tests - Calling RectApi
if: always()
env:
MARKETPLACE_URL1: "http://localhost:5001/api"
run: dotnet test -e "MARKETPLACE_URL1=http://localhost:5001/api" ${{env.TEST3_PROJECT_FQDN}}
# Testing -- Call into Marketplace Rest Api (call from inside container )
- name: T__010__Tests - Access to RectApi inside container (On Desktop)
if: always()
env:
MARKETPLACE_URL1: "http://localhost/api"
run: docker exec -i CESMII.Marketplace.API dotnet test -e "MARKETPLACE_URL1=http://localhost/api" ${{env.TEST3_PROJECT_ABSOLUTE}}
- name: T__011__Tests - Access to RectApi inside container (On Desktop)
if: always()
env:
MARKETPLACE_URL1: "http://localhost:80/api"
run: docker exec -i CESMII.Marketplace.API dotnet test -e "MARKETPLACE_URL1=http://localhost:80/api" ${{env.TEST3_PROJECT_ABSOLUTE}}
- name: T__012__Tests - Access to RectApi inside container (On Desktop)
if: always()
env:
MARKETPLACE_URL1: "http://localhost:5000/api"
run: docker exec -i CESMII.Marketplace.API dotnet test -e "MARKETPLACE_URL1=http://localhost:5000/api" ${{env.TEST3_PROJECT_ABSOLUTE}}
- name: T__013__Tests - Access to RectApi inside container (On Desktop)
if: always()
env:
MARKETPLACE_URL1: "http://localhost:5001/api"
run: docker exec -i CESMII.Marketplace.API dotnet test -e "MARKETPLACE_URL1=http://localhost:5001/api" ${{env.TEST3_PROJECT_ABSOLUTE}}
# Testing -- Call into Marketplace Rest Api using bridge IP address from inside container
- name: T__1010__Tests - Access to RectApi inside container (On Desktop)
if: always()
env:
MARKETPLACE_URL1: "${{ env.MARKETPLACE_BRIDGE_CONNECTION}}/api"
run: docker exec -i CESMII.Marketplace.API dotnet test ${{env.TEST3_PROJECT_ABSOLUTE}}
- name: T__1011__Tests - Access to RectApi inside container (On Desktop)
if: always()
env:
MARKETPLACE_URL1: "${{ env.MARKETPLACE_BRIDGE_CONNECTION}}:80/api"
run: docker exec -i CESMII.Marketplace.API dotnet test ${{env.TEST3_PROJECT_ABSOLUTE}}
- name: T__1012__Tests - Access to RectApi inside container (On Desktop)
if: always()
env:
MARKETPLACE_URL1: "${{ env.MARKETPLACE_BRIDGE_CONNECTION}}:5000/api"
run: docker exec -i CESMII.Marketplace.API dotnet test ${{env.TEST3_PROJECT_ABSOLUTE}}
- name: T__1013__Tests - Access to RectApi inside container (On Desktop)
if: always()
env:
MARKETPLACE_URL1: "${{ env.MARKETPLACE_BRIDGE_CONNECTION}}:5001/api"
run: docker exec -i CESMII.Marketplace.API dotnet test ${{env.TEST3_PROJECT_ABSOLUTE}}
#######################################################################################################
#- name: FrontEnd - Start browser and fetch version
# run: chrome --version
#- name: FrontEnd - Use Node.js version (${{env.NODEJS_VERSION}})
# uses: actions/setup-node@v3
# with:
# node-version: ${{env.NODEJS_VERSION}}
#- name: FrontEnd - Build React Code - npm install, build
# working-directory: ${{env.NPM_WORKING_DIRECTORY}}
# env:
# CI: '' #when process-env-ci is true, warnings are ignored and not treated as errors
# run: |
# npm install
# npm run build:in-browser-test
# npm run start-in-browser-test &
##- name: Docker - launch standalone chrome browser
## run: |
## docker run -d -p 4444:4444 selenium/standalone-chrome
#- name: In-Browser Testing - Restore dependencies CESMII.Marketplace.InBrowser.Tests
# working-directory: ${{env.SOLUTION_DIRECTORY}}
# run: dotnet restore
#- name: In-Browser Testing - Run Test on project (${{env.TEST1_PROJECT_FILE}})
# run: dotnet test ${{env.SOLUTION_DIRECTORY}}api/Tests/CESMII.Marketplace.InBrowser.Tests/${{env.TEST1_PROJECT_FILE}}.csproj --configuration Staging --verbosity normal -l:"console;verbosity=normal"
# working-directory: ${{env.SOLUTION_DIRECTORY}}
# # Testing -- Call into Marketplace Rest Api (call from inside container) - On Github
# # Does not work
# - name: 11__Tests - Access to RectApi inside container (On Github)
# if: env.ONGITHUB == 'true'
# env:
# MARKETPLACE_URL1: "http://localhost:80/api"
# run: docker exec -i CESMII.Marketplace.API dotnet test -e "MARKETPLACE_URL1=http://localhost:80/api" ${{env.TEST3_PROJECT_ABSOLUTE}}
# Post-Run Diagnostic Support - app_log contents
- name: 100__Diagnostic__MarketplaceAPI - Dump app_log Log
if: always()
env:
MARKETPLACE_MONGODB_CONNECTIONSTRING: mongodb://testuser:password@localhost:27017
MARKETPLACE_MONGODB_DATABASE: test
run: dotnet run --project ./DumpAppLog/DumpAppLog.csproj
# Post-Run Diagnostic Support - MyMongoDB log
- name: 101__Diagnostic__MyMongoDB Container
if: always()
run: docker logs --details MyMongoDB
# CESMII.Marketplace.API - CESMII.Marketplace.API log
- name: 102__Diagnostic__CESMII.Marketplace.API Container
if: always()
run: docker logs --details CESMII.Marketplace.API