Skip to content

Commit 9252749

Browse files
authored
nuget package generation and integration tests project (#4)
* nuget package generation and integration tests project * fix MinVer package reference * another fix to the MinVer package reference * build source files first then execute the test projects * remove duplicated tests * fix MinVer usage * remove the file version configuration * align the continuous integration variable name with dotnet documentation
1 parent 79495e8 commit 9252749

13 files changed

+181
-34
lines changed

.editorconfig

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
; For instance if you change to `dotnet_sort_system_directives_first = true:warning` (adding `:warning`)
1313
; then the rule will be silently ignored.
1414

15+
; ###############################################################################################################
16+
; IDE0005 (Remove unnecessary usings/imports) disabled waiting for https://github.com/dotnet/roslyn/issues/41640
17+
; ###############################################################################################################
18+
1519
; This is the default for the codeline.
1620
root = true
1721

@@ -268,7 +272,7 @@ dotnet_diagnostic.CA2246.severity = warning
268272
dotnet_diagnostic.CA2249.severity = warning
269273

270274
# IDE0005: Remove unnecessary usings
271-
dotnet_diagnostic.IDE0005.severity = warning
275+
dotnet_diagnostic.IDE0005.severity = suggestion
272276

273277
# IDE0011: Curly braces to surround blocks of code
274278
dotnet_diagnostic.IDE0011.severity = warning
@@ -331,7 +335,7 @@ dotnet_diagnostic.IDE0200.severity = warning
331335
dotnet_style_allow_multiple_blank_lines_experimental = false
332336
dotnet_diagnostic.IDE2000.severity = warning
333337

334-
[test/**.cs]
338+
[test/**/*.cs]
335339
# CA1018: Mark attributes with AttributeUsageAttribute
336340
dotnet_diagnostic.CA1018.severity = suggestion
337341
# CA1507: Use nameof to express symbol names

.github/workflows/ci.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Continuous Integration
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
7+
jobs:
8+
build:
9+
name: Continuous Integration
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
filter: tree:0
17+
18+
- name: Set up .NET Core (version from global.json)
19+
uses: actions/setup-dotnet@v4
20+
with:
21+
global-json-file: global.json
22+
23+
- name: dotnet build sources
24+
run: dotnet build src/Sotsera.Sources.Common/Sotsera.Sources.Common.csproj --configuration Release
25+
26+
- name: dotnet test
27+
run: dotnet test --configuration Release
28+
29+
- uses: actions/upload-artifact@v4
30+
with:
31+
name: artifact
32+
path: artifacts/

.github/workflows/verify-pull-request.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ jobs:
1717
with:
1818
global-json-file: global.json
1919

20-
- name: dotnet build
21-
run: dotnet build --configuration Release
20+
- name: dotnet build sources
21+
run: dotnet build src/Sotsera.Sources.Common/Sotsera.Sources.Common.csproj --configuration Release
2222

2323
- name: dotnet test
24-
run: dotnet test --configuration Release --no-build
24+
run: dotnet test --configuration Release
2525

2626
- name: dotnet format
2727
run: dotnet format -v detailed --verify-no-changes

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
*.user
22

33
.vs/
4+
.restore/
45

6+
artifacts/
57
bin/
68
obj/

Directory.Build.props

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project>
3+
34
<PropertyGroup>
45
<TargetFramework>net9.0</TargetFramework>
56
<ImplicitUsings>enable</ImplicitUsings>
@@ -8,9 +9,14 @@
89
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
910
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
1011
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
12+
13+
<ContinuousIntegrationBuild Condition="'$(GITHUB_ACTIONS)' == 'true'">true</ContinuousIntegrationBuild>
14+
15+
<SotseraPackagesFolder>$([System.IO.Path]::Combine($(MSBuildThisFileDirectory), "artifacts"))</SotseraPackagesFolder>
16+
<SotseraRestoreFolder>$([System.IO.Path]::Combine($(MSBuildThisFileDirectory), ".restore"))</SotseraRestoreFolder>
17+
<SotseraSourceProjectFolder>$([System.IO.Path]::Combine($(MSBuildThisFileDirectory), "src", "Sotsera.Sources.Common"))</SotseraSourceProjectFolder>
18+
<SotseraTestProjectFolder>$([System.IO.Path]::Combine($(MSBuildThisFileDirectory), "test", "Sotsera.Sources.Common.Tests.Unit"))</SotseraTestProjectFolder>
19+
<SotseraIntegrationTestProject>$([System.IO.Path]::Combine($(MSBuildThisFileDirectory), "test", "Sotsera.Sources.Common.Tests.Integration", "Sotsera.Sources.Common.Tests.Integration.csproj"))</SotseraIntegrationTestProject>
1120
</PropertyGroup>
1221

13-
<ItemGroup>
14-
<InternalsVisibleTo Include="$(AssemblyName).Tests.Unit" />
15-
</ItemGroup>
1622
</Project>

Directory.Packages.props

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
<PackageVersion Include="FluentAssertions" Version="7.0.0-alpha.4" />
88
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
99
<PackageVersion Include="MinVer" Version="6.0.0" />
10+
<PackageVersion Include="Sotsera.Sources.Common" Version="0.0.0-local">
11+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
12+
<PrivateAssets>all</PrivateAssets>
13+
</PackageVersion>
1014
<PackageVersion Include="xunit" Version="2.9.0" />
1115
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.0-pre.30" />
1216
</ItemGroup>

Sotsera.Sources.Common.sln

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@ EndProject
2121
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sotsera.Sources.Common", "src\Sotsera.Sources.Common\Sotsera.Sources.Common.csproj", "{42618E66-214F-40CD-8D9A-E0FB593042A2}"
2222
EndProject
2323
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{2D9C9B3C-7907-4BE5-9FAC-49E4A04D9907}"
24+
ProjectSection(SolutionItems) = preProject
25+
test\Directory.Build.props = test\Directory.Build.props
26+
EndProjectSection
2427
EndProject
2528
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sotsera.Sources.Common.Tests.Unit", "test\Sotsera.Sources.Common.Tests.Unit\Sotsera.Sources.Common.Tests.Unit.csproj", "{06F10E05-619C-4BEA-B5DA-8B30BAC9EA25}"
2629
EndProject
30+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sotsera.Sources.Common.Tests.Integration", "test\Sotsera.Sources.Common.Tests.Integration\Sotsera.Sources.Common.Tests.Integration.csproj", "{7E83FA83-B12E-42F3-8D75-5D34AA3953C7}"
31+
EndProject
2732
Global
2833
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2934
Debug|Any CPU = Debug|Any CPU
@@ -38,13 +43,18 @@ Global
3843
{06F10E05-619C-4BEA-B5DA-8B30BAC9EA25}.Debug|Any CPU.Build.0 = Debug|Any CPU
3944
{06F10E05-619C-4BEA-B5DA-8B30BAC9EA25}.Release|Any CPU.ActiveCfg = Release|Any CPU
4045
{06F10E05-619C-4BEA-B5DA-8B30BAC9EA25}.Release|Any CPU.Build.0 = Release|Any CPU
46+
{7E83FA83-B12E-42F3-8D75-5D34AA3953C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
47+
{7E83FA83-B12E-42F3-8D75-5D34AA3953C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
48+
{7E83FA83-B12E-42F3-8D75-5D34AA3953C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
49+
{7E83FA83-B12E-42F3-8D75-5D34AA3953C7}.Release|Any CPU.Build.0 = Release|Any CPU
4150
EndGlobalSection
4251
GlobalSection(SolutionProperties) = preSolution
4352
HideSolutionNode = FALSE
4453
EndGlobalSection
4554
GlobalSection(NestedProjects) = preSolution
4655
{42618E66-214F-40CD-8D9A-E0FB593042A2} = {B3030FA3-01FF-42F6-A449-1D8D960AE6D1}
4756
{06F10E05-619C-4BEA-B5DA-8B30BAC9EA25} = {2D9C9B3C-7907-4BE5-9FAC-49E4A04D9907}
57+
{7E83FA83-B12E-42F3-8D75-5D34AA3953C7} = {2D9C9B3C-7907-4BE5-9FAC-49E4A04D9907}
4858
EndGlobalSection
4959
GlobalSection(ExtensibilityGlobals) = postSolution
5060
SolutionGuid = {65291AE5-25E8-40F9-A3FF-37165D3C14E0}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,65 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2+
23
<PropertyGroup>
34
<GenerateDocumentationFile>true</GenerateDocumentationFile>
5+
6+
<Version Condition="'$(ContinuousIntegrationBuild)' != 'true'">0.0.0-local</Version>
7+
<MinVerSkip Condition="'$(ContinuousIntegrationBuild)' != 'true'">true</MinVerSkip>
8+
<MinVerTagPrefix>v</MinVerTagPrefix>
9+
10+
<Authors>Alessandro Ghidini</Authors>
11+
<Company>Sotsera</Company>
12+
<Description>A source-code only package for the Sotsera common utilities</Description>
13+
<Copyright>Sotsera</Copyright>
14+
15+
<RepositoryUrl>https://github.com/sotsera/sotsera.sources.common</RepositoryUrl>
16+
<RepositoryType>git</RepositoryType>
17+
18+
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
19+
<DevelopmentDependency>true</DevelopmentDependency>
20+
<IncludeBuildOutput>false</IncludeBuildOutput>
21+
<!--<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>-->
22+
<NoWarn>$(NoWarn);NU5128;</NoWarn>
23+
24+
<PackageOutputPath>$(SotseraPackagesFolder)</PackageOutputPath>
25+
<PackageIcon>icon.png</PackageIcon>
26+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
27+
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
28+
<PackageProjectUrl>https://github.com/sotsera/sotsera.sources.common</PackageProjectUrl>
29+
<PackageTags>sotsera source</PackageTags>
30+
<PackageReadmeFile>Readme.md</PackageReadmeFile>
31+
32+
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);CustomContentTarget</TargetsForTfmSpecificContentInPackage>
433
</PropertyGroup>
34+
535
<ItemGroup>
636
<PackageReference Include="MinVer">
737
<PrivateAssets>all</PrivateAssets>
838
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
939
</PackageReference>
1040
</ItemGroup>
41+
42+
<ItemGroup>
43+
<None Include="../../Readme.md;../../icon.png" Pack="true" PackagePath="/" Visible="false" />
44+
<None Include="Sotsera.Sources.Common.props" Pack="true" PackagePath="build/" Visible="true" Action="Compile" />
45+
</ItemGroup>
46+
47+
<Target Name="CustomContentTarget">
48+
<ItemGroup>
49+
<TfmSpecificPackageFile Include="**/*.cs" Exclude="bin/**/*.*;obj/**/*.*;$(OutputPath)/*.dll" BuildAction="Compile" Visible="false">
50+
<PackagePath>contentFiles/cs/$(TargetFramework)/$(PackageId)/</PackagePath>
51+
</TfmSpecificPackageFile>
52+
</ItemGroup>
53+
</Target>
54+
55+
<Target Name="RestoreTestDependencies" AfterTargets="Pack">
56+
<Message Text="Remove the old library: $(SotseraRestoreFolder)/$(PackageId)" Importance="high" Condition="Exists('$(SotseraRestoreFolder)/$(PackageId)')" />
57+
<RemoveDir Directories="$(SotseraRestoreFolder)/$(PackageId)" Condition="Exists('$(SotseraRestoreFolder)/$(PackageId)')" />
58+
59+
<Exec Command="dotnet remove $(SotseraIntegrationTestProject) package $(PackageId)" IgnoreExitCode="true" />
60+
<Exec Command="dotnet add $(SotseraIntegrationTestProject) package $(PackageId) -v $(PackageVersion)" />
61+
62+
<MSBuild Projects="$(SotseraIntegrationTestProject)" Targets="Rebuild" Properties="Configuration=$(Configuration);" />
63+
</Target>
64+
1165
</Project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project>
3+
4+
<ItemGroup>
5+
<Compile Update="@(Compile)">
6+
<Visible Condition="'%(NuGetItemType)' == 'Compile' and '%(NuGetPackageId)' == 'Sotsera.Sources.Common'">false</Visible>
7+
</Compile>
8+
</ItemGroup>
9+
10+
</Project>

test/Directory.Build.props

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project>
3+
4+
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
5+
6+
<PropertyGroup>
7+
<IsPackable>false</IsPackable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="coverlet.collector" />
12+
<PackageReference Include="FluentAssertions" />
13+
<PackageReference Include="Microsoft.NET.Test.Sdk" />
14+
<PackageReference Include="xunit" />
15+
<PackageReference Include="xunit.runner.visualstudio" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<Using Include="Xunit" />
20+
<Using Include="FluentAssertions" />
21+
</ItemGroup>
22+
23+
</Project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<RestoreIgnoreFailedSources>true</RestoreIgnoreFailedSources>
5+
<RestoreAdditionalProjectSources>$(SotseraPackagesFolder)</RestoreAdditionalProjectSources>
6+
<RestorePackagesPath>$(SotseraRestoreFolder)</RestorePackagesPath>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<Compile Include="$(SotseraTestProjectFolder)/**/*.cs" Exclude="$(SotseraTestProjectFolder)/bin/**/*.*;$(SotseraTestProjectFolder)/obj/**/*.*">
11+
<Link>Sotsera.Sources.Common.Tests/%(RecursiveDir)%(Filename)%(Extension)</Link>
12+
</Compile>
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<PackageReference Include="Sotsera.Sources.Common">
17+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
18+
<PrivateAssets>all</PrivateAssets>
19+
</PackageReference>
20+
</ItemGroup>
21+
22+
</Project>

test/Sotsera.Sources.Common.Tests.Unit/Extensions/StringExtensionsTests.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) Alessandro Ghidini. All rights reserved.
22
// SPDX-License-Identifier: MIT.
33

4-
using System.Diagnostics.CodeAnalysis;
54
using Sotsera.Sources.Common.Extensions;
65
using Xunit.Abstractions;
76

@@ -85,22 +84,18 @@ public NonWhitespaceValueGenerator()
8584

8685
private class StringEnumerableToBeJoinedValueGenerator : TheoryData<EnumerableStringList, bool, string>
8786
{
88-
[SuppressMessage("Style", "IDE0301:Simplify collection initialization", Justification = "The specific type are needed by the test")]
89-
[SuppressMessage("ReSharper", "UseCollectionExpression", Justification = "The specific type are needed by the test")]
9087
public StringEnumerableToBeJoinedValueGenerator()
9188
{
9289
Add(new EnumerableStringList(null), false, "");
93-
Add(new EnumerableStringList(Enumerable.Empty<string>()), false, "");
94-
Add(new EnumerableStringList(Array.Empty<string>()), false, "");
90+
Add(new EnumerableStringList([]), false, "");
9591
Add(new EnumerableStringList([null]), false, "");
9692
Add(new EnumerableStringList([null, "ciao"]), false, "ciao");
9793
Add(new EnumerableStringList(["ciao"]), false, "ciao");
9894
Add(new EnumerableStringList(["a", "b"]), false, "a; b");
9995
Add(new EnumerableStringList(["a", null, "b"]), false, "a; b");
10096

10197
Add(new EnumerableStringList(null), true, "");
102-
Add(new EnumerableStringList(Enumerable.Empty<string>()), true, "");
103-
Add(new EnumerableStringList(Array.Empty<string>()), true, "");
98+
Add(new EnumerableStringList([]), true, "");
10499
Add(new EnumerableStringList([null]), true, "");
105100
Add(new EnumerableStringList([null, "ciao"]), true, "; ciao");
106101
Add(new EnumerableStringList(["ciao"]), true, "ciao");
Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,9 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
2-
3-
<PropertyGroup>
4-
<IsPackable>false</IsPackable>
5-
</PropertyGroup>
6-
7-
<ItemGroup>
8-
<PackageReference Include="coverlet.collector" />
9-
<PackageReference Include="FluentAssertions" />
10-
<PackageReference Include="Microsoft.NET.Test.Sdk" />
11-
<PackageReference Include="xunit" />
12-
<PackageReference Include="xunit.runner.visualstudio" />
13-
</ItemGroup>
14-
15-
<ItemGroup>
16-
<ProjectReference Include="..\..\src\Sotsera.Sources.Common\Sotsera.Sources.Common.csproj" />
17-
</ItemGroup>
1+
<Project Sdk="Microsoft.NET.Sdk">
182

193
<ItemGroup>
20-
<Using Include="Xunit" />
21-
<Using Include="FluentAssertions" />
4+
<Compile Include="$(SotseraSourceProjectFolder)/**/*.cs" Exclude="$(SotseraSourceProjectFolder)/bin/**/*.*;$(SotseraSourceProjectFolder)\obj\**\*.*">
5+
<Link>Sotsera.Sources.Common/%(RecursiveDir)%(Filename)%(Extension)</Link>
6+
</Compile>
227
</ItemGroup>
238

249
</Project>

0 commit comments

Comments
 (0)