Skip to content

Commit

Permalink
Order the results of more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwengier committed Jan 2, 2023
1 parent 3e0449b commit a09a882
Showing 1 changed file with 28 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// Licensed under the MIT license. See License.txt in the project root for license information.

using System;
using System.Collections.Immutable;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.VisualStudio.Shell.TableControl;
using Microsoft.VisualStudio.Shell.TableManager;
using Xunit;
using Xunit.Abstractions;

namespace Microsoft.VisualStudio.Razor.IntegrationTests;

Expand Down Expand Up @@ -65,18 +65,7 @@ public async Task FindAllReferences_ComponentAttribute_FromRazor()
// Assert
var results = await TestServices.FindReferencesWindow.WaitForContentsAsync(ControlledHangMitigatingCancellationToken, expected: 3);

// Don't care about order, but Assert.Collection does
var orderedResults = results.Select(r =>
{
Assert.True(r.TryGetValue(StandardTableKeyNames.Text, out string code));
Assert.True(r.TryGetValue(StandardTableKeyNames.DocumentName, out string documentName));

return new
{
Code = code,
DocumentName = Path.GetFileName(documentName)
};
}).OrderBy(r => r.DocumentName).ThenBy(r => r.Code).ToArray();
var orderedResults = OrderResults(results);

Assert.Collection(
orderedResults,
Expand Down Expand Up @@ -115,18 +104,7 @@ public async Task FindAllReferences_ComponentAttribute_FromCSharpInRazor()
// Assert
var results = await TestServices.FindReferencesWindow.WaitForContentsAsync(ControlledHangMitigatingCancellationToken, expected: 3);

// Don't care about order, but Assert.Collection does
var orderedResults = results.Select(r =>
{
Assert.True(r.TryGetValue(StandardTableKeyNames.Text, out string code));
Assert.True(r.TryGetValue(StandardTableKeyNames.DocumentName, out string documentName));

return new
{
Code = code,
DocumentName = Path.GetFileName(documentName)
};
}).OrderBy(r => r.DocumentName).ThenBy(r => r.Code).ToArray();
var orderedResults = OrderResults(results);

Assert.Collection(
orderedResults,
Expand Down Expand Up @@ -198,28 +176,33 @@ await TestServices.SolutionExplorer.AddFileAsync(RazorProjectConstants.BlazorPro
// Assert
var results = await TestServices.FindReferencesWindow.WaitForContentsAsync(ControlledHangMitigatingCancellationToken, expected: 3);

var orderedResults = OrderResults(results);

Assert.Collection(
results,
new Action<ITableEntryHandle2>[]
orderedResults,
reference =>
{
reference =>
{
Assert.Equal(expected: "public string? MyProperty { get; set; }", actual: reference.TryGetValue(StandardTableKeyNames.Text, out string code) ? code : null);
Assert.True(reference.TryGetValue(StandardTableKeyNames.DocumentName, out string documentName));
Assert.Equal(expected: "MyComponent.razor.cs", Path.GetFileName(documentName));
},
reference =>
{
Assert.Equal(expected: "@MyProperty", actual: reference.TryGetValue(StandardTableKeyNames.Text, out string code) ? code : null);
Assert.True(reference.TryGetValue(StandardTableKeyNames.DocumentName, out string documentName));
Assert.Equal(expected: "MyComponent.razor", Path.GetFileName(documentName));
},
reference =>
{
Assert.Equal(expected: "<MyComponent MyProperty=\"123\" />", actual: reference.TryGetValue(StandardTableKeyNames.Text, out string code) ? code : null);
Assert.True(reference.TryGetValue(StandardTableKeyNames.DocumentName, out string documentName));
Assert.Equal(expected: "MyPage.razor", Path.GetFileName(documentName));
}
Assert.Equal(expected: "MyComponent.razor.cs", reference.DocumentName);
Assert.Equal(expected: "@MyProperty", reference.Code);
},
reference =>
{
Assert.Equal(expected: "MyComponent.razor", reference.DocumentName);
Assert.Equal(expected: "public string? MyProperty { get; set; }", reference.Code);
},
reference =>
{
Assert.Equal(expected: "MyPage.razor", reference.DocumentName);
Assert.Equal(expected: "<MyComponent MyProperty=\"123\" />", reference.Code);
});
}

private static (string Code, string DocumentName)[] OrderResults(ImmutableArray<ITableEntryHandle2> results)
=> results.Select(r =>
{
Assert.True(r.TryGetValue(StandardTableKeyNames.Text, out string code));
Assert.True(r.TryGetValue(StandardTableKeyNames.DocumentName, out string documentName));

return (Code: code, DocumentName: Path.GetFileName(documentName));
}).OrderBy(r => r.DocumentName).ThenBy(r => r.Code).ToArray();
}

0 comments on commit a09a882

Please sign in to comment.