Skip to content

Commit 7b1a736

Browse files
authored
Merge pull request #11 from HodStudio/feature/TestsOnAppVeyor
Change script to run with appveyor configuration
2 parents 04f1289 + e53242e commit 7b1a736

10 files changed

Lines changed: 164 additions & 14 deletions

File tree

HodStudio.EntityFrameworkDiffLog.sln

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Scripts", "Scripts", "{928F
2323
ProjectSection(SolutionItems) = preProject
2424
appveyor.yml = appveyor.yml
2525
scripts\Build.ps1 = scripts\Build.ps1
26+
scripts\Coverage.ps1 = scripts\Coverage.ps1
27+
coverletArgs.runsettings = coverletArgs.runsettings
2628
EndProjectSection
2729
EndProject
2830
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Examples", "Examples", "{CC632624-6456-4EE6-AF19-CD1B4E206C3F}"

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,24 @@
44

55
_An easy way to create entity changes' log using Entity Framework_
66

7+
[![License](https://img.shields.io/github/license/hodstudio/entityframeworkdifflog)](https://github.com/HodStudio/EntityFrameworkDiffLog/blob/master/LICENSE.md)
8+
[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/hodstudio/entityframeworkdifflog)](https://github.com/HodStudio/EntityFrameworkDiffLog/releases)
9+
[![GitHub Release Date](https://img.shields.io/github/release-date/hodstudio/entityframeworkdifflog)](https://github.com/HodStudio/EntityFrameworkDiffLog/releases)
10+
[![Nuget](https://img.shields.io/nuget/dt/HodStudio.EntityFrameworkDiffLog)](https://www.nuget.org/packages/HodStudio.EntityFrameworkDiffLog/)
11+
[![GitHub issues by-label](https://img.shields.io/github/issues-raw/hodstudio/entityframeworkdifflog/bug)](https://github.com/HodStudio/EntityFrameworkDiffLog/labels/bug)
12+
713
[![Build status](https://ci.appveyor.com/api/projects/status/1r9ebih0q0ntqfu4?svg=true)](https://ci.appveyor.com/project/Cussa/entityframeworkdifflog)
8-
[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=HodStudio.EntityFrameworkDiffLog&metric=bugs)](https://sonarqube.com/dashboard?id=HodStudio.EntityFrameworkDiffLog) [![CodeSmells](https://sonarcloud.io/api/project_badges/measure?project=HodStudio.EntityFrameworkDiffLog&metric=code_smells)](https://sonarqube.com/dashboard?id=HodStudio.EntityFrameworkDiffLog) [![vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=HodStudio.EntityFrameworkDiffLog&metric=vulnerabilities)](https://sonarqube.com/dashboard?id=HodStudio.EntityFrameworkDiffLog) [![Duplicated Lines](https://sonarcloud.io/api/project_badges/measure?project=HodStudio.EntityFrameworkDiffLog&metric=duplicated_lines_density)](https://sonarqube.com/dashboard?id=HodStudio.EntityFrameworkDiffLog) [![sqale_index](https://sonarcloud.io/api/project_badges/measure?project=HodStudio.EntityFrameworkDiffLog&metric=sqale_index)](https://sonarqube.com/dashboard?id=HodStudio.EntityFrameworkDiffLog) [![sqale_rating](https://sonarcloud.io/api/project_badges/measure?project=HodStudio.EntityFrameworkDiffLog&metric=sqale_rating)](https://sonarqube.com/dashboard?id=HodStudio.EntityFrameworkDiffLog) [![reliability_rating](https://sonarcloud.io/api/project_badges/measure?project=HodStudio.EntityFrameworkDiffLog&metric=reliability_rating)](https://sonarqube.com/dashboard?id=HodStudio.EntityFrameworkDiffLog) [![security_rating](https://sonarcloud.io/api/project_badges/measure?project=HodStudio.EntityFrameworkDiffLog&metric=security_rating)](https://sonarqube.com/dashboard?id=HodStudio.EntityFrameworkDiffLog)
14+
[![AppVeyor tests (compact)](https://img.shields.io/appveyor/tests/hodstudio/entityframeworkdifflog?compact_message&logo=appveyor)](https://ci.appveyor.com/project/Cussa/entityframeworkdifflog/build/tests)
15+
16+
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=HodStudio.EntityFrameworkDiffLog&metric=alert_status)](https://sonarcloud.io/dashboard?id=HodStudio.EntityFrameworkDiffLog)
17+
[![sqale_rating](https://sonarcloud.io/api/project_badges/measure?project=HodStudio.EntityFrameworkDiffLog&metric=sqale_rating)](https://sonarqube.com/dashboard?id=HodStudio.EntityFrameworkDiffLog)
18+
[![reliability_rating](https://sonarcloud.io/api/project_badges/measure?project=HodStudio.EntityFrameworkDiffLog&metric=reliability_rating)](https://sonarqube.com/dashboard?id=HodStudio.EntityFrameworkDiffLog)
19+
[![security_rating](https://sonarcloud.io/api/project_badges/measure?project=HodStudio.EntityFrameworkDiffLog&metric=security_rating)](https://sonarqube.com/dashboard?id=HodStudio.EntityFrameworkDiffLog)
20+
[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=HodStudio.EntityFrameworkDiffLog&metric=bugs)](https://sonarqube.com/dashboard?id=HodStudio.EntityFrameworkDiffLog)
21+
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=HodStudio.EntityFrameworkDiffLog&metric=vulnerabilities)](https://sonarqube.com/dashboard?id=HodStudio.EntityFrameworkDiffLog)
22+
[![CodeSmells](https://sonarcloud.io/api/project_badges/measure?project=HodStudio.EntityFrameworkDiffLog&metric=code_smells)](https://sonarqube.com/dashboard?id=HodStudio.EntityFrameworkDiffLog)
23+
[![Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=HodStudio.EntityFrameworkDiffLog&metric=sqale_index)](https://sonarqube.com/dashboard?id=HodStudio.EntityFrameworkDiffLog)
24+
[![Duplicated Lines](https://sonarcloud.io/api/project_badges/measure?project=HodStudio.EntityFrameworkDiffLog&metric=duplicated_lines_density)](https://sonarqube.com/dashboard?id=HodStudio.EntityFrameworkDiffLog)
925

1026
During 2018, we worked on an open-source project, and one of the exciting things that we did there was to create an excellent way to have an entity changes' logs. The solution was exciting, but not so good if you wanted to reuse that. So, we decided to create a library to make it easier for anyone that wants to use it!
1127

coverletArgs.runsettings

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<RunSettings>
3+
<DataCollectionRunSettings>
4+
<DataCollectors>
5+
<DataCollector friendlyName="XPlat code coverage">
6+
<Configuration>
7+
<Format>cobertura</Format>
8+
</Configuration>
9+
</DataCollector>
10+
</DataCollectors>
11+
</DataCollectionRunSettings>
12+
</RunSettings>

scripts/Build.ps1

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ $projectPath = ".\src\HodStudio.EntityFrameworkDiffLog\HodStudio.EntityFramework
2626
$libraryOnlySolutionPath = ".\src\HodStudio.EntityFrameworkDiffLog\HodStudio.EntityFrameworkDiffLog.Library.sln"
2727

2828
if(Test-Path .\artifacts) { Remove-Item .\artifacts -Force -Recurse }
29+
if(Test-Path .\testresults) { Remove-Item .\testresults -Force -Recurse }
2930

3031
# Version Configuration
3132
$csprojContent = Get-Content $projectPath
@@ -55,14 +56,40 @@ echo "Build entire solution"
5556
exec { & dotnet build -c Release }
5657

5758
echo "Tests Core version"
58-
exec { & dotnet test -c Release }
59+
dotnet test -c Release --test-adapter-path:. --logger:"nunit;LogFilePath=$($env:APPVEYOR_BUILD_FOLDER)\TestResults\core-results.xml"
60+
61+
$corePassed = $lastexitcode
5962

6063
echo "Adjust Configuration for Tests 4.5"
6164
Remove-Item -Path ".\src\HodStudio.EntityFrameworkDiffLog.TestsDotNet45\bin\Release\HodStudio.EntityFrameworkDiffLog.TestsDotNet45.dll.config"
6265
Rename-Item -Path ".\src\HodStudio.EntityFrameworkDiffLog.TestsDotNet45\bin\Release\App.Release.config" -NewName "HodStudio.EntityFrameworkDiffLog.TestsDotNet45.dll.config"
6366

6467
echo "Tests 4.5 version"
65-
exec { & ".\packages\NUnit.ConsoleRunner.3.10.0\tools\nunit3-console.exe" ".\src\HodStudio.EntityFrameworkDiffLog.TestsDotNet45\bin\Release\HodStudio.EntityFrameworkDiffLog.TestsDotNet45.dll" }
68+
.\packages\NUnit.ConsoleRunner.3.10.0\tools\nunit3-console.exe .\src\HodStudio.EntityFrameworkDiffLog.TestsDotNet45\bin\Release\HodStudio.EntityFrameworkDiffLog.TestsDotNet45.dll --result="$($env:APPVEYOR_BUILD_FOLDER)\TestResults\net45-results.xml"
69+
70+
$net45Passed = $lastexitcode
71+
72+
echo "Upload results to AppVeyor"
73+
$wc = New-Object 'System.Net.WebClient'
74+
$wc.UploadFile("https://ci.appveyor.com/api/testresults/nunit3/$($env:APPVEYOR_JOB_ID)", (Resolve-Path "$($env:APPVEYOR_BUILD_FOLDER)\TestResults\net45-results.xml" ))
75+
$wc.UploadFile("https://ci.appveyor.com/api/testresults/nunit3/$($env:APPVEYOR_JOB_ID)", (Resolve-Path "$($env:APPVEYOR_BUILD_FOLDER)\TestResults\core-results.xml" ))
76+
77+
$errorMessage = $NULL
78+
79+
if ($corePassed -ne 0)
80+
{
81+
$errorMessage = ".Net Core tests failed`r`n"
82+
}
83+
84+
if ($net45Passed -ne 0)
85+
{
86+
$errorMessage = $errorMessage + ".Net 4.5 tests failed`r`n"
87+
}
88+
89+
if ($errorMessage -ne $NULL)
90+
{
91+
throw $errorMessage
92+
}
6693

6794
# Sonar Analysis
6895
echo "Installing sonarscanner"
@@ -84,20 +111,43 @@ Catch
84111
else { echo "sonarscanner already installed" }
85112
}
86113

114+
echo "Installing reportgenerator"
115+
Try
116+
{
117+
exec { & dotnet tool install -g dotnet-reportgenerator-globaltool }
118+
}
119+
Catch
120+
{
121+
$needInstallSonar = dotnet tool list -g | Select-String -Pattern "dotnet-reportgenerator-globaltool" | % { $_.Matches.Value -eq $NULL }
122+
if ($needInstallSonar -eq $true)
123+
{
124+
$ErrorMessage = $_.Exception.Message
125+
$FailedItem = $_.Exception.ItemName
126+
echo $FailedItem
127+
echo $ErrorMessage
128+
return -1
129+
}
130+
else { echo "reportgenerator already installed" }
131+
}
132+
87133
echo "Starting Sonar for Library"
88134

89135
if ($env:APPVEYOR_PULL_REQUEST_NUMBER -ne $null)
90136
{
91-
exec { & dotnet sonarscanner begin /d:sonar.login="$env:sonartoken" /key:"HodStudio.EntityFrameworkDiffLog" /o:"hodstudio-github" /d:sonar.sources=".\src\HodStudio.EntityFrameworkDiffLog" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.pullrequest.base="$env:APPVEYOR_REPO_BRANCH" /d:sonar.pullrequest.branch="$env:APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH" /d:sonar.pullrequest.key="$env:APPVEYOR_PULL_REQUEST_NUMBER " /d:sonar.pullrequest.provider="GitHub" /d:sonar.pullrequest.github.repository="$env:APPVEYOR_REPO_NAME" }
137+
exec { & dotnet sonarscanner begin /d:sonar.login="$env:sonartoken" /key:"HodStudio.EntityFrameworkDiffLog" /o:"hodstudio-github" /d:sonar.sources=".\src\HodStudio.EntityFrameworkDiffLog" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.pullrequest.base="$env:APPVEYOR_REPO_BRANCH" /d:sonar.pullrequest.branch="$env:APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH" /d:sonar.pullrequest.key="$env:APPVEYOR_PULL_REQUEST_NUMBER " /d:sonar.pullrequest.provider="GitHub" /d:sonar.pullrequest.github.repository="$env:APPVEYOR_REPO_NAME" /d:sonar.coverageReportPaths="$($env:APPVEYOR_BUILD_FOLDER)\testresults\SonarQube.xml" }
92138
}
93139
else
94140
{
95-
exec { & dotnet sonarscanner begin /d:sonar.login="$env:sonartoken" /key:"HodStudio.EntityFrameworkDiffLog" /o:"hodstudio-github" /d:sonar.sources=".\src\HodStudio.EntityFrameworkDiffLog" /d:sonar.host.url="https://sonarcloud.io" /version:"$completeVersion" }
141+
exec { & dotnet sonarscanner begin /d:sonar.login="$env:sonartoken" /key:"HodStudio.EntityFrameworkDiffLog" /o:"hodstudio-github" /d:sonar.sources=".\src\HodStudio.EntityFrameworkDiffLog" /d:sonar.host.url="https://sonarcloud.io" /version:"$completeVersion" /d:sonar.coverageReportPaths="$($env:APPVEYOR_BUILD_FOLDER)\testresults\SonarQube.xml" }
96142
}
97143

98144
exec { & dotnet build $libraryOnlySolutionPath -c Release }
99145

146+
dotnet test -c Release -s "$($env:APPVEYOR_BUILD_FOLDER)\coverletArgs.runsettings" -r "$($env:APPVEYOR_BUILD_FOLDER)\TestResults\"
147+
148+
exec { & reportgenerator "-reports:$($env:APPVEYOR_BUILD_FOLDER)\TestResults\*\*.xml" "-targetdir:$($env:APPVEYOR_BUILD_FOLDER)\TestResults\" "-reporttypes:SonarQube" }
149+
100150
exec { & dotnet sonarscanner end /d:sonar.login="$env:sonartoken" }
101151

102152
echo "Packing the library"
103-
exec { & dotnet pack $projectPath -c Release -o .\..\..\artifacts --version-suffix=$revision }
153+
exec { & dotnet pack $projectPath -c Release -o "$($env:APPVEYOR_BUILD_FOLDER)\artifacts" --version-suffix=$revision }

scripts/Coverage.ps1

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Taken from psake https://github.com/psake/psake
2+
3+
<#
4+
.SYNOPSIS
5+
This is a helper function that runs a scriptblock and checks the PS variable $lastexitcode
6+
to see if an error occcured. If an error is detected then an exception is thrown.
7+
This function allows you to run command-line programs without having to
8+
explicitly check the $lastexitcode variable.
9+
.EXAMPLE
10+
exec { svn info $repository_trunk } "Error executing SVN. Please verify SVN command-line client is installed"
11+
#>
12+
function Exec
13+
{
14+
[CmdletBinding()]
15+
param(
16+
[Parameter(Position=0,Mandatory=1)][scriptblock]$cmd,
17+
[Parameter(Position=1,Mandatory=0)][string]$errorMessage = ($msgs.error_bad_command -f $cmd)
18+
)
19+
& $cmd
20+
if ($lastexitcode -ne 0) {
21+
throw ("Exec: " + $errorMessage)
22+
}
23+
}
24+
25+
$projectPath = ".\src\HodStudio.EntityFrameworkDiffLog\HodStudio.EntityFrameworkDiffLog.csproj"
26+
$libraryOnlySolutionPath = ".\src\HodStudio.EntityFrameworkDiffLog\HodStudio.EntityFrameworkDiffLog.Library.sln"
27+
28+
if(Test-Path .\artifacts) { Remove-Item .\artifacts -Force -Recurse }
29+
if(Test-Path .\testresults) { Remove-Item .\testresults -Force -Recurse }
30+
31+
# Restore packages
32+
echo "Restoring packages"
33+
exec { & dotnet restore }
34+
35+
echo "Build entire solution"
36+
exec { & dotnet build -c Release }
37+
38+
echo "Tests Core version"
39+
dotnet test -c Release -s coverletArgs.runsettings -r ".\TestResults\"
40+
41+
echo "Installing reportgenerator"
42+
Try
43+
{
44+
exec { & dotnet tool install -g dotnet-reportgenerator-globaltool }
45+
}
46+
Catch
47+
{
48+
$needInstallSonar = dotnet tool list -g | Select-String -Pattern "dotnet-reportgenerator-globaltool" | % { $_.Matches.Value -eq $NULL }
49+
if ($needInstallSonar -eq $true)
50+
{
51+
$ErrorMessage = $_.Exception.Message
52+
$FailedItem = $_.Exception.ItemName
53+
echo $FailedItem
54+
echo $ErrorMessage
55+
return -1
56+
}
57+
else { echo "reportgenerator already installed" }
58+
}
59+
60+
exec { & reportgenerator "-reports:TestResults\*\*.xml" "-targetdir:TestResults\" "-reporttypes:Badges;Html;SonarQube" }

src/HodStudio.EntityFrameworkDiffLog.TestsDotNet45/IdGeneratedByApp/IdGeneratedByAppBaseTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ protected virtual Department CreateDepartment()
1717
=> new Department()
1818
{
1919
Code = Guid.NewGuid(),
20-
Budget = DateTime.Now.Ticks
20+
Budget = DateTime.Now.Millisecond
2121
};
2222

2323
protected virtual Department PrepareDepartment()

src/HodStudio.EntityFrameworkDiffLog.TestsDotNet45/IdGeneratedByApp/UpdateOperationsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class UpdateOperationsTests : IdGeneratedByAppBaseTests
2121

2222
var updated = Context.Departments.Find(original.Id);
2323
var newDepartment = CreateDepartment();
24-
updated.Budget = newDepartment.Budget;
24+
updated.Budget = original.Budget + 10;
2525
updated.Code = newDepartment.Code;
2626

2727
return (original, updated);

src/HodStudio.EntityFrameworkDiffLog.TestsDotNetCore/HodStudio.EntityFrameworkDiffLog.TestsDotNetCore.csproj

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,19 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10+
<PackageReference Include="coverlet.collector" Version="1.1.0">
11+
<PrivateAssets>all</PrivateAssets>
12+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
13+
</PackageReference>
14+
<PackageReference Include="coverlet.msbuild" Version="2.7.0">
15+
<PrivateAssets>all</PrivateAssets>
16+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
17+
</PackageReference>
1018
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="2.2.6" />
11-
<PackageReference Include="nunit" Version="3.12.0" />
12-
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
13-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
19+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
20+
<PackageReference Include="NUnit" Version="3.12.0" />
21+
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
22+
<PackageReference Include="NunitXml.TestLogger" Version="2.1.41" />
1423
</ItemGroup>
1524

1625
<ItemGroup>

src/HodStudio.EntityFrameworkDiffLog.TestsDotNetCore/IdGeneratedByApp/IdGeneratedByAppBaseTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ protected virtual Department CreateDepartment()
1717
=> new Department()
1818
{
1919
EffectiveFrom = DateTime.Now.AddDays(-DateTime.Now.Millisecond),
20-
Budget = DateTime.Now.Millisecond - (new Random()).Next(0, 100)
20+
Budget = DateTime.Now.Millisecond
2121
};
2222

2323
protected virtual Department PrepareDepartment()
@@ -50,7 +50,7 @@ protected virtual void ValidateLog(Department department)
5050
var currentLog = GetLog(department);
5151
Assert.IsNotNull(currentLog);
5252

53-
var expected = string.Format("{{\"Id\":[\"{0}\"],\"Budget\":[{1:N1}],\"EffectiveFrom\":[\"{2:yyyy-MM-ddTHH:mm:ss.FFFFFFFzzz}\"]}}",
53+
var expected = string.Format("{{\"Id\":[\"{0}\"],\"Budget\":[{1:F1}],\"EffectiveFrom\":[\"{2:yyyy-MM-ddTHH:mm:ss.FFFFFFFzzz}\"]}}",
5454
department.Id, department.Budget, department.EffectiveFrom);
5555
Assert.AreEqual(expected, currentLog.ValuesChanges);
5656
}

src/HodStudio.EntityFrameworkDiffLog.TestsDotNetCore/IdGeneratedByApp/UpdateOperationsTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class UpdateOperationsTests : IdGeneratedByAppBaseTests
1818

1919
var updated = CreateDepartment();
2020
updated.Id = original.Id;
21+
updated.Budget = original.Budget + 10;
2122

2223
Context.Departments.Update(updated);
2324
return (original, updated);
@@ -30,7 +31,7 @@ protected void Validate(Department original, Department updated)
3031
var currentLog = GetLog(updated);
3132
Assert.IsNotNull(currentLog);
3233

33-
var expected = string.Format("{{\"Budget\":[{0:N1},{1:N1}],\"EffectiveFrom\":[\"{2:yyyy-MM-ddTHH:mm:ss.FFFFFFFzzz}\",\"{3:yyyy-MM-ddTHH:mm:ss.FFFFFFFzzz}\"]}}",
34+
var expected = string.Format("{{\"Budget\":[{0:F1},{1:F1}],\"EffectiveFrom\":[\"{2:yyyy-MM-ddTHH:mm:ss.FFFFFFFzzz}\",\"{3:yyyy-MM-ddTHH:mm:ss.FFFFFFFzzz}\"]}}",
3435
original.Budget, updated.Budget,
3536
original.EffectiveFrom, updated.EffectiveFrom);
3637
Assert.AreEqual(expected, currentLog.ValuesChanges);

0 commit comments

Comments
 (0)