Skip to content

Commit b646cde

Browse files
committed
Build and tests
1 parent 8f81186 commit b646cde

28 files changed

+1653
-0
lines changed

Build.ps1

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
if(Test-Path .\artifacts) { Remove-Item .\artifacts -Force -Recurse }
26+
27+
28+
$branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$env:APPVEYOR_REPO_BRANCH -ne $NULL];
29+
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
30+
$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "master" -and $revision -ne "local"]
31+
$commitHash = $(git rev-parse --short HEAD)
32+
$buildSuffix = @{ $true = "$($suffix)-$($commitHash)"; $false = "$($branch)-$($commitHash)" }[$suffix -ne ""]
33+
34+
exec { & .\tools\rh.exe /d=ContosoUniversity /f=ContosoUniversity\App_Data /s="(LocalDb)\mssqllocaldb" /silent }
35+
exec { & .\tools\rh.exe /d=ContosoUniversity-Test /f=ContosoUniversity\App_Data /s="(LocalDb)\mssqllocaldb" /silent /drop }
36+
exec { & .\tools\rh.exe /d=ContosoUniversity-Test /f=ContosoUniversity\App_Data /s="(LocalDb)\mssqllocaldb" /silent /simple }
37+
38+
39+
exec { & dotnet restore }
40+
41+
exec { & dotnet build -c Release --version-suffix=$buildSuffix }
42+
43+
Push-Location -Path .\ContosoUniversity.IntegrationTests
44+
45+
try {
46+
exec { & dotnet test -c Release --no-build }
47+
}
48+
finally {
49+
Pop-Location
50+
}
51+
52+
#Push-Location -Path .\test\ContosoUniversity.UnitTests
53+
54+
#try {
55+
# exec { & dotnet test -c Release --no-build }
56+
#}
57+
#finally {
58+
# Pop-Location
59+
#}
60+
61+
exec { & dotnet publish ContosoUniversity --output .\..\publish --configuration Release }
62+
63+
$octo_revision = @{ $true = $env:APPVEYOR_BUILD_NUMBER; $false = "0" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
64+
$octo_version = "1.0.$octo_revision"
65+
66+
exec { & .\tools\Octo.exe pack --id ContosoUniversity --version $octo_version --basePath publish --outFolder artifacts }
67+
68+
69+
70+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<None Update="appsettings.json">
9+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
10+
</None>
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0-preview-20170810-02" />
15+
<PackageReference Include="xunit" Version="2.3.0-beta4-build3742" />
16+
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta1-build3642" />
17+
<PackageReference Include="Shouldly" Version="3.0.0-beta0003" />
18+
<PackageReference Include="Respawn" Version="0.3.0" />
19+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.0" />
20+
<PackageReference Include="FakeItEasy" Version="4.0.0" />
21+
<PackageReference Include="Microsoft.NETCore.Platforms" Version="2.0.0" />
22+
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta4-build3742" />
23+
</ItemGroup>
24+
25+
<ItemGroup>
26+
<ProjectReference Include="..\ContosoUniversity\ContosoUniversity.csproj" />
27+
</ItemGroup>
28+
29+
</Project>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
namespace ContosoUniversity.IntegrationTests.Features.Courses
2+
{
3+
using System;
4+
using Microsoft.EntityFrameworkCore;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using ContosoUniversity.Features.Courses;
8+
using Models;
9+
using Shouldly;
10+
using Xunit;
11+
using static SliceFixture;
12+
13+
public class CreateTests : IntegrationTestBase
14+
{
15+
[Fact]
16+
public async Task Should_create_new_course()
17+
{
18+
var adminId = await SendAsync(new ContosoUniversity.Features.Instructors.CreateEdit.Command
19+
{
20+
FirstMidName = "George",
21+
LastName = "Costanza",
22+
HireDate = DateTime.Today,
23+
});
24+
25+
var dept = new Department
26+
{
27+
Name = "History",
28+
InstructorID = adminId,
29+
Budget = 123m,
30+
StartDate = DateTime.Today
31+
};
32+
33+
34+
Create.Command command = null;
35+
36+
await ExecuteDbContextAsync(async (ctxt, mediator) =>
37+
{
38+
await ctxt.Departments.AddAsync(dept);
39+
command = new Create.Command
40+
{
41+
Credits = 4,
42+
Department = dept,
43+
Number = 1234,
44+
Title = "English 101"
45+
};
46+
await mediator.Send(command);
47+
});
48+
49+
var created = await ExecuteDbContextAsync(db => db.Courses.Where(c => c.Id == command.Number).SingleOrDefaultAsync());
50+
51+
created.ShouldNotBeNull();
52+
created.DepartmentID.ShouldBe(dept.Id);
53+
created.Credits.ShouldBe(command.Credits);
54+
created.Title.ShouldBe(command.Title);
55+
}
56+
}
57+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
using System;
2+
using System.Linq;
3+
using System.Threading.Tasks;
4+
using ContosoUniversity.Features.Courses;
5+
using ContosoUniversity.Models;
6+
using Shouldly;
7+
using Xunit;
8+
using Microsoft.EntityFrameworkCore;
9+
using static ContosoUniversity.IntegrationTests.SliceFixture;
10+
11+
12+
namespace ContosoUniversity.IntegrationTests.Features.Courses
13+
{
14+
public class DeleteTests : IntegrationTestBase
15+
{
16+
[Fact]
17+
public async Task Should_query_for_command()
18+
{
19+
var adminId = await SendAsync(new ContosoUniversity.Features.Instructors.CreateEdit.Command
20+
{
21+
FirstMidName = "George",
22+
LastName = "Costanza",
23+
HireDate = DateTime.Today,
24+
});
25+
26+
var dept = new Department
27+
{
28+
Name = "History",
29+
InstructorID = adminId,
30+
Budget = 123m,
31+
StartDate = DateTime.Today
32+
};
33+
34+
var course = new Course
35+
{
36+
Credits = 4,
37+
Department = dept,
38+
Id = 1234,
39+
Title = "English 101"
40+
};
41+
42+
await InsertAsync(dept, course);
43+
44+
var result = await SendAsync(new Delete.Query {Id = course.Id});
45+
46+
result.ShouldNotBeNull();
47+
result.Credits.ShouldBe(course.Credits);
48+
result.DepartmentName.ShouldBe(dept.Name);
49+
result.Title.ShouldBe(course.Title);
50+
}
51+
52+
[Fact]
53+
public async Task Should_delete()
54+
{
55+
var adminId = await SendAsync(new ContosoUniversity.Features.Instructors.CreateEdit.Command
56+
{
57+
FirstMidName = "George",
58+
LastName = "Costanza",
59+
HireDate = DateTime.Today,
60+
});
61+
62+
var dept = new Department
63+
{
64+
Name = "History",
65+
InstructorID = adminId,
66+
Budget = 123m,
67+
StartDate = DateTime.Today
68+
};
69+
70+
var course = new Course
71+
{
72+
Credits = 4,
73+
Department = dept,
74+
Id = 1234,
75+
Title = "English 101"
76+
};
77+
78+
await InsertAsync(dept, course);
79+
80+
await SendAsync(new Delete.Command {Id = course.Id});
81+
82+
var result = await ExecuteDbContextAsync(db => db.Courses.Where(c => c.Id == course.Id).SingleOrDefaultAsync());
83+
84+
result.ShouldBeNull();
85+
}
86+
}
87+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
namespace ContosoUniversity.IntegrationTests.Features.Courses
2+
{
3+
using System;
4+
using System.Threading.Tasks;
5+
using ContosoUniversity.Features.Courses;
6+
using Models;
7+
using Shouldly;
8+
using Xunit;
9+
using static SliceFixture;
10+
11+
public class DetailsTests : IntegrationTestBase
12+
{
13+
[Fact]
14+
public async Task Should_query_for_details()
15+
{
16+
var adminId = await SendAsync(new ContosoUniversity.Features.Instructors.CreateEdit.Command
17+
{
18+
FirstMidName = "George",
19+
LastName = "Costanza",
20+
HireDate = DateTime.Today,
21+
});
22+
23+
var dept = new Department
24+
{
25+
Name = "History",
26+
InstructorID = adminId,
27+
Budget = 123m,
28+
StartDate = DateTime.Today
29+
};
30+
31+
var course = new Course
32+
{
33+
Credits = 4,
34+
Department = dept,
35+
Id = 1234,
36+
Title = "English 101"
37+
};
38+
39+
await InsertAsync(dept, course);
40+
41+
var result = await SendAsync(new Details.Query { Id = course.Id });
42+
43+
result.ShouldNotBeNull();
44+
result.Credits.ShouldBe(course.Credits);
45+
result.DepartmentName.ShouldBe(dept.Name);
46+
result.Title.ShouldBe(course.Title);
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)