forked from dotnet/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMockManifestProvider.cs
57 lines (48 loc) · 2.09 KB
/
MockManifestProvider.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
// 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
{
internal class MockManifestProvider : IWorkloadManifestProvider
{
readonly (string name, string path, string manifestVersion, string featureBand)[] _manifests;
public MockManifestProvider(params string[] manifestPaths)
{
_manifests = Array.ConvertAll(manifestPaths, mp =>
{
string manifestId = Path.GetFileNameWithoutExtension(Path.GetDirectoryName(mp));
return (manifestId, mp, (string)null, (string)null);
});
SdkFeatureBand = new SdkFeatureBand("6.0.100");
}
public MockManifestProvider(params (string name, string path, string manifestVersion, string featureBand)[] manifests)
{
_manifests = manifests;
SdkFeatureBand = new SdkFeatureBand("6.0.100");
}
public SdkFeatureBand SdkFeatureBand { get; set; }
public Dictionary<string, WorkloadSet> GetAvailableWorkloadSets() => new();
public void RefreshWorkloadManifests() { }
public IEnumerable<ReadableWorkloadManifest> GetManifests()
{
foreach ((var id, var path, var manifestVersion, var featureBand) in _manifests)
{
yield return new(
id,
Path.GetDirectoryName(path),
path,
featureBand ?? SdkFeatureBand.ToString(),
manifestVersion,
() => File.OpenRead(path),
() => WorkloadManifestReader.TryOpenLocalizationCatalogForManifest(path)
);
}
}
public string GetSdkFeatureBand() => SdkFeatureBand.ToString();
public WorkloadVersion GetWorkloadVersion() => new WorkloadVersion
{
Version = GetSdkFeatureBand() + ".2",
WorkloadInstallType = WorkloadVersion.Type.LooseManifest
};
}
}