-
Notifications
You must be signed in to change notification settings - Fork 113
/
Copy pathNugetPackageInstallerTests.cs
82 lines (67 loc) · 3.31 KB
/
NugetPackageInstallerTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using CSharpRepl.Services;
using CSharpRepl.Services.Nuget;
using CSharpRepl.Services.Roslyn;
using Microsoft.CodeAnalysis;
using Xunit;
namespace CSharpRepl.Tests;
[Collection(nameof(RoslynServices))]
public class NugetPackageInstallerTests : IAsyncLifetime
{
private readonly NugetPackageInstaller installer;
public NugetPackageInstallerTests()
{
installer = new NugetPackageInstaller(FakeConsole.CreateStubbedOutput().console, new Configuration());
}
public Task InitializeAsync() => Task.CompletedTask;
public Task DisposeAsync() => Task.CompletedTask;
/// <summary>
/// https://github.com/waf/CSharpRepl/issues/58
/// </summary>
[Fact]
public async Task InstallRuntimeSpecificPackage()
{
var references = await installer.InstallAsync("System.Management", "6.0.0");
Assert.True(references.Length >= 1);
var reference = references.FirstOrDefault(r => r.FilePath.EndsWith("System.Management.dll", StringComparison.OrdinalIgnoreCase));
Assert.NotNull(reference);
var winRuntimeSelected = reference.FilePath.Contains(Path.Combine("runtimes", "win", "lib"), StringComparison.OrdinalIgnoreCase);
var isWin = Environment.OSVersion.Platform == PlatformID.Win32NT;
Assert.Equal(isWin, winRuntimeSelected);
}
[Fact]
public async Task InstallPackageWithSupportedButEmptyTargets()
{
var references = await installer.InstallAsync("Microsoft.CSharp", "4.7.0"); //some targets contains only empty file '_._'
Assert.True(references.Length >= 1);
var reference = references.FirstOrDefault(r => r.FilePath.EndsWith("Microsoft.CSharp.dll", StringComparison.OrdinalIgnoreCase));
Assert.NotNull(reference);
Assert.True(reference.FilePath.Contains("lib", StringComparison.OrdinalIgnoreCase));
}
[Fact]
public async Task InstallPackageThatOnlyContainsDependencies()
{
// humanizer does not target any frameworks itself, but depends on nuget packages that do.
var references = await installer.InstallAsync("Humanizer", "2.14.1");
Assert.True(references.Length >= 1);
var reference = references.FirstOrDefault(r => r.FilePath.EndsWith("Humanizer.dll", StringComparison.OrdinalIgnoreCase));
Assert.NotNull(reference);
Assert.True(reference.FilePath.Contains("lib", StringComparison.OrdinalIgnoreCase));
}
[Fact] // https://github.com/waf/CSharpRepl/issues/251
public async Task InstallPackageThatContainsImplicitVersioning()
{
// The package version is "1.2" but if we accidentally normalize the version, it normalizes to 1.2.0 and causes directory not found errors
var references = await installer.InstallAsync("Emik.Results", "1.2");
Assert.True(references.Length >= 1);
var reference = references.FirstOrDefault(r => r.FilePath.EndsWith("Emik.Results.dll", StringComparison.OrdinalIgnoreCase));
Assert.NotNull(reference);
Assert.True(reference.FilePath.Contains("lib", StringComparison.OrdinalIgnoreCase));
}
}