Skip to content

Commit 23e58ea

Browse files
committed
Setting up build pipeline with github actions
1 parent 4c7fdaf commit 23e58ea

File tree

11 files changed

+123
-28
lines changed

11 files changed

+123
-28
lines changed

.github/workflows/build.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Build + Test
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
schedule:
9+
- cron: "0 1 * * *"
10+
11+
jobs:
12+
build:
13+
runs-on: windows-latest
14+
15+
steps:
16+
- uses: actions/checkout@v2
17+
- name: Setup .NET Core
18+
uses: actions/setup-dotnet@v1
19+
with:
20+
dotnet-version: '3.1.x' # SDK Version to use; x will use the latest version of the 3.1 channel
21+
- name: Create folder
22+
run: mkdir BuildReports
23+
- name: Install dependencies
24+
run: dotnet restore --verbosity m > BuildReports/Restore.txt
25+
- name: Build
26+
run: dotnet build --no-restore --verbosity m --configuration Release > BuildReports/Build.txt
27+
- name: Test
28+
run: dotnet test --configuration Release > BuildReports/Tests.txt
29+
- name: Copy generated nuget file
30+
shell: bash
31+
run: find . -name "SystemTestingTools*.nupkg" -exec cp "{}" ./ \;
32+
- name: Set build report artifacts
33+
if: ${{ always() }} # run this step even if previous steps failed
34+
uses: actions/upload-artifact@v2
35+
with:
36+
name: BuildReports
37+
path: |
38+
BuildReports/**
39+
retention-days: 7
40+
if-no-files-found: error
41+
- name: Set nuget package artifact
42+
if: ${{ success() }} # run this step even if previous steps failed
43+
uses: actions/upload-artifact@v2
44+
with:
45+
name: Nugget package
46+
path: SystemTestingTools*.nupkg
47+
retention-days: 7
48+
if-no-files-found: error

Examples/MovieProject/MovieProject.Logic/Extensions/StringExtensions.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,25 @@ public static string FormatDuration(this string durationInMinutes)
2828
}
2929

3030
// example 1998-2005
31-
private static readonly Regex seriesYearsRegex = new Regex("^(19|20)[0-9]{2}–(19|20)[0-9]{2}$");
31+
private static readonly Regex seriesYearsRegex = new Regex("^(19|20)[0-9]{2}–(19|20)[0-9]{2}$", RegexOptions.Compiled);
3232
public static string CleanYear(this string yearString)
3333
{
3434
if (string.IsNullOrWhiteSpace(yearString)) return Constants.Unknown;
3535

3636
yearString = yearString.Trim();
37-
if (seriesYearsRegex.IsMatch(yearString)) return yearString;
37+
if (seriesYearsRegex.IsMatch(yearString))
38+
{
39+
yearString = yearString.Replace("-", " to ").Replace("–", " to ");
40+
return yearString;
41+
}
3842

3943
if (!int.TryParse(yearString, out var year)) return Constants.Unknown;
4044

4145
if(year < 1888) // the year of the first movie
4246
return Constants.Unknown;
4347

4448
if(year > DateTime.Now.Year +20) // sometimes the service returns in production movies
45-
return Constants.Unknown;
49+
return Constants.Unknown;
4650

4751
return year.ToString();
4852
}

Examples/MovieProject/MovieProject.Tests/MovieProject.IntegrationTests/MovieDatabaseProxyTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public async Task CanRetrieveTvSeries_TheBigBangTheory()
6262
result.Should().NotBeNull();
6363
result.Id.Should().Be("tt0898266");
6464
result.Name.Should().Be("The Big Bang Theory");
65-
result.Year.Should().Be("20072019");
65+
result.Year.Should().Be("2007 to 2019");
6666

6767
logger.DidNotReceiveWithAnyArgs().Log(LogLevel.Critical, "", null);
6868
}

Examples/MovieProject/MovieProject.Tests/MovieProject.IsolatedTests/ComponentTesting/TestServerFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public TestServerFixture()
3131

3232
private void StartServer()
3333
{
34-
StubsFolder = new Regex(@"\\bin\\.*").Replace(System.Environment.CurrentDirectory, "") + @"\ComponentTesting\Stubs";
34+
StubsFolder = EnvironmentHelper.GetProjectFolder("ComponentTesting/Stubs");
3535

3636
var builder = Program.CreateWebHostBuilder(new string[0]) // use the exact same builder as the website, to test the wiring
3737
.ConfigureAppConfiguration((hostingContext, config) =>

Tool/SystemTestingTools.UnitTests/MockEndpointHappyTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ public class StubResponseFactoryHappyTests
1313
private string FilesFolder;
1414
public StubResponseFactoryHappyTests()
1515
{
16-
FilesFolder = new Regex(@"\\bin\\.*").Replace(System.Environment.CurrentDirectory, "") + @"\files\";
16+
FilesFolder = EnvironmentHelper.GetProjectFolder("files/");
1717
}
1818

1919
[Fact]
2020
public async Task Read401File()
2121
{
22-
var sut = ResponseFactory.FromFiddlerLikeResponseFile( FilesFolder + @"happy\401_InvalidKey.txt");
22+
var sut = ResponseFactory.FromFiddlerLikeResponseFile( FilesFolder + @"happy/401_InvalidKey.txt");
2323

2424
sut.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
2525
sut.Headers.ShouldContainHeader("Server", "cloudflare");
@@ -33,7 +33,7 @@ public async Task Read401File()
3333
[Fact]
3434
public async Task Read401File_WithoutBody()
3535
{
36-
var sut = ResponseFactory.FromFiddlerLikeResponseFile( FilesFolder + @"happy\401_Unauthorized_WithoutBody.txt");
36+
var sut = ResponseFactory.FromFiddlerLikeResponseFile( FilesFolder + @"happy/401_Unauthorized_WithoutBody.txt");
3737

3838
sut.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
3939

@@ -58,7 +58,7 @@ public async Task Read401File_WithoutBody()
5858
[Fact]
5959
public async Task Read424File()
6060
{
61-
var sut = ResponseFactory.FromFiddlerLikeResponseFile(FilesFolder + @"happy\424_NoHeaders.txt");
61+
var sut = ResponseFactory.FromFiddlerLikeResponseFile(FilesFolder + @"happy/424_NoHeaders.txt");
6262

6363
sut.StatusCode.Should().Be(HttpStatusCode.FailedDependency);
6464

@@ -70,7 +70,7 @@ public async Task Read424File()
7070
[Fact]
7171
public async Task Read200File()
7272
{
73-
var sut = ResponseFactory.FromFiddlerLikeResponseFile(FilesFolder + @"happy\200_MovieNotFound.txt");
73+
var sut = ResponseFactory.FromFiddlerLikeResponseFile(FilesFolder + @"happy/200_MovieNotFound.txt");
7474

7575
sut.StatusCode.Should().Be(HttpStatusCode.OK);
7676

@@ -100,7 +100,7 @@ public async Task Read200File()
100100
[Fact]
101101
public async Task Read200WithComments()
102102
{
103-
var sut = ResponseFactory.FromFiddlerLikeResponseFile(FilesFolder + @"happy\200_WithComments.txt");
103+
var sut = ResponseFactory.FromFiddlerLikeResponseFile(FilesFolder + @"happy/200_WithComments.txt");
104104

105105
sut.StatusCode.Should().Be(HttpStatusCode.OK);
106106

@@ -126,7 +126,7 @@ public async Task Read200WithComments()
126126
[Fact]
127127
public async Task FromBodyOnlyFile()
128128
{
129-
var fullFileName = FilesFolder + @"happy\OnlyBody.txt";
129+
var fullFileName = FilesFolder + @"happy/OnlyBody.txt";
130130

131131
var sut = ResponseFactory.FromBodyOnlyFile(fullFileName, HttpStatusCode.OK);
132132

Tool/SystemTestingTools.UnitTests/MockEndpointUnhappyTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class StubResponseFactoryUnhappyTests
1212
private string FilesFolder;
1313
public StubResponseFactoryUnhappyTests()
1414
{
15-
FilesFolder = new Regex(@"\\bin\\.*").Replace(System.Environment.CurrentDirectory, "") + @"\files\";
15+
FilesFolder = EnvironmentHelper.GetProjectFolder("files/");
1616
}
1717

1818
[Fact]
@@ -29,7 +29,7 @@ public void FileDoesntExist()
2929
[Fact]
3030
public void FileIsEmpty()
3131
{
32-
var fullFileName = FilesFolder + @"unhappy\Empty.txt";
32+
var fullFileName = FilesFolder + @"unhappy/Empty.txt";
3333

3434
Action act = () => ResponseFactory.FromFiddlerLikeResponseFile(fullFileName);
3535

@@ -40,7 +40,7 @@ public void FileIsEmpty()
4040
[Fact]
4141
public void NoHttpStatusCode()
4242
{
43-
var fullFileName = FilesFolder + @"unhappy\NoHttpStatusCode.txt";
43+
var fullFileName = FilesFolder + @"unhappy/NoHttpStatusCode.txt";
4444

4545
Action act = () => ResponseFactory.FromFiddlerLikeResponseFile(fullFileName);
4646

@@ -52,7 +52,7 @@ public void NoHttpStatusCode()
5252
public void OnlyBody()
5353
{
5454
// should throw exception if we try to read with method FromFiddlerLikeResponseFile, but not FromBodyOnlyFile
55-
var fullFileName = FilesFolder + @"unhappy\OnlyBody.txt";
55+
var fullFileName = FilesFolder + @"unhappy/OnlyBody.txt";
5656

5757
Action act = () => ResponseFactory.FromFiddlerLikeResponseFile(fullFileName);
5858

@@ -63,7 +63,7 @@ public void OnlyBody()
6363
[Fact]
6464
public void InvalidHttpStatus()
6565
{
66-
var fullFileName = FilesFolder + @"unhappy\InvalidHttpStatus.txt";
66+
var fullFileName = FilesFolder + @"unhappy/InvalidHttpStatus.txt";
6767

6868
Action act = () => ResponseFactory.FromFiddlerLikeResponseFile(fullFileName);
6969

@@ -74,7 +74,7 @@ public void InvalidHttpStatus()
7474
[Fact]
7575
public void NoBody()
7676
{
77-
var fullFileName = FilesFolder + @"unhappy\401_NoBody.txt";
77+
var fullFileName = FilesFolder + @"unhappy/401_NoBody.txt";
7878

7979
var response = ResponseFactory.FromFiddlerLikeResponseFile(fullFileName);
8080

Tool/SystemTestingTools.UnitTests/RecordingManagerTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,13 @@ public void When_Files_Dont_Exist_Create_First_File()
8989
{
9090
var tempFolder = Path.GetTempPath();
9191
var fileSystem = Substitute.For<IFileSystemFacade>();
92-
fileSystem.GetTextFileNames(tempFolder, "bla").Returns(new List<string>());
92+
93+
fileSystem.GetTextFileNames(Path.Combine(tempFolder, "temp"), "bla").Returns(new List<string>());
9394
var sut = new RecordingManager(tempFolder);
9495
sut._fileSystem = fileSystem;
9596

9697
// act
97-
var fileName = sut.Save(CreateLog(), tempFolder, "bla");
98+
var fileName = sut.Save(CreateLog(), "temp", "bla");
9899

99100
// asserts
100101
fileName.Should().Be("bla_0001");

Tool/SystemTestingTools.UnitTests/ValueObjectsTests.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using FluentAssertions;
22
using FluentAssertions.Execution;
33
using System;
4+
using System.IO;
45
using System.Text.RegularExpressions;
56
using Xunit;
67

@@ -11,7 +12,7 @@ public class ValueObjectsTests
1112
private string FilesFolder;
1213
public ValueObjectsTests()
1314
{
14-
FilesFolder = new Regex(@"\\bin\\.*").Replace(System.Environment.CurrentDirectory, "") + @"\files\";
15+
FilesFolder = EnvironmentHelper.GetProjectFolder("files");
1516
}
1617

1718
[Fact]
@@ -41,8 +42,8 @@ public void FileName_Unhappy(string fileName, string expectedMessage)
4142
[Fact]
4243
public void FileFullPath_Happy()
4344
{
44-
FileFullPath file1 = FilesFolder + @"happy\401_InvalidKey";
45-
FileFullPath file2 = FilesFolder + @"happy\401_InvalidKey.txt";
45+
FileFullPath file1 = FilesFolder + @"/happy/401_InvalidKey";
46+
FileFullPath file2 = FilesFolder + @"/happy/401_InvalidKey.txt";
4647
}
4748

4849
[Fact]
@@ -55,7 +56,7 @@ public void FileFullPath_Empty_Unhappy()
5556
[Fact]
5657
public void FileFullPath_FileDoesntExist_Unhappy()
5758
{
58-
var fullFileName = FilesFolder + @"happy\401_InvalidKeyAAA";
59+
var fullFileName = FilesFolder + @"happy/401_InvalidKeyAAA";
5960

6061
var ex = Assert.Throws<ArgumentException>(() => { FileFullPath file = fullFileName; });
6162

@@ -65,10 +66,10 @@ public void FileFullPath_FileDoesntExist_Unhappy()
6566
[Fact]
6667
public void FolderAbsolutePath_Happy()
6768
{
68-
FolderAbsolutePath folder = FilesFolder + "happy";
69+
FolderAbsolutePath folder = FilesFolder + "/happy";
6970

7071
folder.AppendPath(null).Should().Be(folder);
71-
folder.AppendPath("bla").Should().Be(folder + @"\bla");
72+
folder.AppendPath("bla").Should().Be(Path.Combine(folder,"bla"));
7273
}
7374

7475
[Fact]
@@ -94,7 +95,7 @@ public void FolderRelativePath_Happy()
9495

9596
[Theory]
9697
[InlineData(" ", null)]
97-
[InlineData("some/invalid|path", "Invalid chars for folder name found: some/invalid|path")]
98+
[InlineData("some/invalid|path\0", "Invalid chars for folder name found: some/invalid|path\0")]
9899
public void FolderRelativePath_Unhappy(string folder, string expectedMessage)
99100
{
100101
if (expectedMessage == null)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Text;
5+
using System.Text.RegularExpressions;
6+
7+
namespace SystemTestingTools
8+
{
9+
/// <summary>
10+
/// Helper methods for environment setup
11+
/// </summary>
12+
public static class EnvironmentHelper
13+
{
14+
private static Regex folderCleanerRegex = new Regex(@"(\\bin\\.*)|(\/bin\/.*)", RegexOptions.Compiled);
15+
16+
/// <summary>
17+
/// Gets the path where the project is setup, and appends the extra folder name, useful to find your stubs
18+
/// </summary>
19+
/// <param name="folderName"></param>
20+
/// <returns></returns>
21+
public static string GetProjectFolder(string folderName)
22+
{
23+
var projectFolder = folderCleanerRegex.Replace(System.Environment.CurrentDirectory, "");
24+
var finalFolder = System.IO.Path.Combine(projectFolder, folderName);
25+
if (!Directory.Exists(finalFolder)) throw new ArgumentException($"Folder doesn't exist: {finalFolder}");
26+
return finalFolder;
27+
}
28+
}
29+
}

Tool/SystemTestingTools/SystemTestingTools.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
</ItemGroup>
3939

4040
<PropertyGroup Label="Version">
41-
<Version>1.0.0</Version>
41+
<Version>0.0.0</Version>
4242
</PropertyGroup>
4343

4444
<ItemGroup>

0 commit comments

Comments
 (0)