Skip to content

Commit

Permalink
Resurrected older Surround With functionality in order to work around…
Browse files Browse the repository at this point in the history
… code templates timeout issue.
  • Loading branch information
sergey-visual-studio committed Feb 20, 2023
1 parent d1d124b commit 863969e
Show file tree
Hide file tree
Showing 21 changed files with 543 additions and 391 deletions.
6 changes: 4 additions & 2 deletions DPackRx.Tests/DPackRx.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@
<Compile Include="Features\MiscellaneousFeatureTests.cs" />
<Compile Include="Features\BookmarksServiceTests.cs" />
<Compile Include="Features\FileBrowserFeatureTests.cs" />
<Compile Include="Features\SurroundWithModelTests.cs" />
<Compile Include="Features\SurroundWithFeatureTests.cs" />
<Compile Include="Features\SupportOptionsFirstTimeUseTests.cs" />
<Compile Include="Features\SupportOptionsFeatureTests.cs" />
<Compile Include="Language\LanguageSettingsTests.cs" />
<Compile Include="Language\LanguageServiceTests.cs" />
<Compile Include="Options\OptionsPersistenceServiceTests.cs" />
<Compile Include="Options\OptionsServiceTests.cs" />
Expand Down Expand Up @@ -93,10 +95,10 @@
<Version>13.0.1</Version>
</PackageReference>
<PackageReference Include="NUnit">
<Version>3.13.2</Version>
<Version>3.13.3</Version>
</PackageReference>
<PackageReference Include="NUnit3TestAdapter">
<Version>4.1.0</Version>
<Version>4.3.1</Version>
</PackageReference>
<PackageReference Include="VsWebSite.Interop90">
<Version>17.0.31902.203</Version>
Expand Down
58 changes: 22 additions & 36 deletions DPackRx.Tests/Features/SurroundWithFeatureTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Windows.Input;

using Moq;
using NUnit.Framework;

using DPackRx.CodeModel;
using DPackRx.Features;
Expand All @@ -12,6 +8,10 @@
using DPackRx.Package;
using DPackRx.Services;

using Moq;

using NUnit.Framework;

namespace DPackRx.Tests.Features
{
/// <summary>
Expand All @@ -25,10 +25,9 @@ public class SurroundWithFeatureTests
private Mock<IServiceProvider> _serviceProviderMock;
private Mock<ILog> _logMock;
private Mock<IOptionsService> _optionsServiceMock;
private Mock<IShellHelperService> _shellHelperServiceMock;
private Mock<IShellSelectionService> _shellSelectionServiceMock;
private Mock<IFileTypeResolver> _fileTypeResolverMock;
private Mock<IKeyboardService> _keyboardServiceMock;
private Mock<ISurroundWithFormatterService> _surroundWithFormatterServiceMock;
private LanguageSettings _settings;

#endregion
Expand All @@ -45,9 +44,6 @@ public void Setup()

_optionsServiceMock = new Mock<IOptionsService>();

_shellHelperServiceMock = new Mock<IShellHelperService>();
_shellHelperServiceMock.Setup(s => s.ExecuteCommand(It.IsNotNull<string>(), null)).Verifiable();

_shellSelectionServiceMock = new Mock<IShellSelectionService>();
_shellSelectionServiceMock.Setup(s => s.IsContextActive(It.IsAny<ContextType>())).Returns(true).Verifiable();
_shellSelectionServiceMock.Setup(s => s.GetActiveProject()).Returns(new object()).Verifiable();
Expand All @@ -57,9 +53,8 @@ public void Setup()
_fileTypeResolverMock = new Mock<IFileTypeResolver>();
_fileTypeResolverMock.Setup(f => f.GetCurrentLanguage(It.IsAny<object>(), out webProject)).Returns(_settings).Verifiable();

_keyboardServiceMock = new Mock<IKeyboardService>();
_keyboardServiceMock.Setup(k => k.Type(It.IsAny<Key>())).Verifiable();
_keyboardServiceMock.Setup(k => k.Type(It.IsAny<string>())).Verifiable();
_surroundWithFormatterServiceMock = new Mock<ISurroundWithFormatterService>();
_surroundWithFormatterServiceMock.Setup(s => s.Format(It.IsAny<SurroundWithLanguageModel>())).Verifiable();
}

[TearDown]
Expand All @@ -68,10 +63,9 @@ public void TearDown()
_serviceProviderMock = null;
_logMock = null;
_optionsServiceMock = null;
_shellHelperServiceMock = null;
_shellSelectionServiceMock = null;
_fileTypeResolverMock = null;
_keyboardServiceMock = null;
_surroundWithFormatterServiceMock = null;
_settings = null;
}

Expand All @@ -85,8 +79,7 @@ public void TearDown()
private IFeature GetFeature()
{
return new SurroundWithFeature(_serviceProviderMock.Object, _logMock.Object, _optionsServiceMock.Object,
_shellHelperServiceMock.Object, _shellSelectionServiceMock.Object, _fileTypeResolverMock.Object,
_keyboardServiceMock.Object);
_shellSelectionServiceMock.Object, _fileTypeResolverMock.Object, _surroundWithFormatterServiceMock.Object);
}

#endregion
Expand Down Expand Up @@ -160,12 +153,12 @@ public void IsValidContext_UnsupportedLanguage()
_shellSelectionServiceMock.Verify(s => s.IsContextActive(It.IsAny<ContextType>()), Times.Never);
}

[TestCase(CommandIDs.SW_TRY_CATCH, SurroundWithFeature.SNIPPET_TRY_CATCH)]
[TestCase(CommandIDs.SW_TRY_FINALLY, SurroundWithFeature.SNIPPET_TRY_FINALLY)]
[TestCase(CommandIDs.SW_FOR, SurroundWithFeature.SNIPPET_FOR)]
[TestCase(CommandIDs.SW_FOR_EACH, SurroundWithFeature.SNIPPET_FOR_EACH)]
[TestCase(CommandIDs.SW_REGION, SurroundWithFeature.SNIPPET_REGION)]
public void Execute(int commandId, string command)
[TestCase(CommandIDs.SW_TRY_CATCH)]
[TestCase(CommandIDs.SW_TRY_FINALLY)]
[TestCase(CommandIDs.SW_FOR)]
[TestCase(CommandIDs.SW_FOR_EACH)]
[TestCase(CommandIDs.SW_REGION)]
public void Execute(int commandId)
{
var feature = GetFeature();
var webProject = false;
Expand All @@ -175,30 +168,23 @@ public void Execute(int commandId, string command)
Assert.That(result, Is.True);
_shellSelectionServiceMock.Verify(s => s.GetActiveProject(), Times.Once);
_fileTypeResolverMock.Verify(f => f.GetCurrentLanguage(It.IsAny<object>(), out webProject), Times.Once);
_shellHelperServiceMock.Verify(s => s.ExecuteCommand(SurroundWithFeature.SURROUND_WITH_COMMAND, null), Times.Once);
_shellHelperServiceMock.Verify(s => s.ExecuteCommand(SurroundWithFeature.ISERT_SNIPPET_COMMAND, null), Times.Never);
_keyboardServiceMock.Verify(k => k.Type(Key.Enter), Times.Once);
_keyboardServiceMock.Verify(k => k.Type(command), Times.Once);
_surroundWithFormatterServiceMock.Verify(s => s.Format(It.IsNotNull<SurroundWithLanguageModel>()), Times.Once);
}

[TestCase("test")]
[TestCase("")]
[TestCase(null)]
public void Execute_LanguageName(string surroundWithLanguageName)
[Test]
public void Execute_UnsupportedLanguage()
{
var feature = GetFeature();
var webProject = false;
_settings.SurroundWithLanguageName = surroundWithLanguageName;
_settings = new LanguageSettings("Xml", "Xml") { Type = LanguageType.Xml, SurroundWith = true };
_fileTypeResolverMock.Setup(f => f.GetCurrentLanguage(It.IsAny<object>(), out webProject)).Returns(_settings).Verifiable();

var result = feature.Execute(CommandIDs.SW_REGION);

Assert.That(result, Is.True);
Assert.That(result, Is.False);
_shellSelectionServiceMock.Verify(s => s.GetActiveProject(), Times.Once);
_fileTypeResolverMock.Verify(f => f.GetCurrentLanguage(It.IsAny<object>(), out webProject), Times.Once);
_shellHelperServiceMock.Verify(s => s.ExecuteCommand(SurroundWithFeature.SURROUND_WITH_COMMAND, null), Times.Exactly(string.IsNullOrEmpty(surroundWithLanguageName) ? 1 : 0));
_shellHelperServiceMock.Verify(s => s.ExecuteCommand(SurroundWithFeature.ISERT_SNIPPET_COMMAND, null), Times.Exactly(string.IsNullOrEmpty(surroundWithLanguageName) ? 0 : 1));
_keyboardServiceMock.Verify(k => k.Type(Key.Enter), Times.Exactly(string.IsNullOrEmpty(surroundWithLanguageName) ? 1 : 2));
_keyboardServiceMock.Verify(k => k.Type(SurroundWithFeature.SNIPPET_REGION), Times.Once);
_surroundWithFormatterServiceMock.Verify(s => s.Format(It.IsAny<SurroundWithLanguageModel>()), Times.Never);
}

[Test]
Expand Down
45 changes: 45 additions & 0 deletions DPackRx.Tests/Features/SurroundWithModelTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using DPackRx.Features.SurroundWith;

using NUnit.Framework;

namespace DPackRx.Tests.Features
{
/// <summary>
/// SurroundWithModel tests.
/// </summary>
[TestFixture]
public class SurroundWithModelTests
{
#region Tests

[Test]
public void SurroundWithModel()
{
var model = new SurroundWithModel();

Assert.That(model.Models, Is.Not.Null);
Assert.That(model.Models.Count, Is.Zero);
}

[Test]
public void SurroundWithLanguageModel()
{
var model = new SurroundWithLanguageModel
{
Language = SurroundWithLanguage.CSharp,
Type = SurroundWithType.ForEach,
StartingCode = "test1",
EndingCode = "test2",
WordOffset = 123
};

Assert.That(model.Language, Is.EqualTo(SurroundWithLanguage.CSharp));
Assert.That(model.Type, Is.EqualTo(SurroundWithType.ForEach));
Assert.That(model.StartingCode, Is.EqualTo("test1"));
Assert.That(model.EndingCode, Is.EqualTo("test2"));
Assert.That(model.WordOffset, Is.EqualTo(123));
}

#endregion
}
}
73 changes: 73 additions & 0 deletions DPackRx.Tests/Language/LanguageSettingsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System.Collections.Generic;

using DPackRx.Language;
using DPackRx.Package;

using NUnit.Framework;

namespace DPackRx.Tests.Language
{
/// <summary>
/// LanguageSettings tests.
/// </summary>
[TestFixture]
public class LanguageSettingsTests
{
#region Tests

[TestCase(LanguageConsts.VS_CM_LANGUAGE_CSHARP, LanguageType.CSharp)]
[TestCase(LanguageConsts.VS_CM_LANGUAGE_VB, LanguageType.VB)]
[TestCase(LanguageConsts.VS_CM_LANGUAGE_VC, LanguageType.CPP)]
[TestCase(LanguageConsts.VS_LANGUAGE_JAVA_SCRIPT, LanguageType.JavaScript)]
[TestCase(LanguageConsts.VS_LANGUAGE_XML, LanguageType.Xml)]
[TestCase(LanguageConsts.VS_LANGUAGE_SOLUTION_ITEMS, LanguageType.SolutionItems)]
[TestCase(LanguageConsts.VS_LANGUAGE_SQL, LanguageType.Sql)]
[TestCase("bad", LanguageType.Unknown)]
public void GetLanguage(string projectLanguage, LanguageType languageType)
{
var language = new LanguageSettings(projectLanguage, "Test")
{
CheckDuplicateNames = true,
Comments = new Dictionary<string, bool> { { "test", true } },
DesignerFiles = LanguageDesignerFiles.FullySupported,
Extensions = new Dictionary<string, bool> { { ".txt", true } },
IgnoreCodeType = true,
Imports = LanguageImports.Supported,
ParentlessFullName = true,
ProjectGuid = "test",
SmartFormat = true,
SupportsCompileBuildAction = true,
SupportsGenerics = true,
SupportsStatistics = true,
SurroundWith = true,
WebLanguage = "test",
WebNames = new string[] { "test" },
XmlDocs = new string[] { "test" },
XmlDocSurround = true,
};

Assert.That(language.Language, Is.EqualTo(projectLanguage));
Assert.That(language.FriendlyName, Is.EqualTo("Test"));
Assert.That(language.Type, Is.EqualTo(languageType));
Assert.That(language.CheckDuplicateNames, Is.True);
Assert.That(language.Comments, Is.Not.Null.And.Count.EqualTo(1));
Assert.That(language.DesignerFiles, Is.EqualTo(LanguageDesignerFiles.FullySupported));
Assert.That(language.Extensions, Is.Not.Null.And.Count.EqualTo(1));
Assert.That(language.IgnoreCodeType, Is.True);
Assert.That(language.Imports, Is.EqualTo(LanguageImports.Supported));
Assert.That(language.ParentlessFullName, Is.True);
Assert.That(language.ProjectGuid, Is.EqualTo("test"));
Assert.That(language.SmartFormat, Is.True);
Assert.That(language.SupportsCompileBuildAction, Is.True);
Assert.That(language.SupportsGenerics, Is.True);
Assert.That(language.SupportsStatistics, Is.True);
Assert.That(language.SurroundWith, Is.True);
Assert.That(language.WebLanguage, Is.EqualTo("test"));
Assert.That(language.WebNames, Is.Not.Null.And.Length.EqualTo(1));
Assert.That(language.XmlDocs, Is.Not.Null.And.Length.EqualTo(1));
Assert.That(language.XmlDocSurround, Is.True);
}

#endregion
}
}
7 changes: 4 additions & 3 deletions DPackRx/DPackRx.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<Compile Include="Features\Miscellaneous\MouseWheelZoomListener.cs" />
<Compile Include="Features\SupportOptions\SupportOptionsFirstTimeUse.cs" />
<Compile Include="Features\SurroundWith\SurroundWithFeature.cs" />
<Compile Include="Helpers\KeyboardHelper.cs" />
<Compile Include="Features\SurroundWith\SurroundWithModel.cs" />
<Compile Include="Language\ILanguageRegistrationService.cs" />
<Compile Include="Language\LanguageRegistrationService.cs" />
<Compile Include="Options\IOptionsPersistenceService.cs" />
Expand All @@ -85,7 +85,8 @@
<Compile Include="Features\Bookmarks\IBookmarksService.cs" />
<Compile Include="Services\ICodeModelEvents.cs" />
<Compile Include="Options\IOptionsService.cs" />
<Compile Include="Services\IKeyboardService.cs" />
<Compile Include="Services\SurroundWithFormatterService.cs" />
<Compile Include="Services\ISurroundWithFormatterService.cs" />
<Compile Include="Services\ISharedServiceProvider.cs" />
<Compile Include="Services\IShellEventsService.cs" />
<Compile Include="Services\IShellCodeModelService.cs" />
Expand Down Expand Up @@ -144,7 +145,6 @@
<Compile Include="CodeModel\ISolutionProcessor.cs" />
<Compile Include="CodeModel\ProjectProcessor.cs" />
<Compile Include="Services\IWildcardMatch.cs" />
<Compile Include="Services\KeyboardService.cs" />
<Compile Include="Services\SearchToken.cs" />
<Compile Include="Services\SharedServiceProvider.cs" />
<Compile Include="Services\IImageService.cs" />
Expand Down Expand Up @@ -215,6 +215,7 @@
<Compile Include="UI\ViewModelBase.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Features\SurroundWith\SurroundWith.json" />
<None Include="source.extension.vsixmanifest">
<SubType>Designer</SubType>
</None>
Expand Down
Loading

0 comments on commit 863969e

Please sign in to comment.