-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathManifestReaderFunctionalTests.cs
104 lines (89 loc) · 4.35 KB
/
ManifestReaderFunctionalTests.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.NET.Sdk.WorkloadManifestReader;
namespace ManifestReaderTests
{
public class ManifestReaderFunctionalTests : SdkTest
{
private readonly string ManifestPath;
public ManifestReaderFunctionalTests(ITestOutputHelper log) : base(log)
{
ManifestPath = Path.Combine(_testAssetsManager.GetAndValidateTestProjectDirectory("SampleManifest"), "Sample.json");
}
[Fact]
public void ItShouldGetAllTemplatesPacks()
{
WorkloadResolver workloadResolver = SetUp();
var result = workloadResolver.GetInstalledWorkloadPacksOfKind(WorkloadPackKind.Template);
result.Should().HaveCount(1);
var templateItem = result.First();
templateItem.Id.ToString().Should().Be("Xamarin.Android.Templates");
templateItem.IsStillPacked.Should().BeFalse();
templateItem.Kind.Should().Be(WorkloadPackKind.Template);
templateItem.Path.Should()
.Be(Path.Combine("fakepath", "template-packs", "xamarin.android.templates.1.0.3.nupkg"));
}
[Fact]
public void ItShouldGetAllSdkPacks()
{
WorkloadResolver workloadResolver = SetUp();
var result = workloadResolver.GetInstalledWorkloadPacksOfKind(WorkloadPackKind.Sdk);
result.Should().HaveCount(5);
var androidWorkloads = result.Single(w => w.Id == "Xamarin.Android.Sdk");
androidWorkloads.Id.ToString().Should().Be("Xamarin.Android.Sdk");
androidWorkloads.IsStillPacked.Should().BeTrue();
androidWorkloads.Kind.Should().Be(WorkloadPackKind.Sdk);
androidWorkloads.Version.Should().Be("8.4.7");
androidWorkloads.Path.Should().Be(Path.Combine("fakepath", "packs", "Xamarin.Android.Sdk", "8.4.7"));
}
[Fact]
public void ItShouldGetWorkloadDescription()
{
WorkloadResolver workloadResolver = SetUp();
var result = workloadResolver.GetWorkloadInfo(new WorkloadId("xamarin-android"));
result.Description.Should().Be("Create, build and run Android apps");
}
private WorkloadResolver SetUp()
{
var workloadResolver =
WorkloadResolver.CreateForTests(new FakeManifestProvider(new[] { ManifestPath }),
"fakepath");
workloadResolver.ReplaceFilesystemChecksForTest(fileExists: (_) => true, directoryExists: (_) => true);
return workloadResolver;
}
[Fact]
public void GivenTemplateNupkgDoesNotExistOnDiskItShouldReturnEmpty()
{
var workloadResolver =
WorkloadResolver.CreateForTests(new FakeManifestProvider(new[] { ManifestPath }),
"fakepath");
workloadResolver.ReplaceFilesystemChecksForTest(fileExists: (_) => false, directoryExists: (_) => true);
var result = workloadResolver.GetInstalledWorkloadPacksOfKind(WorkloadPackKind.Template);
result.Should().HaveCount(0);
}
[Fact]
public void GivenWorkloadSDKsDirectoryNotExistOnDiskItShouldReturnEmpty()
{
var workloadResolver =
WorkloadResolver.CreateForTests(new FakeManifestProvider(new[] { ManifestPath }),
"fakepath");
workloadResolver.ReplaceFilesystemChecksForTest(fileExists: (_) => true, directoryExists: (_) => false);
var result = workloadResolver.GetInstalledWorkloadPacksOfKind(WorkloadPackKind.Sdk);
result.Should().HaveCount(0);
}
[Fact]
public void ItCanReadIntegerVersion()
{
var testFolder = _testAssetsManager.CreateTestDirectory().Path;
var manifestPath = Path.Combine(testFolder, "manifest.json");
File.WriteAllText(manifestPath, @"
{
""version"": 5
}");
var workloadResolver =
WorkloadResolver.CreateForTests(new FakeManifestProvider(manifestPath), "fakepath");
workloadResolver.ReplaceFilesystemChecksForTest(fileExists: (_) => true, directoryExists: (_) => true);
workloadResolver.GetInstalledWorkloadPacksOfKind(WorkloadPackKind.Template).Should().BeEmpty();
}
}
}