From 2a4934419c66169e66ed9c4a16905f31539c070c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Hellander?= Date: Wed, 3 Jan 2024 13:07:17 +0100 Subject: [PATCH] Update IImportScopeWrapperCSharp11UnitTests to also verify the alias symbols returned by the wrapper #3594 --- .../IImportScopeWrapperCSharp11UnitTests.cs | 30 +++++++++++-------- .../StyleCop.Analyzers.Test.CSharp11.csproj | 1 + 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp11/Lightup/IImportScopeWrapperCSharp11UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp11/Lightup/IImportScopeWrapperCSharp11UnitTests.cs index 1980e143e..2043f5cba 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp11/Lightup/IImportScopeWrapperCSharp11UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp11/Lightup/IImportScopeWrapperCSharp11UnitTests.cs @@ -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 Aliases => ImmutableArray.Empty; + var aliasSymbolMocks = new List(); + for (var i = 0; i < numberOfAliasSymbols; i++) + { + aliasSymbolMocks.Add(Mock.Of()); + } - public ImmutableArray ExternAliases => throw new NotImplementedException(); - - public ImmutableArray Imports => throw new NotImplementedException(); - - public ImmutableArray XmlNamespaces => throw new NotImplementedException(); + var importScopeMock = new Mock(); + importScopeMock.Setup(x => x.Aliases).Returns(aliasSymbolMocks.ToImmutableArray()); + return importScopeMock.Object; } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp11/StyleCop.Analyzers.Test.CSharp11.csproj b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp11/StyleCop.Analyzers.Test.CSharp11.csproj index 3ce4f0d1c..1172669bb 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp11/StyleCop.Analyzers.Test.CSharp11.csproj +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp11/StyleCop.Analyzers.Test.CSharp11.csproj @@ -19,6 +19,7 @@ +