-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Rob Anderson <jamsidedown@users.noreply.github.com> Co-authored-by: Daniel P. Doyle <3020488+TheDanielDoyle@users.noreply.github.com>
- Loading branch information
1 parent
4c03e96
commit 1c77554
Showing
14 changed files
with
250 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# NuGet | ||
|
||
- [NuGetThosePackages.csx](../src/scripts/NuGetThosePackages.csx) | ||
|
||
Running `dotnet add package` | ||
|
||
```dotnetcli | ||
info : GET https://api.nuget.org/v3/registration5-gz-semver2/ironpython/index.json | ||
info : OK https://api.nuget.org/v3/registration5-gz-semver2/ironpython/index.json 165ms | ||
info : Restoring packages for /Users/robert.anderson/Documents/code/playground/nuget_testing/nuget_testing.csproj... | ||
info : GET https://api.nuget.org/v3-flatcontainer/ironpython/index.json | ||
info : OK https://api.nuget.org/v3-flatcontainer/ironpython/index.json 177ms | ||
info : GET https://api.nuget.org/v3-flatcontainer/ironpython/3.4.1/ironpython.3.4.1.nupkg | ||
info : OK https://api.nuget.org/v3-flatcontainer/ironpython/3.4.1/ironpython.3.4.1.nupkg 445ms | ||
info : GET https://api.nuget.org/v3-flatcontainer/dynamiclanguageruntime/index.json | ||
info : GET https://api.nuget.org/v3-flatcontainer/mono.unix/index.json | ||
info : OK https://api.nuget.org/v3-flatcontainer/dynamiclanguageruntime/index.json 158ms | ||
info : GET https://api.nuget.org/v3-flatcontainer/dynamiclanguageruntime/1.3.4/dynamiclanguageruntime.1.3.4.nupkg | ||
info : OK https://api.nuget.org/v3-flatcontainer/mono.unix/index.json 166ms | ||
info : GET https://api.nuget.org/v3-flatcontainer/mono.unix/7.1.0-final.1.21458.1/mono.unix.7.1.0-final.1.21458.1.nupkg | ||
info : OK https://api.nuget.org/v3-flatcontainer/dynamiclanguageruntime/1.3.4/dynamiclanguageruntime.1.3.4.nupkg 86ms | ||
info : OK https://api.nuget.org/v3-flatcontainer/mono.unix/7.1.0-final.1.21458.1/mono.unix.7.1.0-final.1.21458.1.nupkg 92ms | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...nteractive.DependencyManagement.Tests/BlazorInteractive.DependencyManagement.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="FluentAssertions" Version="6.11.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" /> | ||
<PackageReference Include="Moq" Version="4.18.4" /> | ||
<PackageReference Include="xunit" Version="2.4.2" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="3.2.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\BlazorInteractive.DependencyManagement\BlazorInteractive.DependencyManagement.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
39 changes: 39 additions & 0 deletions
39
src/BlazorInteractive.DependencyManagement.Tests/NuGetPackageGetterTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using FluentAssertions; | ||
using Microsoft.Extensions.Logging; | ||
using Moq; | ||
using OneOf.Types; | ||
|
||
namespace BlazorInteractive.DependencyManagement.Tests; | ||
|
||
public class NuGetPackageGetterTest | ||
{ | ||
private readonly Mock<ILogger<NuGetPackageGetter>> _logger; | ||
// private readonly CancellationToken _defaultCancellationToken; | ||
|
||
public NuGetPackageGetterTest() | ||
{ | ||
_logger = new Mock<ILogger<NuGetPackageGetter>>(); | ||
// _defaultCancellationToken = CancellationToken.None; | ||
} | ||
|
||
[Fact] | ||
public async Task GetPackage_WithValidName_ReturnsSuccess() | ||
{ | ||
var packageName = "Package"; | ||
var nugetPackageGetter = new NuGetPackageGetter(_logger.Object); | ||
|
||
var result = await nugetPackageGetter.GetPackage(packageName); | ||
result.Value.Should().BeOfType<Success>(); | ||
} | ||
|
||
[Fact] | ||
public async Task GetPackage_WithInvalidName_ReturnsFailure() | ||
{ | ||
var packageName = "Package"; | ||
var nugetPackageGetter = new NuGetPackageGetter(_logger.Object); | ||
|
||
var result = await nugetPackageGetter.GetPackage(packageName); | ||
result.Value.Should().BeOfType<Failure>(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global using Xunit; |
15 changes: 15 additions & 0 deletions
15
src/BlazorInteractive.DependencyManagement/BlazorInteractive.DependencyManagement.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" /> | ||
<PackageReference Include="OneOf" Version="3.0.255" /> | ||
<PackageReference Include="OneOf.SourceGenerator" Version="3.0.255" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace BlazorInteractive.DependencyManagement; | ||
|
||
public interface IPackageGetter | ||
{ | ||
// GetVersions() | ||
Task<PackageResult> GetPackage(string name); | ||
} |
18 changes: 18 additions & 0 deletions
18
src/BlazorInteractive.DependencyManagement/NuGetPackageGetter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace BlazorInteractive.DependencyManagement; | ||
|
||
public class NuGetPackageGetter : IPackageGetter | ||
{ | ||
private readonly ILogger _logger; | ||
|
||
public NuGetPackageGetter(ILogger<NuGetPackageGetter> logger) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
public Task<PackageResult> GetPackage(string name) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/BlazorInteractive.DependencyManagement/Results/Failure.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace BlazorInteractive.DependencyManagement; | ||
|
||
public sealed record Failure(string errorMessage) { | ||
|
||
public Failure(Exception ex, string errorMessage) : this(errorMessage) | ||
{ | ||
Exception = ex; | ||
} | ||
|
||
public Exception? Exception { get; init; } | ||
} |
8 changes: 8 additions & 0 deletions
8
src/BlazorInteractive.DependencyManagement/Results/PackageResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using System.Reflection; | ||
using OneOf; | ||
using OneOf.Types; | ||
|
||
namespace BlazorInteractive.DependencyManagement; | ||
|
||
[GenerateOneOf] | ||
public partial class PackageResult : OneOfBase<Success, Failure> { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# src | ||
|
||
- [data](data/) | ||
- [Scripts](scripts/README.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System.IO.Compression; | ||
using System.Net.Http; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
record IndexResource([property:JsonPropertyName("@Id")] string Id, [property:JsonPropertyName("@Type")] string Type, string Comment); | ||
record IndexResponse(string Version, List<IndexResource> Resources); | ||
|
||
record PackageVersions(List<string> Versions); | ||
|
||
var client = new HttpClient(); | ||
|
||
async Task<T> GetAndCache<T>(string url, string file) | ||
{ | ||
string json; | ||
if (!File.Exists(file)) | ||
{ | ||
json = await client.GetStringAsync(url); | ||
await File.WriteAllTextAsync(file, json); | ||
} | ||
else | ||
{ | ||
json = await File.ReadAllTextAsync(file); | ||
} | ||
|
||
return JsonSerializer.Deserialize<T>(json, new JsonSerializerOptions {PropertyNameCaseInsensitive = true}); | ||
} | ||
|
||
var nugetIndexResponse = await GetAndCache<IndexResponse>("https://api.nuget.org/v3/index.json", "nuget/index.json"); | ||
var packageVersionsBaseUrl = nugetIndexResponse.Resources.First(resource => resource.Type == "PackageBaseAddress/3.0.0").Id; | ||
|
||
var testUrl = $"{packageVersionsBaseUrl}ironpython/index.json"; | ||
Console.WriteLine(testUrl); | ||
var versionsResponse = await GetAndCache<PackageVersions>($"{packageVersionsBaseUrl}ironpython/index.json", "nuget/ironpythonversions.json"); | ||
var latestVersion = versionsResponse.Versions.Last(); | ||
|
||
var packageUrl = $"{packageVersionsBaseUrl}ironpython/{latestVersion}/ironpython.{latestVersion}.nupkg"; | ||
|
||
if (!File.Exists($"nuget/ironpython.{latestVersion}.nupkg")) | ||
{ | ||
using (var localFile = File.OpenWrite($"nuget/ironpython.{latestVersion}.nupkg")) | ||
{ | ||
var packageZip = await client.GetStreamAsync(packageUrl); | ||
await packageZip.CopyToAsync(localFile); | ||
} | ||
} | ||
|
||
var extractDir = $"nuget/ironpython.{latestVersion}"; | ||
if (!Directory.Exists(extractDir)) | ||
{ | ||
Directory.CreateDirectory(extractDir); | ||
} | ||
|
||
using (var zip = ZipFile.OpenRead($"nuget/ironpython.{latestVersion}.nupkg")) | ||
{ | ||
foreach (var file in zip.Entries) | ||
{ | ||
var target = $"{extractDir}/{file.Name}"; | ||
if (File.Exists(target)) | ||
{ | ||
continue; | ||
} | ||
|
||
if (file.Name.EndsWith(".dll") && file.FullName.Contains("net6")) | ||
{ | ||
file.ExtractToFile(target); | ||
Console.WriteLine($"Extracted {file.FullName}"); | ||
} | ||
else if (file.Name.EndsWith("nuspec")) | ||
{ | ||
file.ExtractToFile(target); | ||
Console.WriteLine($"Extracted {file.FullName}"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Scripts | ||
|
||
- [NuGetThosePackages.csx](NuGetThosePackages.csx) |