Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
14a3bb3
Set up CI with Azure Pipelines
codebytes Apr 18, 2020
2b14c7a
Update azure-pipelines.yml for Azure Pipelines
codebytes Apr 18, 2020
cfdc130
added coverlet for test coverage reporting
codebytes Apr 18, 2020
0dd80c0
Set up CI with Azure Pipelines
codebytes Apr 18, 2020
f8bb9ed
Update azure-pipelines.yml for Azure Pipelines
codebytes Apr 18, 2020
e433aad
Merge branch 'azure-pipelines' of https://github.com/Codebytes/UnitTe…
codebytes Apr 18, 2020
513a491
updated references
codebytes Apr 18, 2020
a7331bf
Update azure-pipelines.yml for Azure Pipelines
codebytes Apr 18, 2020
12d9b17
Added coverlet msbuild package to test projects
codebytes Apr 18, 2020
3daec11
Update azure-pipelines.yml for Azure Pipelines
codebytes Apr 18, 2020
6763a41
added package locks
codebytes Apr 18, 2020
7fe3499
try to fix restore
codebytes Apr 18, 2020
300812c
fix unit tests
codebytes Apr 18, 2020
852c77c
updated packages
codebytes Apr 18, 2020
7c521fd
updated packeges.lock
codebytes Apr 18, 2020
bd59f2c
removed all package locks
codebytes Apr 18, 2020
0c194dc
removed package cache
codebytes Apr 18, 2020
fc293ab
Resolved test issue
codebytes Apr 18, 2020
351994b
tweak pipeline
codebytes Apr 18, 2020
bb9b635
Update azure-pipelines.yml for Azure Pipelines
codebytes Apr 19, 2020
87742e7
Update azure-pipelines.yml for Azure Pipelines
codebytes Apr 19, 2020
1e1274f
Update azure-pipelines.yml for Azure Pipelines
codebytes Apr 19, 2020
c7cc24f
Update azure-pipelines.yml for Azure Pipelines
codebytes Apr 19, 2020
6a8792a
Update azure-pipelines.yml for Azure Pipelines
codebytes Apr 19, 2020
36cd331
Update azure-pipelines.yml for Azure Pipelines
codebytes Apr 19, 2020
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
18 changes: 9 additions & 9 deletions UnitTestingDemo.sln
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.421
# Visual Studio Version 16
VisualStudioVersion = 16.0.30011.22
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTestingDemo", "src\UnitTestingDemo\UnitTestingDemo.csproj", "{55970F10-87CB-4F50-B14B-6AB8258D22DD}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTestingDemo", "src\UnitTestingDemo\UnitTestingDemo.csproj", "{55970F10-87CB-4F50-B14B-6AB8258D22DD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTestingDemo.Data", "src\UnitTestingDemo.Data\UnitTestingDemo.Data.csproj", "{54963324-B96D-4FB5-8B11-E00B9FC9016B}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTestingDemo.Data", "src\UnitTestingDemo.Data\UnitTestingDemo.Data.csproj", "{54963324-B96D-4FB5-8B11-E00B9FC9016B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTestingDemo.Services", "src\UnitTestingDemo.Services\UnitTestingDemo.Services.csproj", "{6C2AF4F6-5FDE-4B8D-BD4F-8D0C424E2F1F}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTestingDemo.Services", "src\UnitTestingDemo.Services\UnitTestingDemo.Services.csproj", "{6C2AF4F6-5FDE-4B8D-BD4F-8D0C424E2F1F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTestingDemo.Domain", "src\UnitTestingDemo.Domain\UnitTestingDemo.Domain.csproj", "{959885B8-F972-42C6-8E2B-CA910CF643A8}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTestingDemo.Domain", "src\UnitTestingDemo.Domain\UnitTestingDemo.Domain.csproj", "{959885B8-F972-42C6-8E2B-CA910CF643A8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{CDB88796-4BCF-4578-89B8-100D596CDBF3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTestingDemo.Data.Tests", "tests\UnitTestingDemo.Data.Tests\UnitTestingDemo.Data.Tests.csproj", "{EF7E491B-D3AC-4535-BE9D-9F1ECBD20D4F}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTestingDemo.Data.Tests", "tests\UnitTestingDemo.Data.Tests\UnitTestingDemo.Data.Tests.csproj", "{EF7E491B-D3AC-4535-BE9D-9F1ECBD20D4F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTestingDemo.Tests", "tests\UnitTestingDemo.Tests\UnitTestingDemo.Tests.csproj", "{511C1EC4-057A-4AF4-A3EF-5563800B3653}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTestingDemo.Tests", "tests\UnitTestingDemo.Tests\UnitTestingDemo.Tests.csproj", "{511C1EC4-057A-4AF4-A3EF-5563800B3653}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTestingDemo.Services.Tests", "tests\UnitTestingDemo.Services.Tests\UnitTestingDemo.Services.Tests.csproj", "{B2998F44-32A3-4987-83F3-307F7A423EF2}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTestingDemo.Services.Tests", "tests\UnitTestingDemo.Services.Tests\UnitTestingDemo.Services.Tests.csproj", "{B2998F44-32A3-4987-83F3-307F7A423EF2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
80 changes: 80 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# ASP.NET Core (.NET Framework)
# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core

trigger:
- master

pool:
vmImage: 'windows-latest'

variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
NUGET_PACKAGES: $(Pipeline.Workspace)/.nuget/packages

steps:
- task: DotNetCoreCLI@2
displayName: Restore nuget packages
inputs:
command: restore
projects: '**/*.csproj'
arguments: '--locked-mode'
workingDirectory: $(Build.SourcesDirectory)

- task: DotNetCoreCLI@2
displayName: Build
inputs:
command: build
projects: '$(solution)'
arguments: '--configuration $(buildConfiguration)'

# Run all tests with "/p:CollectCoverage=true /p:CoverletOutputFormat=cobertura" to generate the code coverage file
- task: DotNetCoreCLI@2
displayName: Test
inputs:
command: test
arguments: '--configuration $(BuildConfiguration) /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura'
projects: '$(solution)'
nobuild: true
continueOnError: true

# Generate the report using ReportGenerator (https://github.com/danielpalme/ReportGenerator)
# First install the tool on the machine, then run it
- script: |
dotnet tool install -g dotnet-reportgenerator-globaltool
reportgenerator -reports:$(Build.SourcesDirectory)/tests/**/coverage.cobertura.xml -targetdir:$(Build.SourcesDirectory)/CodeCoverage -reporttypes:Cobertura
displayName: Create Code coverage report

# Publish the code coverage result (summary and web site)
# The summary allows to view the coverage percentage in the summary tab
# The web site allows to view which lines are covered directly in Azure Pipeline
- task: PublishCodeCoverageResults@1
displayName: 'Publish code coverage'
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(Build.SourcesDirectory)/CodeCoverage/Cobertura.xml'
reportDirectory: '$(Build.SourcesDirectory)/CodeCoverage'
pathToSources: '$(Build.SourcesDirectory)'

- task: PublishTestResults@2
inputs:
testResultsFormat: 'VSTest'
testResultsFiles: '**/TEST-*.xml'
mergeTestResults: true
failTaskOnFailedTests: true

- task: DotNetCoreCLI@2
inputs:
command: publish
publishWebProjects: True
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: True

- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
1 change: 0 additions & 1 deletion src/UnitTestingDemo.Data/UnitTestingDemo.Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@
<ItemGroup>
<ProjectReference Include="..\UnitTestingDemo.Domain\UnitTestingDemo.Domain.csproj" />
</ItemGroup>

</Project>
1 change: 0 additions & 1 deletion src/UnitTestingDemo.Domain/UnitTestingDemo.Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@
<ProjectReference Include="..\UnitTestingDemo.Domain\UnitTestingDemo.Domain.csproj" />
<ProjectReference Include="..\UnitTestingDemo.Data\UnitTestingDemo.Data.csproj" />
</ItemGroup>

</Project>
1 change: 0 additions & 1 deletion src/UnitTestingDemo/UnitTestingDemo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@
<ProjectReference Include="..\UnitTestingDemo.Services\UnitTestingDemo.Services.csproj" />
<ProjectReference Include="..\UnitTestingDemo.Domain\UnitTestingDemo.Domain.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,34 @@ namespace UnitTestingDemo.Data.Tests
[TestClass]
public class BookRepositoryTestsWithInMemoryDB
{
readonly List<BookEntity> _books = new List<BookEntity>
private readonly AuthorEntity shakespeare = new AuthorEntity
{
new BookEntity
Id = 1,
FirstName = "William",
LastName = "Shakespeare",
Books = new List<BookEntity>
{
Id = 1,
Title = "Hamlet",
Author = new AuthorEntity
new BookEntity
{
Id = 1,
FirstName = "William",
LastName = "Shakespeare"
}
},
new BookEntity
{
Id = 2,
Title = "A Midsummer Night's Dream",
Author = new AuthorEntity
Title = "Hamlet",
Author = new AuthorEntity
{
Id = 1,
FirstName = "William",
LastName = "Shakespeare"
}
},
new BookEntity
{
Id = 1,
FirstName = "William",
LastName = "Shakespeare"
Id = 2,
Title = "A Midsummer Night's Dream",
Author = new AuthorEntity
{
Id = 1,
FirstName = "William",
LastName = "Shakespeare"
}
}
}
};
Expand All @@ -47,7 +53,7 @@ public void GetAll_WithItems_returnsAll()
.Options;
using (var context = new BookContext(options))
{
context.Books.AddRange(_books);
context.Authors.Add(shakespeare);
context.SaveChanges();
}

Expand All @@ -60,7 +66,7 @@ public void GetAll_WithItems_returnsAll()
}

//assert
Assert.AreEqual(_books.Count(), result.Count);
Assert.AreEqual(shakespeare.Books.Count(), result.Count);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using EntityFrameworkCoreMock;
using Microsoft.EntityFrameworkCore;
using EntityFrameworkCore3Mock;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using UnitTestingDemo.Data.Contexts;
using UnitTestingDemo.Data.EntityModels;

Expand All @@ -13,7 +11,7 @@ namespace UnitTestingDemo.Data.Tests
public class BookRepositoryTestsWithMocks2
{
private BookRepository _bookRepository;
private Mock<BookContext> _mockBookContext;
private DbContextMock<BookContext> _mockBookContext;
private IQueryable<BookEntity> _books;

[TestInitialize]
Expand All @@ -31,7 +29,7 @@ public void TestInitialize()
FirstName = "William",
LastName = "Shakespeare"
}
},
},
new BookEntity
{
Id = 2,
Expand All @@ -45,8 +43,9 @@ public void TestInitialize()
}
}.AsQueryable();

var _mockBookContext = new DbContextMock<BookContext>(new DbContextOptionsBuilder<BookContext>().Options);
_mockBookContext = new DbContextMock<BookContext>();
var bookDbSetMock = _mockBookContext.CreateDbSetMock(x => x.Books, _books);

_bookRepository = new BookRepository(_mockBookContext.Object);
}

Expand Down
18 changes: 14 additions & 4 deletions tests/UnitTestingDemo.Data.Tests/UnitTestingDemo.Data.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk">


<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>

<IsPackable>false</IsPackable>

<OutputType>Library</OutputType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EntityFrameworkCoreMock.Moq" Version="1.0.0.30" />
<PackageReference Include="coverlet.msbuild" Version="2.8.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="EntityFrameworkCore3Mock.Moq" Version="1.0.0.3" />
<PackageReference Include="EntityFrameworkCore3Mock.Shared" Version="1.0.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.1" />
<PackageReference Include="coverlet.collector" Version="1.2.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>


<ItemGroup>
<ProjectReference Include="..\..\src\UnitTestingDemo.Data\UnitTestingDemo.Data.csproj" />
<ProjectReference Include="..\..\src\UnitTestingDemo.Domain\UnitTestingDemo.Domain.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">


<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>

<IsPackable>false</IsPackable>

<OutputType>Library</OutputType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="2.8.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.1" />
<PackageReference Include="coverlet.collector" Version="1.2.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>


<ItemGroup>
<ProjectReference Include="..\..\src\UnitTestingDemo.Domain\UnitTestingDemo.Domain.csproj" />
<ProjectReference Include="..\..\src\UnitTestingDemo.Data\UnitTestingDemo.Data.csproj" />
<ProjectReference Include="..\..\src\UnitTestingDemo.Services\UnitTestingDemo.Services.csproj" />
</ItemGroup>

</Project>
13 changes: 11 additions & 2 deletions tests/UnitTestingDemo.Tests/UnitTestingDemo.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">


<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>

<IsPackable>false</IsPackable>

<OutputType>Library</OutputType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="2.8.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.1" />
<PackageReference Include="coverlet.collector" Version="1.2.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>


<ItemGroup>
<ProjectReference Include="..\..\src\UnitTestingDemo.Services\UnitTestingDemo.Services.csproj" />
<ProjectReference Include="..\..\src\UnitTestingDemo.Domain\UnitTestingDemo.Domain.csproj" />
Expand Down