build: 增加 MySql 单元测试

This commit is contained in:
Argo-2016 2020-02-13 12:06:36 +08:00
parent 78f41e4aa0
commit 722b2e1a52
7 changed files with 47 additions and 31 deletions

View File

@ -70,6 +70,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{D8F90830-15D0-4031-94EE-6E5D93CB734A}"
ProjectSection(SolutionItems) = preProject
appveyor.build.ps1 = appveyor.build.ps1
appveyor.install.ps1 = appveyor.install.ps1
appveyor.test.ps1 = appveyor.test.ps1
appveyor.yml = appveyor.yml
EndProjectSection
@ -110,6 +111,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ci", "ci", "{5F732D4E-133B-4DA6-811B-C369CDC3FB89}"
ProjectSection(SolutionItems) = preProject
appveyor.build.ps1 = appveyor.build.ps1
appveyor.install.ps1 = appveyor.install.ps1
appveyor.test.ps1 = appveyor.test.ps1
appveyor.yml = appveyor.yml
EndProjectSection

13
appveyor.install.ps1 Normal file
View File

@ -0,0 +1,13 @@
# 显示 dotnet version
write-host "dotnet --version" -ForegroundColor Cyan
dotnet --version
# 注意 my.ini 文件行结束符必须为CRLF
$iniPath="C:\Program Files\MySQL\MySQL Server 5.7\my.ini"
write-host "copy $($env:appveyor_build_folder)\db\MySQL\my.ini -> $iniPath" -ForegroundColor Cyan
xcopy "$($env:appveyor_build_folder)\db\MySQL\my.ini" $iniPath /y
$newText = ([System.IO.File]::ReadAllText($iniPath)).Replace("\n", "\r\n")
[System.IO.File]::WriteAllText($iniPath, $newText)
write-host "starting database services ..." -ForegroundColor Cyan

View File

@ -8,21 +8,21 @@
sqlcmd -S "$sqlInstance" -U sa -P Password12! -i "$sqlFile" -i "$initFile" -o "$outFile"
#write-host "init mysql database..." -ForegroundColor Cyan
#$env:MYSQL_PWD="Password12!"
#$mysql = '"C:\Program Files\MySQL\MySQL Server 5.7\bin\mysql.exe"'
#$cmd = $mysql + ' -e "create database BootstrapAdmin;" -uroot'
#cmd.exe /c $cmd
write-host "init mysql database..." -ForegroundColor Cyan
$env:MYSQL_PWD="Password12!"
$mysql = '"C:\Program Files\MySQL\MySQL Server 5.7\bin\mysql.exe"'
$cmd = $mysql + ' -e "create database BootstrapAdmin;" -uroot'
cmd.exe /c $cmd
#$startPath = "$($env:appveyor_build_folder)\db\MySQL"
#$para = ' -hlocalhost -uroot -DBootstrapAdmin < '
#$sqlFile = join-path $startPath "Install.sql"
#$cmd = $mysql + $para + $sqlFile
#cmd.exe /c $cmd
$startPath = "$($env:appveyor_build_folder)\db\MySQL"
$para = ' -hlocalhost -uroot -DBootstrapAdmin < '
$sqlFile = join-path $startPath "Install.sql"
$cmd = $mysql + $para + $sqlFile
cmd.exe /c $cmd
#$initFile = join-path $startPath "InitData.sql"
#$cmd = $mysql + $para + $initFile
#cmd.exe /c $cmd
$initFile = join-path $startPath "InitData.sql"
$cmd = $mysql + $para + $initFile
cmd.exe /c $cmd
write-host "init mongodb data..." -ForegroundColor Cyan
$initFolder = "$($env:appveyor_build_folder)\db\MongoDB"
@ -38,7 +38,7 @@
function runUnitTest() {
write-host "dotnet test test\UnitTest" -ForegroundColor Cyan
dotnet test "test\UnitTest" --filter="FullyQualifiedName!~MySql" /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Include="[Bootstrap.Admin*]*%2c[Bootstrap.DataAccess*]*" /p:Exclude="[*]*Program%2c[*]*Startup%2c[Bootstrap.DataAccess*]*AutoDB*%2c[Bootstrap.DataAccess]*WeChatHelper" /p:ExcludeByFile="**/SMSExtensions.cs%2c**/Helper/OAuthHelper.cs%2c**/Extensions/CloudLoggerExtensions.cs%2c**/Extensions/AutoGenerateDatabaseExtensions.cs%2c**/Api/HealthsController.cs%2c**/Pages/**%2c**/DBLogTask.cs%2c**/AutoDbHelper.cs" /p:CoverletOutput=..\..\
dotnet test "test\UnitTest" /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Include="[Bootstrap.Admin*]*%2c[Bootstrap.DataAccess*]*" /p:Exclude="[*]*Program%2c[*]*Startup%2c[Bootstrap.DataAccess*]*AutoDB*%2c[Bootstrap.DataAccess]*WeChatHelper" /p:ExcludeByFile="**/SMSExtensions.cs%2c**/Helper/OAuthHelper.cs%2c**/Extensions/CloudLoggerExtensions.cs%2c**/Extensions/AutoGenerateDatabaseExtensions.cs%2c**/Api/HealthsController.cs%2c**/Pages/**%2c**/DBLogTask.cs%2c**/AutoDbHelper.cs" /p:CoverletOutput=..\..\
}
function installCoveralls() {
@ -53,6 +53,11 @@ function reportCoveralls() {
.\tools\csmacnz.Coveralls.exe --opencover -i coverage.opencover.xml --useRelativePaths
}
function installCodecov {
write-host "install Codecov.Tool tools" -ForegroundColor Cyan
dotnet tool install Codecov.Tool --tool-path ".\tools"
}
function reportCodecov() {
Set-AppveyorBuildVariable CODECOV_TOKEN $($env:CODECOV_TOKEN)
Set-AppveyorBuildVariable CI $($env:CI)
@ -60,9 +65,6 @@ function reportCodecov() {
$coverageFile = Test-Path coverage.opencover.xml
if ($coverageFile) {
write-host "install Codecov.Tool tools" -ForegroundColor Cyan
dotnet tool install Codecov.Tool --tool-path ".\tools"
write-host "report UnitTest with Codecov" -ForegroundColor Cyan
.\tools\codecov -f coverage.opencover.xml
}
@ -72,6 +74,7 @@ $branch = $($env:APPVEYOR_REPO_BRANCH)
if ($branch -ne "dev") {
installDB
installCoveralls
installCodecov
runUnitTest
reportCoveralls
reportCodecov

View File

@ -21,14 +21,11 @@ environment:
secure: +22PuAn5seq4bbCVCly8zDFuyEV3m2NjW3QuM0+2gm4c8akwicNFmv2T/ZGd0Jpd
services:
- mssql2017
- mysql
- mongodb
install:
- ps: >-
#copy my.ini into mysql folder
dotnet --version
#xcopy "$($env:appveyor_build_folder)\db\MySQL\my.ini" "C:\Program Files\MySQL\MySQL Server 5.7" /y
.\appveyor.install.ps1
build_script:
- ps: >-
.\appveyor.build.ps1

View File

@ -1,9 +1,10 @@
[client]
[mysqld]
basedir=C:\\Program Files\\MySQL\\MySQL Server 5.7
datadir=C:\\Program Files\\MySQL\\MySQL Server 5.7\\data
character-set-server=utf8
[client]
default-character-set=utf8
[mysqld]
charcater_set_client=utf8
character_set_connection=utf8
character_set_results=utf8
character_set_server=utf8
character_set_database=utf8
[mysql]
default-character-set=utf8

View File

@ -18,7 +18,7 @@
"Enabled": true,
"ProviderName": "MySql",
"ConnectionStrings": {
"ba": "Server=localhost;Database=BootstrapAdmin;Uid=root;Pwd=Password12!;SslMode=none;"
"ba": "Server=localhost;Database=BootstrapAdmin;Uid=root;Pwd=Password12!;SslMode=none;charset=utf8;"
}
},
{

View File

@ -37,7 +37,7 @@
"Enabled": false,
"ProviderName": "MySql",
"ConnectionStrings": {
"ba": "Server=localhost;Database=UnitTest;Uid=argozhang;Pwd=argo@163.com;SslMode=none;"
"ba": "Server=localhost;Database=UnitTest;Uid=root;Pwd=argo@163.com;SslMode=none;charset=utf8;"
}
},
{