Skip to content

Commit

Permalink
Update the project
Browse files Browse the repository at this point in the history
- add .net8 target
- Update nuget packages
- Replace Moq with NSubstitute
  • Loading branch information
sensslen committed Nov 24, 2023
1 parent 84ac29e commit a868a4f
Show file tree
Hide file tree
Showing 21 changed files with 316 additions and 318 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/action.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Main workflow
name: "Main workflow"

on: [push, pull_request]

Expand Down Expand Up @@ -29,6 +29,10 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: "7.0.x"
- name: Setup dotnet 8.0.x
uses: actions/setup-dotnet@v3
with:
dotnet-version: "8.0.x"
- name: restore
run: dotnet restore

Expand All @@ -51,6 +55,9 @@ jobs:
- targetFramework: net7.0
dotnetVersion: "7.0.x"

- targetFramework: net8.0
dotnetVersion: "8.0.x"

steps:
- uses: actions/checkout@v3
- name: Setup dotnet ${{ matrix.dotnetVersion }}
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: "7.0.x"
- name: Setup dotnet 8.0.x
uses: actions/setup-dotnet@v3
with:
dotnet-version: "8.0.x"
env:
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}

Expand All @@ -39,6 +43,8 @@ jobs:
run: dotnet publish ./src/NuGetUtility/NuGetUtility.csproj -c Release --no-restore -o ./artifacts/net6 -f net6.0 -p:Version=${{ steps.version.outputs.full_without_prefix }}
- name: Publish the application binaries (.net7)
run: dotnet publish ./src/NuGetUtility/NuGetUtility.csproj -c Release --no-restore -o ./artifacts/net7 -f net7.0 -p:Version=${{ steps.version.outputs.full_without_prefix }}
- name: Publish the application binaries (.net8)
run: dotnet publish ./src/NuGetUtility/NuGetUtility.csproj -c Release --no-restore -o ./artifacts/net8 -f net8.0 -p:Version=${{ steps.version.outputs.full_without_prefix }}
- name: Create nuget package
run: dotnet pack ./src/NuGetUtility/NuGetUtility.csproj -c Release --no-build -o ./artifacts -p:Version=${{ steps.version.outputs.full_without_prefix }}

Expand Down
19 changes: 12 additions & 7 deletions src/NuGetUtility/NuGetUtility.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<IsPackable>true</IsPackable>
<PackAsTool>true</PackAsTool>
<PackageType>DotnetTool</PackageType>
Expand All @@ -24,18 +24,23 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="4.0.2" />
<PackageReference Include="Microsoft.Build.Locator" Version="1.5.5" />
<PackageReference Include="NuGet.Commands" Version="6.5.0" />
<PackageReference Include="NuGet.Packaging" Version="6.5.0" />
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="4.1.0" />
<PackageReference Include="Microsoft.Build.Locator" Version="1.6.10" />
<PackageReference Include="NuGet.Commands" Version="6.8.0" />
<PackageReference Include="NuGet.Packaging" Version="6.8.0" />
<PackageReference Include="System.Text.Json" Version="8.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<PackageReference Include="Microsoft.Build" ExcludeAssets="runtime" Version="17.3.2" />
<PackageReference Include="Microsoft.Build" ExcludeAssets="runtime" Version="17.3.*" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
<PackageReference Include="Microsoft.Build" ExcludeAssets="runtime" Version="17.5.0" />
<PackageReference Include="Microsoft.Build" ExcludeAssets="runtime" Version="17.6.*" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.Build" ExcludeAssets="runtime" Version="17.8.*" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public IProject GetProject(string projectPath)

public IEnumerable<string> GetProjectsFromSolution(string inputPath)
{
string absolutePath = Path.GetFullPath(inputPath, Environment.CurrentDirectory);
string absolutePath = Path.GetFullPath(inputPath, Environment.CurrentDirectory);
var sln = SolutionFile.Parse(absolutePath);
return sln.ProjectsInOrder.Select(p => p.AbsolutePath);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace NuGetUtility.Wrapper.NuGetWrapper.Frameworks
{
public interface INuGetFramework { }
public interface INuGetFramework
{
string? ToString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public CachingPackageMetadataResource(PackageMetadataResource metadataResource,
{
try
{
IPackageSearchMetadata result = await _metadataResource.GetMetadataAsync(new NuGet.Packaging.Core.PackageIdentity(identity.Id, new NuGetVersion(identity.Version.ToString())),
IPackageSearchMetadata result = await _metadataResource.GetMetadataAsync(new NuGet.Packaging.Core.PackageIdentity(identity.Id, new NuGetVersion(identity.Version.ToString()!)),
_cacheContext,
new NullLogger(),
cancellationToken);
Expand All @@ -35,9 +35,9 @@ public CachingPackageMetadataResource(PackageMetadataResource metadataResource,
}
}

private class WrappedPackageSearchMetadata : IPackageMetadata
private sealed class WrappedPackageSearchMetadata : IPackageMetadata
{
private IPackageSearchMetadata _searchMetadata;
private readonly IPackageSearchMetadata _searchMetadata;

public WrappedPackageSearchMetadata(IPackageSearchMetadata searchMetadata)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public GlobalPackagesFolderUtility(ISettings settings)

public IWrappedPackageMetadata? GetPackage(PackageIdentity identity)
{
DownloadResourceResult cachedPackage = OriginalGlobalPackagesFolderUtility.GetPackage(new OriginalPackageIdentity(identity.Id, new NuGetVersion(identity.Version.ToString())), _globalPackagesFolder);
DownloadResourceResult cachedPackage = OriginalGlobalPackagesFolderUtility.GetPackage(new OriginalPackageIdentity(identity.Id, new NuGetVersion(identity.Version.ToString()!)), _globalPackagesFolder);
if (cachedPackage == null)
{
return null;
Expand Down
41 changes: 19 additions & 22 deletions tests/NuGetUtility.Test/Extensions/ProjectExtensionsTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Moq;
using NSubstitute;
using NuGetUtility.Extensions;
using NuGetUtility.Wrapper.MsBuildWrapper;

Expand All @@ -10,32 +10,29 @@ public class ProjectExtensionsTest
[SetUp]
public void SetUp()
{
_projectMock = new Mock<IProject>();
_uut = _projectMock.Object;
_project = Substitute.For<IProject>();
}

private Mock<IProject>? _projectMock;

private IProject? _uut;
private IProject _project = null!;

[Test]
public void HasNugetPackagesReferenced_Should_ReturnTrue_If_PackageReferenceCountIsMoreThanZero(
[Values(1, 50, 999)] int referenceCount)
{
_projectMock!.Setup(m => m.GetPackageReferenceCount()).Returns(referenceCount);
_project.GetPackageReferenceCount().Returns(referenceCount);

bool result = _uut!.HasNugetPackagesReferenced();
bool result = _project.HasNugetPackagesReferenced();

Assert.That(result, Is.True);
}

[Test]
public void HasNugetPackagesReferences_Should_ReturnTrue_If_ProjectHasPackagesConfigFileReferenced()
{
_projectMock!.Setup(m => m.GetPackageReferenceCount()).Returns(0);
_projectMock.Setup(m => m.GetEvaluatedIncludes()).Returns(new List<string> { "packages.config" });
_project.GetPackageReferenceCount().Returns(0);
_project.GetEvaluatedIncludes().Returns(new List<string> { "packages.config" });

bool result = _uut!.HasNugetPackagesReferenced();
bool result = _project!.HasNugetPackagesReferenced();

Assert.That(result, Is.True);
}
Expand All @@ -45,10 +42,10 @@ public void
HasNugetPackagesReferenced_Should_ReturnFalse_If_PackageReferenceCountIsZeroOrLess_And_ProjectHasNoPackagesConfigFileReferenced(
[Values(-9999, -50, 0)] int referenceCount)
{
_projectMock!.Setup(m => m.GetPackageReferenceCount()).Returns(referenceCount);
_projectMock.Setup(m => m.GetEvaluatedIncludes()).Returns(Enumerable.Empty<string>());
_project.GetPackageReferenceCount().Returns(referenceCount);
_project.GetEvaluatedIncludes().Returns(Enumerable.Empty<string>());

bool result = _uut!.HasNugetPackagesReferenced();
bool result = _project!.HasNugetPackagesReferenced();

Assert.That(result, Is.False);
}
Expand All @@ -64,11 +61,11 @@ public void IsPackageReferenceProject_Should_ReturnTrue_If_ProjectIsPackageRefer
string nugetStyleTag,
string restoreStyleTag)
{
_projectMock!.Setup(m => m.GetNugetStyleTag()).Returns(nugetStyleTag);
_projectMock.Setup(m => m.GetRestoreStyleTag()).Returns(restoreStyleTag);
_projectMock.Setup(m => m.GetEvaluatedIncludes()).Returns(new List<string> { "not-packages.config" });
_project.GetNugetStyleTag().Returns(nugetStyleTag);
_project.GetRestoreStyleTag().Returns(restoreStyleTag);
_project.GetEvaluatedIncludes().Returns(new List<string> { "not-packages.config" });

bool result = _uut!.IsPackageReferenceProject();
bool result = _project!.IsPackageReferenceProject();

Assert.That(result, Is.True);
}
Expand All @@ -85,11 +82,11 @@ public void IsPackageReferenceProject_Should_ReturnFalse_If_ProjectIsNotPackageR
string restoreStyleTag,
string evaluatedInclude)
{
_projectMock!.Setup(m => m.GetNugetStyleTag()).Returns(nugetStyleTag);
_projectMock.Setup(m => m.GetRestoreStyleTag()).Returns(restoreStyleTag);
_projectMock.Setup(m => m.GetEvaluatedIncludes()).Returns(new List<string> { evaluatedInclude });
_project.GetNugetStyleTag().Returns(nugetStyleTag);
_project.GetRestoreStyleTag().Returns(restoreStyleTag);
_project.GetEvaluatedIncludes().Returns(new List<string> { evaluatedInclude });

bool result = _uut!.IsPackageReferenceProject();
bool result = _project!.IsPackageReferenceProject();

Assert.That(result, Is.False);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ public static IAsyncEnumerable<T> AsAsyncEnumerable<T>(this IEnumerable<T> synch
return new AsyncEnumerable<T>(synchronous);
}

public static async Task<IEnumerable<T>> Synchronize<T>(this IAsyncEnumerable<T> async)
public static async Task<IEnumerable<T>> Synchronize<T>(this IAsyncEnumerable<T> asyncEnumerable)
{
var list = new List<T>();
await foreach (T? item in async)
await foreach (T? item in asyncEnumerable)
{
lock (list)
{
Expand Down
22 changes: 0 additions & 22 deletions tests/NuGetUtility.Test/Helper/AutoFixture/MockBuilder.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public class LicenseValidationResultValueEqualityComparer : IEqualityComparer<Li
public bool Equals(LicenseValidationResult? x, LicenseValidationResult? y)
{
if (ReferenceEquals(x, y)) return true;
if (ReferenceEquals(x, null)) return false;
if (ReferenceEquals(y, null)) return false;
if (x is null) return false;
if (y is null) return false;
if (x.GetType() != y.GetType()) return false;
return x.ValidationErrors.SequenceEqual(y.ValidationErrors) && (x.License == y.License) &&
(x.LicenseInformationOrigin == y.LicenseInformationOrigin) && (x.PackageId == y.PackageId) &&
Expand Down
Loading

0 comments on commit a868a4f

Please sign in to comment.