Skip to content

Commit

Permalink
Update IImportScopeWrapperCSharp11UnitTests to also verify the alias …
Browse files Browse the repository at this point in the history
…symbols returned by the wrapper

#3594
  • Loading branch information
bjornhellander committed Jan 3, 2024
1 parent 972a866 commit 2a49344
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,39 @@

namespace StyleCop.Analyzers.Test.CSharp11.Lightup
{
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
using Moq;
using StyleCop.Analyzers.Lightup;
using StyleCop.Analyzers.Test.CSharp10.Lightup;
using Xunit;

public partial class IImportScopeWrapperCSharp11UnitTests : IImportScopeWrapperCSharp10UnitTests
{
[Fact]
public void TestCompatibleInstance()
[Theory]
[InlineData(0)]
[InlineData(1)]
[InlineData(2)]
public void TestCompatibleInstance(int numberOfAliasSymbols)
{
var obj = new TestImportScope();
var obj = CreateImportScope(numberOfAliasSymbols);
Assert.True(IImportScopeWrapper.IsInstance(obj));
var wrapper = IImportScopeWrapper.FromObject(obj);
Assert.Empty(wrapper.Aliases);
Assert.Equal(obj.Aliases, wrapper.Aliases);
}

private class TestImportScope : IImportScope
private static IImportScope CreateImportScope(int numberOfAliasSymbols)
{
public ImmutableArray<IAliasSymbol> Aliases => ImmutableArray<IAliasSymbol>.Empty;
var aliasSymbolMocks = new List<IAliasSymbol>();
for (var i = 0; i < numberOfAliasSymbols; i++)
{
aliasSymbolMocks.Add(Mock.Of<IAliasSymbol>());
}

public ImmutableArray<IAliasSymbol> ExternAliases => throw new NotImplementedException();

public ImmutableArray<ImportedNamespaceOrType> Imports => throw new NotImplementedException();

public ImmutableArray<ImportedXmlNamespace> XmlNamespaces => throw new NotImplementedException();
var importScopeMock = new Mock<IImportScope>();
importScopeMock.Setup(x => x.Aliases).Returns(aliasSymbolMocks.ToImmutableArray());
return importScopeMock.Object;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.4.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" PrivateAssets="all" />
</ItemGroup>
Expand Down

0 comments on commit 2a49344

Please sign in to comment.