Skip to content

Commit 7c3a25c

Browse files
authored
Refactoring (#1)
v2.0
1 parent d4e7a5d commit 7c3a25c

38 files changed

+849
-779
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ jobs:
3535

3636
steps:
3737
- name: Checkout repository
38-
uses: actions/checkout@v2
38+
uses: actions/checkout@v3
3939

4040
# Initializes the CodeQL tools for scanning.
4141
- name: Initialize CodeQL
42-
uses: github/codeql-action/init@v1
42+
uses: github/codeql-action/init@v2
4343
with:
4444
languages: ${{ matrix.language }}
4545
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -50,7 +50,7 @@ jobs:
5050
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
5151
# If this step fails, then you should remove it and run the build manually (see below)
5252
- name: Autobuild
53-
uses: github/codeql-action/autobuild@v1
53+
uses: github/codeql-action/autobuild@v2
5454

5555
# ℹ️ Command-line programs to run using the OS shell.
5656
# 📚 https://git.io/JvXDl
@@ -64,4 +64,4 @@ jobs:
6464
# make release
6565

6666
- name: Perform CodeQL Analysis
67-
uses: github/codeql-action/analyze@v1
67+
uses: github/codeql-action/analyze@v2

.github/workflows/dotnet.yml

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
pull_request:
77
branches: [ main ]
88

9-
9+
1010
# Allows you to run this workflow manually from the Actions tab
1111
workflow_dispatch:
1212

@@ -16,31 +16,24 @@ jobs:
1616
runs-on: ubuntu-latest
1717

1818
steps:
19+
20+
- uses: actions/checkout@v3
21+
- name: Setup .NET
22+
uses: actions/setup-dotnet@v3
23+
with:
24+
dotnet-version: 7.0.x
1925

20-
- uses: actions/checkout@v2
21-
- name: Setup .NET
22-
uses: actions/setup-dotnet@v1
23-
with:
24-
dotnet-version: 6.0.x
25-
26-
# run build and test
27-
- name: Restore dependencies
28-
run: dotnet restore
29-
- name: Build
30-
run: dotnet build --no-restore
31-
- name: Test
32-
run: dotnet test --no-build --logger 'trx;LogFileName=test-results.trx'
33-
- name: Collect Code Coverage
34-
run: dotnet test --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=lcov /p:CoverletOutput=ManagedCode.Communication.Tests/lcov.info
35-
- name : coverlet
36-
uses: b3b00/coverlet-action@1.1.9
37-
with:
38-
testProject: 'ManagedCode.Communication.Tests/ManagedCode.Communication.Tests.csproj'
39-
output: 'lcov.info'
40-
outputFormat: 'lcov'
41-
excludes: '[program]*,[test]test.*'
42-
- name: coveralls
43-
uses: coverallsapp/github-action@master
44-
with:
45-
github-token: ${{secrets.GITHUB_TOKEN }}
46-
path-to-lcov: ManagedCode.Communication.Tests/lcov.info
26+
# run build and test
27+
- name: Restore dependencies
28+
run: dotnet restore
29+
- name: Build
30+
run: dotnet build --no-restore
31+
- name: Test and Collect Code Coverage
32+
run: dotnet test -p:CollectCoverage=true -p:CoverletOutputFormat=lcov -p:CoverletOutput=ManagedCode.Communication.Tests/
33+
34+
35+
- name: coveralls
36+
uses: coverallsapp/github-action@master
37+
with:
38+
github-token: ${{secrets.GITHUB_TOKEN }}
39+
path-to-lcov: ManagedCode.Communication.Tests/coverage.info

.github/workflows/nuget.yml

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: nuget
33
on:
44
push:
55
branches: [ main ]
6-
6+
77
# Allows you to run this workflow manually from the Actions tab
88
workflow_dispatch:
99

@@ -13,23 +13,23 @@ jobs:
1313
runs-on: ubuntu-latest
1414

1515
steps:
16-
- uses: actions/checkout@v2
17-
- name: Setup .NET
18-
uses: actions/setup-dotnet@v1
19-
with:
20-
dotnet-version: 6.0.x
21-
22-
- name: Restore dependencies
23-
run: dotnet restore
24-
- name: Build
25-
run: dotnet build --configuration Release
26-
- name: Pack
27-
run: dotnet pack --configuration Release
16+
- uses: actions/checkout@v3
17+
- name: Setup .NET
18+
uses: actions/setup-dotnet@v3
19+
with:
20+
dotnet-version: 7.0.x
2821

29-
- name: publish nuget packages
30-
run: |
31-
shopt -s globstar
32-
for file in **/*.nupkg
33-
do
34-
dotnet nuget push "$file" --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json
35-
done
22+
- name: Restore dependencies
23+
run: dotnet restore
24+
- name: Build
25+
run: dotnet build --configuration Release
26+
- name: Pack
27+
run: dotnet pack -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg --configuration Release
28+
29+
- name: publish nuget packages
30+
run: |
31+
shopt -s globstar
32+
for file in **/*.nupkg
33+
do
34+
dotnet nuget push "$file" --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
35+
done

Directory.Build.props

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
<PackageLicenseExpression>MIT</PackageLicenseExpression>
1414
<EnablePackageValidation>true</EnablePackageValidation>
1515
<PackageReadmeFile>README.md</PackageReadmeFile>
16-
16+
1717
<RepositoryUrl>https://github.com/managedcode/Communication</RepositoryUrl>
1818
<PackageProjectUrl>https://github.com/managedcode/Communication</PackageProjectUrl>
1919
<Product>Managed Code - Communication</Product>
20-
<Version>1.0.3</Version>
21-
<PackageVersion>1.0.3</PackageVersion>
22-
20+
<Version>2.0.0</Version>
21+
<PackageVersion>2.0.0</PackageVersion>
22+
2323
</PropertyGroup>
2424
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
2525
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>

ManagedCode.Communication.Tests/DeserializationTests.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Net;
34
using FluentAssertions;
45
using Newtonsoft.Json;
56
using Xunit;
@@ -11,19 +12,19 @@ public class DeserializationTests
1112
{
1213
[Theory]
1314
[MemberData(nameof(GetResults))]
14-
public void DeserializeResult_WithNewtonsoftJson(Result result)
15+
public void DeserializeResult_WithNewtonsoftJson(IResult result)
1516
{
1617
// Act
1718
var serialized = JsonConvert.SerializeObject(result);
18-
var deserialized = JsonConvert.DeserializeObject<Result<int>>(serialized);
19+
var deserialized = JsonConvert.DeserializeObject<Result>(serialized);
1920

2021
// Assert
2122
deserialized.Should().BeEquivalentTo(result);
2223
}
2324

2425
[Theory]
2526
[MemberData(nameof(GetValueResults))]
26-
public void DeserializeValueResult_WithNewtonsoftJson<T>(Result<T> result)
27+
public void DeserializeValueResult_WithNewtonsoftJson<T>(IResult result)
2728
{
2829
// Act
2930
var serialized = JsonConvert.SerializeObject(result);
@@ -35,7 +36,7 @@ public void DeserializeValueResult_WithNewtonsoftJson<T>(Result<T> result)
3536

3637
[Theory]
3738
[MemberData(nameof(GetResults))]
38-
public void DeserializeResult_WithTextJson(Result result)
39+
public void DeserializeResult_WithTextJson(IResult result)
3940
{
4041
// Act
4142
var serialized = JsonSerializer.Serialize(result);
@@ -47,7 +48,7 @@ public void DeserializeResult_WithTextJson(Result result)
4748

4849
[Theory]
4950
[MemberData(nameof(GetValueResults))]
50-
public void DeserializeValueResult_WithTextJson<T>(Result<T> result)
51+
public void DeserializeValueResult_WithTextJson<T>(IResult result)
5152
{
5253
// Act
5354
var serialized = JsonSerializer.Serialize(result);
@@ -62,7 +63,7 @@ public static IEnumerable<object[]> GetResults()
6263
yield return new object[] { Result.Succeed() };
6364
yield return new object[] { Result.Fail() };
6465
yield return new object[] { Result.Fail(new Exception("Test exception")) };
65-
yield return new object[] { Result.Fail(new Error<ErrorCode>("Test error", ErrorCode.InvalidState)) };
66+
yield return new object[] { Result.Fail(new Error("Test error", HttpStatusCode.Found)) };
6667
}
6768

6869
public static IEnumerable<object[]> GetValueResults()
@@ -71,6 +72,6 @@ public static IEnumerable<object[]> GetValueResults()
7172
yield return new object[] { Result<string>.Succeed("Test string") };
7273
yield return new object[] { Result<int>.Fail() };
7374
yield return new object[] { Result<int>.Fail(new Exception("Test exception")) };
74-
yield return new object[] { Result<int>.Fail(new Error<ErrorCode>("Test error", ErrorCode.InvalidState)) };
75+
yield return new object[] { Result<int>.Fail(new Error("Test error", HttpStatusCode.Found)) };
7576
}
7677
}

ManagedCode.Communication.Tests/ManagedCode.Communication.Tests.csproj

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net7.0</TargetFramework>
55
<EnableNETAnalyzers>true</EnableNETAnalyzers>
66
<IsPackable>false</IsPackable>
7-
<LangVersion>10</LangVersion>
7+
<LangVersion>11</LangVersion>
88
<Nullable>enable</Nullable>
99
</PropertyGroup>
1010
<PropertyGroup>
1111
<VSTestLogger>trx%3bLogFileName=$(MSBuildProjectName).trx</VSTestLogger>
1212
<VSTestResultsDirectory>$(MSBuildThisFileDirectory)</VSTestResultsDirectory>
1313
</PropertyGroup>
14+
<PropertyGroup>
15+
<CollectCoverage>true</CollectCoverage>
16+
<ExcludeByAttribute>GeneratedCodeAttribute</ExcludeByAttribute>
17+
<Exclude>[*]*.Migrations.*</Exclude>
18+
<ExcludeByFile>**/MyFile.cs</ExcludeByFile>
19+
<CoverletOutputFormat>lcov</CoverletOutputFormat>
20+
</PropertyGroup>
1421
<ItemGroup>
1522
<None Update="xunit.runner.json">
1623
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

ManagedCode.Communication.Tests/ResultErrorHandlerTests.cs

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)