Skip to content

Commit db64e70

Browse files
committed
fixup failing tests
- file conflicts are now the full path, since the goal state is fully resolved. - added a helper to make it easier to read test output when errors don't match.
1 parent b56ad61 commit db64e70

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

test/LibraryManager.Test/LibrariesValidatorTest.cs

+8-7
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
using Microsoft.Web.LibraryManager.Mocks;
1414
using Microsoft.Web.LibraryManager.Providers.Cdnjs;
1515
using Microsoft.Web.LibraryManager.Providers.FileSystem;
16-
using Microsoft.Web.LibraryManager.Providers.Unpkg;
1716
using Microsoft.Web.LibraryManager.Providers.jsDelivr;
17+
using Microsoft.Web.LibraryManager.Providers.Unpkg;
18+
using Microsoft.Web.LibraryManager.Test.TestUtilities;
1819
using Moq;
1920

2021
namespace Microsoft.Web.LibraryManager.Test
@@ -44,8 +45,9 @@ public void Setup()
4445
[TestMethod]
4546
public async Task DetectConflictsAsync_ConflictingFiles_SameDestination()
4647
{
48+
string conflictFilePath = Path.Combine(_dependencies.GetHostInteractions().WorkingDirectory, "lib", "package.json");
4749
string expectedErrorCode = "LIB016";
48-
string expectedErrorMessage = "Conflicting file \"lib\\package.json\" found in more than one library: jquery, d3";
50+
string expectedErrorMessage = $"Conflicting file \"{conflictFilePath}\" found in more than one library: jquery, d3";
4951
var manifest = Manifest.FromJson(_docDifferentLibraries_SameFiles_SameLocation, _dependencies);
5052

5153
IEnumerable<OperationResult<LibraryInstallationGoalState>> conflicts = await LibrariesValidator.GetManifestErrorsAsync(manifest, _dependencies, CancellationToken.None);
@@ -92,11 +94,10 @@ public async Task DetectConflictsAsync_SameLibrary_DifferentProviders()
9294

9395
IEnumerable<OperationResult<LibraryInstallationGoalState>> results = await LibrariesValidator.GetManifestErrorsAsync(manifest, _dependencies, CancellationToken.None);
9496

95-
var conflictsList = results.ToList();
97+
var conflictsList = results.Where(r => r.Errors?.Count > 0).ToList();
9698
Assert.AreEqual(1, conflictsList.Count);
97-
Assert.IsTrue(conflictsList[0].Errors.Count == 1);
98-
Assert.AreEqual(conflictsList[0].Errors[0].Code, expectedErrorCode);
99-
Assert.AreEqual(conflictsList[0].Errors[0].Message, expectedErrorMessage);
99+
List<IError> expectedErrors = [new Contracts.Error(expectedErrorCode, expectedErrorMessage)];
100+
Assert.That.ErrorsEqual(expectedErrors, conflictsList[0].Errors);
100101
}
101102

102103
[TestMethod]
@@ -244,7 +245,7 @@ public async Task GetLibrariesErrors_LibrariesNoProvider()
244245
""{ManifestConstants.Library}"": ""[email protected]"",
245246
""{ManifestConstants.Provider}"": ""unpkg"",
246247
""{ManifestConstants.Destination}"": ""lib2"",
247-
""{ManifestConstants.Files}"": [ ""jquery.js"" ]
248+
""{ManifestConstants.Files}"": [ ""dist/jquery.js"" ]
248249
}},
249250
]
250251
}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Runtime.CompilerServices;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
using Microsoft.VisualStudio.TestTools.UnitTesting;
11+
using Microsoft.Web.LibraryManager.Contracts;
12+
13+
namespace Microsoft.Web.LibraryManager.Test.TestUtilities;
14+
15+
public static class AssertExtensions
16+
{
17+
public static void ErrorsEqual(this Assert assert, IList<IError> expected, IList<IError> actual)
18+
{
19+
string BuildString(IList<IError> errors)
20+
{
21+
StringBuilder stringBuilder = new StringBuilder();
22+
foreach (IError error in errors)
23+
{
24+
stringBuilder.AppendLine($"{error.Code}: {error.Message}");
25+
}
26+
return stringBuilder.ToString();
27+
}
28+
29+
Assert.AreEqual(BuildString(expected), BuildString(actual));
30+
}
31+
}

0 commit comments

Comments
 (0)