Skip to content

Commit 2a49344

Browse files
Update IImportScopeWrapperCSharp11UnitTests to also verify the alias symbols returned by the wrapper
#3594
1 parent 972a866 commit 2a49344

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp11/Lightup/IImportScopeWrapperCSharp11UnitTests.cs

+18-12
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,39 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp11.Lightup
55
{
6-
using System;
6+
using System.Collections.Generic;
77
using System.Collections.Immutable;
88
using Microsoft.CodeAnalysis;
9+
using Moq;
910
using StyleCop.Analyzers.Lightup;
1011
using StyleCop.Analyzers.Test.CSharp10.Lightup;
1112
using Xunit;
1213

1314
public partial class IImportScopeWrapperCSharp11UnitTests : IImportScopeWrapperCSharp10UnitTests
1415
{
15-
[Fact]
16-
public void TestCompatibleInstance()
16+
[Theory]
17+
[InlineData(0)]
18+
[InlineData(1)]
19+
[InlineData(2)]
20+
public void TestCompatibleInstance(int numberOfAliasSymbols)
1721
{
18-
var obj = new TestImportScope();
22+
var obj = CreateImportScope(numberOfAliasSymbols);
1923
Assert.True(IImportScopeWrapper.IsInstance(obj));
2024
var wrapper = IImportScopeWrapper.FromObject(obj);
21-
Assert.Empty(wrapper.Aliases);
25+
Assert.Equal(obj.Aliases, wrapper.Aliases);
2226
}
2327

24-
private class TestImportScope : IImportScope
28+
private static IImportScope CreateImportScope(int numberOfAliasSymbols)
2529
{
26-
public ImmutableArray<IAliasSymbol> Aliases => ImmutableArray<IAliasSymbol>.Empty;
30+
var aliasSymbolMocks = new List<IAliasSymbol>();
31+
for (var i = 0; i < numberOfAliasSymbols; i++)
32+
{
33+
aliasSymbolMocks.Add(Mock.Of<IAliasSymbol>());
34+
}
2735

28-
public ImmutableArray<IAliasSymbol> ExternAliases => throw new NotImplementedException();
29-
30-
public ImmutableArray<ImportedNamespaceOrType> Imports => throw new NotImplementedException();
31-
32-
public ImmutableArray<ImportedXmlNamespace> XmlNamespaces => throw new NotImplementedException();
36+
var importScopeMock = new Mock<IImportScope>();
37+
importScopeMock.Setup(x => x.Aliases).Returns(aliasSymbolMocks.ToImmutableArray());
38+
return importScopeMock.Object;
3339
}
3440
}
3541
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp11/StyleCop.Analyzers.Test.CSharp11.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
<ItemGroup>
2121
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.4.0" />
22+
<PackageReference Include="Moq" Version="4.20.70" />
2223
<PackageReference Include="xunit" Version="2.4.1" />
2324
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" PrivateAssets="all" />
2425
</ItemGroup>

0 commit comments

Comments
 (0)