Skip to content

Commit 82c25e2

Browse files
authored
Add Github actions workflows for PRs (#137)
1 parent 27f3d25 commit 82c25e2

File tree

13 files changed

+134
-46
lines changed

13 files changed

+134
-46
lines changed

.github/workflows/pr-checks.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
6+
# This workflow will build, test, sign and package a WPF or Windows Forms desktop application
7+
# built on .NET Core.
8+
# To learn how to migrate your existing application to .NET Core,
9+
# refer to https://docs.microsoft.com/en-us/dotnet/desktop-wpf/migration/convert-project-from-net-framework
10+
#
11+
# To configure this workflow:
12+
#
13+
# 1. Configure environment variables
14+
# GitHub sets default environment variables for every workflow run.
15+
# Replace the variables relative to your project in the "env" section below.
16+
#
17+
# 2. Signing
18+
# Generate a signing certificate in the Windows Application
19+
# Packaging Project or add an existing signing certificate to the project.
20+
# Next, use PowerShell to encode the .pfx file using Base64 encoding
21+
# by running the following Powershell script to generate the output string:
22+
#
23+
# $pfx_cert = Get-Content '.\SigningCertificate.pfx' -Encoding Byte
24+
# [System.Convert]::ToBase64String($pfx_cert) | Out-File 'SigningCertificate_Encoded.txt'
25+
#
26+
# Open the output file, SigningCertificate_Encoded.txt, and copy the
27+
# string inside. Then, add the string to the repo as a GitHub secret
28+
# and name it "Base64_Encoded_Pfx."
29+
# For more information on how to configure your signing certificate for
30+
# this workflow, refer to https://github.com/microsoft/github-actions-for-desktop-apps#signing
31+
#
32+
# Finally, add the signing certificate password to the repo as a secret and name it "Pfx_Key".
33+
# See "Build the Windows Application Packaging project" below to see how the secret is used.
34+
#
35+
# For more information on GitHub Actions, refer to https://github.com/features/actions
36+
# For a complete CI/CD sample to get started with GitHub Action workflows for Desktop Applications,
37+
# refer to https://github.com/microsoft/github-actions-for-desktop-apps
38+
39+
name: PR Build Checks
40+
41+
on:
42+
pull_request:
43+
branches: [ master ]
44+
45+
jobs:
46+
47+
build:
48+
49+
strategy:
50+
matrix:
51+
configuration: [Debug, Release]
52+
dotnet-version: [ '4.8', '6.0.x' ]
53+
54+
runs-on: windows-latest # For a list of available runner types, refer to
55+
# https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on
56+
57+
env:
58+
Solution_Name: ReactiveDomain.sln
59+
60+
steps:
61+
- name: Checkout
62+
uses: actions/checkout@v3
63+
with:
64+
fetch-depth: 0
65+
66+
# Install the .NET Core workload
67+
- name: Install .NET ${{ matrix.dotnet-version }}
68+
if: ${{ matrix.dotnet-version == '6.0.x' }}
69+
uses: actions/setup-dotnet@v3
70+
with:
71+
dotnet-version: ${{ matrix.dotnet-version }}
72+
73+
# Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
74+
- name: Setup MSBuild.exe
75+
uses: microsoft/[email protected]
76+
77+
# Build all framework versions
78+
- name: Build all
79+
working-directory: src
80+
run: dotnet build $env:Solution_Name
81+
82+
# Execute all unit tests in the solution
83+
- name: Execute unit tests with .NET Framework
84+
if: ${{ matrix.dotnet-version == '4.8' }}
85+
working-directory: src
86+
run: dotnet test $env:Solution_Name -f net48 -p:ParallelizeTestCollections=false
87+
88+
# Execute all unit tests in the solution
89+
- name: Execute unit tests with .NET
90+
if: ${{ matrix.dotnet-version == '6.0.x' }}
91+
working-directory: src
92+
run: dotnet test $env:Solution_Name -f net6.0 -p:ParallelizeTestCollections=false

src/ReactiveDomain.Foundation.Tests/when_using_read_model_base.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public void can_wait_for_two_streams_to_go_live() {
113113
AssertEx.IsOrBecomesTrue(() => Sum == 20, 100);
114114

115115
Start(_stream2, null, true);
116-
AssertEx.IsOrBecomesTrue(() => Count == 20, 10, msg: $"Expected 20 got {Count}");
116+
AssertEx.IsOrBecomesTrue(() => Count == 20, 100, msg: $"Expected 20 got {Count}");
117117
AssertEx.IsOrBecomesTrue(() => Sum == 50, 100);
118118
}
119119
[Fact]

src/ReactiveDomain.Foundation.Tests/when_using_read_model_base_with_reader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public void can_wait_for_two_streams_to_go_live()
115115
AssertEx.IsOrBecomesTrue(() => Sum == 20, 100);
116116

117117
Start(_stream2, null, true);
118-
AssertEx.IsOrBecomesTrue(() => Count == 20, 10, msg: $"Expected 20 got {Count}");
118+
AssertEx.IsOrBecomesTrue(() => Count == 20, 100, msg: $"Expected 20 got {Count}");
119119
AssertEx.IsOrBecomesTrue(() => Sum == 50, 100);
120120
}
121121
[Fact]

src/ReactiveDomain.IdentityStorage.Tests/SubjectRmTests.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using ReactiveDomain.Testing;
33
using System;
44
using System.Collections.Generic;
5+
using System.Linq;
56
using ReactiveDomain.IdentityStorage.Domain;
67
using ReactiveDomain.IdentityStorage.Messages;
78
using ReactiveDomain.IdentityStorage.ReadModels;
@@ -28,12 +29,14 @@ public SubjectRmTests()
2829
[Fact]
2930
public void readmodel_lists_existing_subjects()
3031
{
32+
AssertEx.IsOrBecomesTrue(() => _rm.SubjectsByUserId.Any() && _subjects.First().Value.Count == _rm.SubjectsByUserId.First().Value.Count);
3133
Assert.Equal(_subjects, _rm.SubjectsByUserId);
3234
}
3335
[Fact]
3436
public void readmodel_lists_added_subjects()
3537
{
3638
AddNewSubject();
39+
AssertEx.IsOrBecomesTrue(() => _rm.SubjectsByUserId.Any() && _subjects.First().Value.Count == _rm.SubjectsByUserId.First().Value.Count);
3740
Assert.Equal(_subjects, _rm.SubjectsByUserId);
3841
}
3942

@@ -44,6 +47,8 @@ public void readmodel_lists_multiple_domains()
4447
AddNewSubject(userId, provider: AuthProvider, domain: AuthDomain);
4548
AddNewSubject(provider: AuthProvider2, domain: "other1");
4649
AddNewSubject(provider: AuthProvider2, domain: "other2");
50+
AssertEx.IsOrBecomesTrue(() => _rm.SubjectsByUserId.Any() && _subjects.First().Value.Count == _rm.SubjectsByUserId.First().Value.Count);
51+
AssertEx.IsOrBecomesTrue(() => _rm.SubjectsByUserId.Any() && _subjects.Last().Value.Count == _rm.SubjectsByUserId.Last().Value.Count);
4752
Assert.Equal(_subjects, _rm.SubjectsByUserId);
4853
}
4954
[Fact]
@@ -55,7 +60,10 @@ public void can_get_subject_ids()
5560
var sub1 = AddNewSubject(user1, provider: AuthProvider2, domain: "other1");
5661
var sub2 = AddNewSubject(user2, provider: AuthProvider2, domain: "other2");
5762
var sub3 = AddNewSubject(user3);
58-
Guid testSub = Guid.Empty;
63+
AssertEx.IsOrBecomesTrue(() => _subjects.Count == _rm.SubjectsByUserId.Count);
64+
AssertEx.IsOrBecomesTrue(() => _subjects.First().Value.Count == _rm.SubjectsByUserId.First().Value.Count);
65+
AssertEx.IsOrBecomesTrue(() => _subjects.Last().Value.Count == _rm.SubjectsByUserId.Last().Value.Count);
66+
var testSub = Guid.Empty;
5967
AssertEx.IsOrBecomesTrue(()=> _rm.TryGetSubjectIdForUser(user1, AuthProvider2, "other1", out testSub));
6068
Assert.Equal(sub1, testSub);
6169
Assert.True(_rm.TryGetSubjectIdForUser(user2, AuthProvider2, "other2", out testSub));
@@ -69,7 +77,8 @@ public void can_get_subject_id_for_principal()
6977
var userId = Guid.NewGuid();
7078
var subjectId = AddNewSubject(userId, provider: AuthProvider, domain: AuthDomain);
7179
var user = new MockPrincipal { Provider = AuthProvider, Domain = AuthDomain, SId = userId.ToString() };
72-
Assert.True(_rm.TryGetSubjectIdForPrincipal(user, out var id));
80+
var id = Guid.Empty;
81+
AssertEx.IsOrBecomesTrue(() => _rm.TryGetSubjectIdForPrincipal(user, out id));
7382
Assert.Equal(subjectId, id);
7483
}
7584
[Fact]
@@ -83,16 +92,16 @@ public void wrong_domain_returns_false()
8392
{
8493
var user1 = Guid.NewGuid();
8594
var sub1 = AddNewSubject(user1, AuthProvider, AuthDomain);
95+
//yes
96+
var testSub = Guid.Empty;
97+
AssertEx.IsOrBecomesTrue(() => _rm.TryGetSubjectIdForUser(user1, AuthProvider, AuthDomain, out testSub));
98+
Assert.Equal(sub1, testSub);
8699
//no
87-
Assert.False(_rm.TryGetSubjectIdForUser(user1, AuthProvider, "other1", out Guid testSub));
100+
Assert.False(_rm.TryGetSubjectIdForUser(user1, AuthProvider, "other1", out testSub));
88101
Assert.Equal(Guid.Empty, testSub);
89102
//no
90103
Assert.False(_rm.TryGetSubjectIdForUser(user1, AuthProvider2, AuthDomain, out testSub));
91104
Assert.Equal(Guid.Empty, testSub);
92-
//yes
93-
Assert.True(_rm.TryGetSubjectIdForUser(user1, AuthProvider, AuthDomain, out testSub));
94-
Assert.Equal(sub1, testSub);
95-
96105
}
97106
private void AddSubjects(int count)
98107
{

src/ReactiveDomain.IdentityStorage.Tests/UsersRMTests.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,40 +32,37 @@ public UsersRMTests()
3232
_fixture = new MockRepositorySpecification();
3333
AddUsers();
3434
_rm = new UsersRm(_fixture.ConfiguredConnection);
35-
3635
}
3736

38-
39-
4037
[Fact]
4138
public void correct_users_exist()
4239
{
43-
Assert.True(_rm.UsersById.ContainsKey(_id1));
44-
Assert.True(_rm.HasUser(SubjectId, AuthDomain, out _));
45-
Assert.True(_rm.UsersById.ContainsKey(_id2));
46-
Assert.True(_rm.HasUser(SubjectId2, AuthDomain, out _));
40+
AssertEx.IsOrBecomesTrue(() => _rm.UsersById.ContainsKey(_id1));
41+
AssertEx.IsOrBecomesTrue(() => _rm.HasUser(SubjectId, AuthDomain, out _));
42+
AssertEx.IsOrBecomesTrue(() => _rm.UsersById.ContainsKey(_id2));
43+
AssertEx.IsOrBecomesTrue(() => _rm.HasUser(SubjectId2, AuthDomain, out _));
4744

4845
Assert.False(_rm.UsersById.ContainsKey(Guid.NewGuid()));
4946
Assert.False(_rm.UsersById.ContainsKey(Guid.Empty));
5047
Assert.False(_rm.HasUser(AuthDomain, "bogus", out _));
5148
Assert.False(_rm.HasUser("bogus", SubjectId, out _));
52-
5349
}
5450

5551
[Fact]
5652
public void can_get_user_id_by_SID()
5753
{
58-
Assert.True(_rm.HasUser(SubjectId, AuthDomain, out var id1));
54+
var id1 = Guid.Empty;
55+
var id2 = Guid.Empty;
56+
AssertEx.IsOrBecomesTrue(() => _rm.HasUser(SubjectId, AuthDomain, out id1));
5957
Assert.Equal(_id1, id1);
60-
Assert.True(_rm.HasUser(SubjectId2, AuthDomain, out var id2));
58+
AssertEx.IsOrBecomesTrue(() => _rm.HasUser(SubjectId2, AuthDomain, out id2));
6159
Assert.Equal(_id2, id2);
6260
}
6361

6462

6563
[Fact]
6664
public void cannot_get_nonexistent_user()
6765
{
68-
6966
Assert.False(_rm.HasUser(SubjectId, "bogus", out _));
7067
Assert.False(_rm.HasUser("bogus", AuthDomain, out _));
7168
}

src/ReactiveDomain.IdentityStorage/ReadModels/SubjectsRm.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public string GetDomainCategory(string provider, string domain)
3434
}
3535
public bool TryGetSubjectIdForUser(Guid userId, string provider, string domain, out Guid subjectId)
3636
{
37+
subjectId = Guid.Empty;
3738
try
3839
{
3940
if (SubjectsByUserId.TryGetValue(GetDomainCategory(provider, domain), out var subList))
@@ -43,24 +44,22 @@ public bool TryGetSubjectIdForUser(Guid userId, string provider, string domain,
4344
}
4445
catch
4546
{
46-
subjectId = Guid.Empty;
4747
return false;
4848
}
4949
return false;
5050
}
5151
public bool TryGetSubjectIdForPrincipal(IPrincipal principal, out Guid subjectId)
5252
{
53+
subjectId = Guid.Empty;
5354
try
5455
{
55-
5656
if (SubjectsBySubClaim.TryGetValue(GetDomainCategory(principal.Provider, principal.Domain), out var subList))
5757
{
5858
return subList.TryGetValue(principal.SId, out subjectId);
5959
}
6060
}
6161
catch
6262
{
63-
subjectId = Guid.Empty;
6463
return false;
6564
}
6665
return false;

src/ReactiveDomain.Testing/ReactiveDomain.Testing.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<Import Project="../ci.build.imports" />
33
<PropertyGroup>
4-
<TargetFrameworks>netstandard2.0;net48;net5.0</TargetFrameworks>
4+
<TargetFrameworks>netstandard2.0;net48;net6.0</TargetFrameworks>
55
<IsPackable>True</IsPackable>
66
</PropertyGroup>
77
<ItemGroup>

src/ReactiveDomain.Testing/Specifications/MockRepositoryTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ public void can_get_repository_events()
2828
var id = Guid.NewGuid();
2929
var aggregate = new TestAggregate(id);
3030
_fixture.Repository.Save(aggregate);
31-
_fixture.RepositoryEvents.WaitFor<TestAggregateMessages.NewAggregate>(TimeSpan.FromMilliseconds(200));
31+
_fixture.RepositoryEvents.WaitFor<TestAggregateMessages.NewAggregate>(TimeSpan.FromMilliseconds(500));
3232

3333
_fixture
3434
.RepositoryEvents
35-
.AssertNext<TestAggregateMessages.NewAggregate>(e => e.AggregateId == id, "Aggregate Id Missmatch")
35+
.AssertNext<TestAggregateMessages.NewAggregate>(e => e.AggregateId == id, "Aggregate Id Mismatch")
3636
.AssertEmpty();
3737
}
3838

src/ReactiveDomain.Testing/Specifications/TestQueue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public void WaitForMsgId(Guid id, TimeSpan timeout)
167167

168168
while (!waithandle.Wait(10))
169169
{
170-
if (DateTime.Now > deadline) { throw new TimeoutException(); }
170+
if (DateTime.Now > deadline) { throw new TimeoutException($"Msg with ID {id} failed to arrive within {timeout}."); }
171171
if (_disposed) { throw new ObjectDisposedException(nameof(TestQueue)); }
172172
}
173173
}

src/ReactiveDomain.Testing/Specifications/TestQueueTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ public void can_wait_for_a_specific_message_twice()
151151
.ContinueWith( _ => _dispatcher.Publish(evt));
152152

153153
Parallel.Invoke(
154-
() => tq.WaitForMsgId(evt.MsgId, TimeSpan.FromMilliseconds(200)),
155-
() => tq.WaitForMsgId(evt.MsgId, TimeSpan.FromMilliseconds(200))
154+
() => tq.WaitForMsgId(evt.MsgId, TimeSpan.FromMilliseconds(1000)),
155+
() => tq.WaitForMsgId(evt.MsgId, TimeSpan.FromMilliseconds(1000))
156156
);
157157

158158
tq.AssertNext<TestEvent>(evt.CorrelationId)

0 commit comments

Comments
 (0)