Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

namespace Microsoft.DotNet.Cli.Utils.Tests
{
[TestClass]
public class TransientSdkResolutionErrorDetectorTests
{
[Fact]
[TestMethod]
public void TransientInBoxSdkResolutionFailureIsDetected()
{
string input =
Expand All @@ -20,13 +21,13 @@ public void TransientInBoxSdkResolutionFailureIsDetected()
TransientSdkResolutionErrorDetector.IsTransientError(input).Should().BeTrue();
}

[Fact]
[TestMethod]
public void NullInputIsNotTransient()
{
TransientSdkResolutionErrorDetector.IsTransientError(null).Should().BeFalse();
}

[Fact]
[TestMethod]
public void SuccessfulBuildIsNotTransient()
{
string input =
Expand All @@ -37,7 +38,7 @@ public void SuccessfulBuildIsNotTransient()
TransientSdkResolutionErrorDetector.IsTransientError(input).Should().BeFalse();
}

[Fact]
[TestMethod]
public void MissingVersionedSdkWithoutResolverNullIsNotTransient()
{
// A genuinely missing, version-specified SDK is a deterministic failure (no workload resolver
Expand All @@ -47,7 +48,7 @@ public void MissingVersionedSdkWithoutResolverNullIsNotTransient()
TransientSdkResolutionErrorDetector.IsTransientError(input).Should().BeFalse();
}

[Fact]
[TestMethod]
public void OtherResolverReturningNullIsNotTransient()
{
// A "returned null" message from a different resolver must not trigger a retry: only the in-box
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
// 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.TestFramework;
using Microsoft.NET.Sdk.WorkloadManifestReader;

namespace ManifestReaderTests
{
[TestClass]
public class ManifestReaderFunctionalTests : SdkTest
{
private readonly string ManifestPath;

public ManifestReaderFunctionalTests(ITestOutputHelper log) : base(log)
public ManifestReaderFunctionalTests()
{
ManifestPath = Path.Combine(TestAssetsManager.GetAndValidateTestProjectDirectory("SampleManifest"), "Sample.json");
}

[Fact]
[TestMethod]
public void ItShouldGetAllTemplatesPacks()
{
WorkloadResolver workloadResolver = SetUp();
Expand All @@ -28,7 +30,7 @@ public void ItShouldGetAllTemplatesPacks()
.Be(Path.Combine("fakepath", "template-packs", "xamarin.android.templates.1.0.3.nupkg"));
}

[Fact]
[TestMethod]
public void ItShouldGetAllSdkPacks()
{
WorkloadResolver workloadResolver = SetUp();
Expand All @@ -42,7 +44,7 @@ public void ItShouldGetAllSdkPacks()
androidWorkloads.Path.Should().Be(Path.Combine("fakepath", "packs", "Xamarin.Android.Sdk", "8.4.7"));
}

[Fact]
[TestMethod]
public void ItShouldGetWorkloadDescription()
{
WorkloadResolver workloadResolver = SetUp();
Expand All @@ -60,7 +62,7 @@ private WorkloadResolver SetUp()
return workloadResolver;
}

[Fact]
[TestMethod]
public void GivenTemplateNupkgDoesNotExistOnDiskItShouldReturnEmpty()
{
var workloadResolver =
Expand All @@ -71,7 +73,7 @@ public void GivenTemplateNupkgDoesNotExistOnDiskItShouldReturnEmpty()
result.Should().HaveCount(0);
}

[Fact]
[TestMethod]
public void GivenWorkloadSDKsDirectoryNotExistOnDiskItShouldReturnEmpty()
{
var workloadResolver =
Expand All @@ -82,7 +84,7 @@ public void GivenWorkloadSDKsDirectoryNotExistOnDiskItShouldReturnEmpty()
result.Should().HaveCount(0);
}

[Fact]
[TestMethod]
public void ItCanReadIntegerVersion()
{
var testFolder = TestAssetsManager.CreateTestDirectory().Path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,27 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Globalization;
using Microsoft.NET.TestFramework;
using Microsoft.NET.Sdk.WorkloadManifestReader;

namespace ManifestReaderTests
{
[TestClass]
public class ManifestTests : SdkTest
{
private const string fakeRootPath = "fakeRootPath";
private readonly string ManifestPath;
private readonly string SampleProjectPath;

public ManifestTests(ITestOutputHelper log) : base(log)
public ManifestTests()
{
SampleProjectPath = TestAssetsManager.GetAndValidateTestProjectDirectory("SampleManifest");
ManifestPath = GetSampleManifestPath("Sample.json");
}

string GetSampleManifestPath(string name) => Path.Combine(SampleProjectPath, name);

[Fact]
[TestMethod]
public void ItCanDeserialize()
{
using (FileStream fsSource = new(ManifestPath, FileMode.Open, FileAccess.Read))
Expand All @@ -36,7 +38,7 @@ public void ItCanDeserialize()
}
}

[Fact]
[TestMethod]
public void AliasedPackPath()
{
var manifestProvider = new FakeManifestProvider(ManifestPath);
Expand All @@ -52,7 +54,7 @@ public void AliasedPackPath()
buildToolsPack.Path.Should().Be(Path.Combine(fakeRootPath, "packs", "Xamarin.Android.BuildTools.Win64Host", "8.4.7"));
}

[Fact]
[TestMethod]
public void UnresolvedAliasedPackPath()
{
var manifestProvider = new FakeManifestProvider(ManifestPath);
Expand All @@ -65,25 +67,25 @@ public void UnresolvedAliasedPackPath()
buildToolsPack.Should().BeNull();
}

[Fact]
[TestMethod]
public void GivenMultiplePackRoots_ItUsesTheFirstInstallableIfThePackDoesntExist()
{
TestMultiplePackRoots(false, false);
}

[Fact]
[TestMethod]
public void GivenMultiplePackRoots_ItUsesTheFirstOneIfBothExist()
{
TestMultiplePackRoots(true, true);
}

[Fact]
[TestMethod]
public void GivenMultiplePackRoots_ItUsesTheFirstOneIfOnlyItExists()
{
TestMultiplePackRoots(false, true);
}

[Fact]
[TestMethod]
public void GivenMultiplePackRoots_ItUsesTheSecondOneIfOnlyItExists()
{
TestMultiplePackRoots(true, false);
Expand Down Expand Up @@ -120,7 +122,7 @@ void TestMultiplePackRoots(bool defaultExists, bool additionalExists)
pack!.Path.Should().Be(expectedPath);
}

[Fact]
[TestMethod]
public void GivenNonExistentPackRoot_ItIgnoresIt()
{
var testDirectory = TestAssetsManager.CreateTestDirectory().Path;
Expand All @@ -140,7 +142,7 @@ public void GivenNonExistentPackRoot_ItIgnoresIt()
pack!.Path.Should().Be(defaultPackPath);
}

[Fact]
[TestMethod]
public void ItChecksDependencies()
{
static string MakeManifest(string version, params (string id, string version)[] dependsOn)
Expand Down Expand Up @@ -181,7 +183,7 @@ static string MakeManifest(string version, params (string id, string version)[]

var missingManifestResolver = WorkloadResolver.CreateForTests(missingManifestProvider, fakeRootPath);

var missingManifestEx = Assert.Throws<WorkloadManifestCompositionException>(() => missingManifestResolver.GetAvailableWorkloads().ToList());
var missingManifestEx = Assert.ThrowsExactly<WorkloadManifestCompositionException>(() => missingManifestResolver.GetAvailableWorkloads().ToList());
Assert.StartsWith("Did not find workload manifest dependency 'BBB' required by manifest 'AAA'", missingManifestEx.Message);

var inconsistentManifestProvider = new InMemoryFakeManifestProvider
Expand All @@ -193,21 +195,21 @@ static string MakeManifest(string version, params (string id, string version)[]
};

var inconsistentManifestResolver = WorkloadResolver.CreateForTests(inconsistentManifestProvider, fakeRootPath);
var inconsistentManifestEx = Assert.Throws<WorkloadManifestCompositionException>(() => inconsistentManifestResolver.GetAvailableWorkloads().ToList());
var inconsistentManifestEx = Assert.ThrowsExactly<WorkloadManifestCompositionException>(() => inconsistentManifestResolver.GetAvailableWorkloads().ToList());
Assert.StartsWith("Workload manifest dependency 'DDD' version '30.0.0' is lower than version '39.0.0' required by manifest 'BBB'", inconsistentManifestEx.Message);
}

[Fact]
[TestMethod]
public void WillNotLoadManifestWithNullAlias()
{
var manifestPath = GetSampleManifestPath("NullAliasError.json");
using FileStream fsSource = new(manifestPath, FileMode.Open, FileAccess.Read);

var ex = Assert.Throws<WorkloadManifestFormatException>(() => WorkloadManifestReader.ReadWorkloadManifest("NullAliasError", fsSource, manifestPath));
var ex = Assert.ThrowsExactly<WorkloadManifestFormatException>(() => WorkloadManifestReader.ReadWorkloadManifest("NullAliasError", fsSource, manifestPath));
Assert.Contains("Expected string value at offset", ex.Message);
}

[Fact]
[TestMethod]
public void ItCanFindLocalizationCatalog()
{
string expected = MakePathNative("manifests/My.Manifest/localize/WorkloadManifest.pt-BR.json");
Expand All @@ -218,10 +220,10 @@ public void ItCanFindLocalizationCatalog()
s => true
);

Assert.Equal(expected, locPath);
Assert.AreEqual(expected, locPath);
}

[Fact]
[TestMethod]
public void ItCanFindParentCultureLocalizationCatalog()
{
string expected = MakePathNative("manifests/My.Manifest/localize/WorkloadManifest.pt.json");
Expand All @@ -232,12 +234,12 @@ public void ItCanFindParentCultureLocalizationCatalog()
s => s == expected
);

Assert.Equal(expected, locPath);
Assert.AreEqual(expected, locPath);
}

static string MakePathNative(string path) => path.Replace('/', Path.DirectorySeparatorChar);

[Fact]
[TestMethod]
public void ItCanLocalizeDescriptions()
{
var manifest = GetSampleManifestPath("Sample.json");
Expand All @@ -250,10 +252,10 @@ public void ItCanLocalizeDescriptions()
var workloads = resolver.GetAvailableWorkloads().ToList();

var xamAndroid = workloads.FirstOrDefault(w => w.Id == "xamarin-android");
Assert.Equal("Localized description for xamarin-android", xamAndroid?.Description);
Assert.AreEqual("Localized description for xamarin-android", xamAndroid?.Description);

var xamAndroidBuild = workloads.FirstOrDefault(w => w.Id == "xamarin-android-build");
Assert.Equal("Localized description for xamarin-android-build", xamAndroidBuild?.Description);
Assert.AreEqual("Localized description for xamarin-android-build", xamAndroidBuild?.Description);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="MSTest.Sdk">

<PropertyGroup>
<TargetFrameworks>net472;$(SdkTargetFramework)</TargetFrameworks>
<TargetFrameworks Condition=" '$([MSBuild]::IsOSPlatform(`Windows`))' == 'false' ">$(SdkTargetFramework)</TargetFrameworks>
<OutputType Condition="'$(TargetFramework)' == '$(SdkTargetFramework)'">Exe</OutputType>
<StrongNameKeyId>MicrosoftAspNetCore</StrongNameKeyId>

<!-- By default test projects don't append TargetFramework to output path, but for multi-targeted tests
Expand All @@ -13,7 +12,7 @@

<ItemGroup>
<ProjectReference Include="..\..\src\Resolvers\Microsoft.NET.Sdk.WorkloadManifestReader\Microsoft.NET.Sdk.WorkloadManifestReader.csproj" />
<ProjectReference Include="..\Microsoft.NET.TestFramework\Microsoft.NET.TestFramework.csproj" />
<ProjectReference Include="..\Microsoft.NET.TestFramework.MSTest\Microsoft.NET.TestFramework.MSTest.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading
Loading