-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrated slimmed down Surround With feature.
- Loading branch information
Sergey M
committed
Jan 29, 2020
1 parent
d74d968
commit 5a31f28
Showing
21 changed files
with
740 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,197 @@ | ||
using System; | ||
using System.Windows.Input; | ||
|
||
using Moq; | ||
using NUnit.Framework; | ||
|
||
using DPackRx.CodeModel; | ||
using DPackRx.Features; | ||
using DPackRx.Features.SurroundWith; | ||
using DPackRx.Language; | ||
using DPackRx.Options; | ||
using DPackRx.Package; | ||
using DPackRx.Services; | ||
|
||
namespace DPackRx.Tests.Features | ||
{ | ||
/// <summary> | ||
/// SurroundWithFeature tests. | ||
/// </summary> | ||
[TestFixture] | ||
public class SurroundWithFeatureTests | ||
{ | ||
#region Fields | ||
|
||
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; | ||
|
||
#endregion | ||
|
||
#region Tests Setup | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
_serviceProviderMock = new Mock<IServiceProvider>(); | ||
|
||
_logMock = new Mock<ILog>(); | ||
_logMock.Setup(l => l.LogMessage(It.IsAny<string>(), It.IsAny<string>())).Verifiable(); | ||
|
||
_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(); | ||
|
||
var webProject = false; | ||
_fileTypeResolverMock = new Mock<IFileTypeResolver>(); | ||
_fileTypeResolverMock.Setup(f => f.GetCurrentLanguage(It.IsAny<object>(), out webProject)) | ||
.Returns(new LanguageSettings("C#", "C#") { Type = LanguageType.CSharp, SurroundWith = true }).Verifiable(); | ||
|
||
_keyboardServiceMock = new Mock<IKeyboardService>(); | ||
_keyboardServiceMock.Setup(k => k.Type(It.IsAny<Key>())).Verifiable(); | ||
_keyboardServiceMock.Setup(k => k.Type(It.IsAny<string>())).Verifiable(); | ||
} | ||
|
||
[TearDown] | ||
public void TearDown() | ||
{ | ||
_serviceProviderMock = null; | ||
_logMock = null; | ||
_optionsServiceMock = null; | ||
_shellHelperServiceMock = null; | ||
_shellSelectionServiceMock = null; | ||
_fileTypeResolverMock = null; | ||
_keyboardServiceMock = null; | ||
} | ||
|
||
#endregion | ||
|
||
#region Private Methods | ||
|
||
/// <summary> | ||
/// Returns test feature instance. | ||
/// </summary> | ||
private IFeature GetFeature() | ||
{ | ||
return new SurroundWithFeature(_serviceProviderMock.Object, _logMock.Object, _optionsServiceMock.Object, | ||
_shellHelperServiceMock.Object, _shellSelectionServiceMock.Object, _fileTypeResolverMock.Object, | ||
_keyboardServiceMock.Object); | ||
} | ||
|
||
#endregion | ||
|
||
#region Tests | ||
|
||
[Test] | ||
public void GetCommandIds() | ||
{ | ||
var feature = GetFeature(); | ||
|
||
var commands = feature.GetCommandIds(); | ||
|
||
Assert.That(commands, Is.Not.Null); | ||
Assert.That(commands.Count, Is.EqualTo(5)); | ||
Assert.That(commands, Contains.Item(CommandIDs.SW_TRY_CATCH)); | ||
Assert.That(commands, Contains.Item(CommandIDs.SW_TRY_FINALLY)); | ||
Assert.That(commands, Contains.Item(CommandIDs.SW_FOR)); | ||
Assert.That(commands, Contains.Item(CommandIDs.SW_FOR_EACH)); | ||
Assert.That(commands, Contains.Item(CommandIDs.SW_REGION)); | ||
} | ||
|
||
[TestCase(CommandIDs.SW_TRY_CATCH, true)] | ||
[TestCase(CommandIDs.SW_TRY_FINALLY, true)] | ||
[TestCase(CommandIDs.SW_FOR, true)] | ||
[TestCase(CommandIDs.SW_FOR_EACH, true)] | ||
[TestCase(CommandIDs.SW_REGION, true)] | ||
[TestCase(0, false)] | ||
public void IsValidContext(int commandId, bool expectedResult) | ||
{ | ||
var feature = GetFeature(); | ||
|
||
var result = feature.IsValidContext(commandId); | ||
|
||
Assert.That(result, Is.EqualTo(expectedResult)); | ||
if (expectedResult) | ||
_shellSelectionServiceMock.Verify(s => s.IsContextActive(It.IsAny<ContextType>()), Times.AtLeast(2)); | ||
else | ||
_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) | ||
{ | ||
var feature = GetFeature(); | ||
var webProject = false; | ||
|
||
var result = feature.Execute(commandId); | ||
|
||
Assert.That(result, Is.True); | ||
_shellSelectionServiceMock.Verify(s => s.GetActiveProject()); | ||
_fileTypeResolverMock.Verify(f => f.GetCurrentLanguage(It.IsAny<object>(), out webProject)); | ||
_shellHelperServiceMock.Verify(s => s.ExecuteCommand(SurroundWithFeature.SURROUND_WITH_COMMAND, null)); | ||
_keyboardServiceMock.Verify(k => k.Type(command)); | ||
_keyboardServiceMock.Verify(k => k.Type(Key.Enter)); | ||
} | ||
|
||
[Test] | ||
public void Execute_InvalidCommand() | ||
{ | ||
var feature = GetFeature(); | ||
|
||
var result = feature.Execute(0); | ||
|
||
Assert.That(result, Is.False); | ||
} | ||
|
||
[Test] | ||
public void Execute_UnknownLanguage() | ||
{ | ||
var feature = GetFeature(); | ||
var webProject = false; | ||
_fileTypeResolverMock.Setup(f => f.GetCurrentLanguage(It.IsAny<object>(), out webProject)) | ||
.Returns(LanguageSettings.UnknownLanguage).Verifiable(); | ||
|
||
var result = feature.Execute(CommandIDs.SW_REGION); | ||
|
||
Assert.That(result, Is.True); | ||
_shellSelectionServiceMock.Verify(s => s.GetActiveProject()); | ||
_fileTypeResolverMock.Verify(f => f.GetCurrentLanguage(It.IsAny<object>(), out webProject)); | ||
_shellHelperServiceMock.Verify(s => s.ExecuteCommand(SurroundWithFeature.SURROUND_WITH_COMMAND, null), Times.Never); | ||
_keyboardServiceMock.Verify(k => k.Type(It.IsAny<string>()), Times.Never); | ||
_keyboardServiceMock.Verify(k => k.Type(Key.Enter), Times.Never); | ||
} | ||
|
||
[Test] | ||
public void Execute_UnsupportedLanguage() | ||
{ | ||
var feature = GetFeature(); | ||
var webProject = false; | ||
_fileTypeResolverMock.Setup(f => f.GetCurrentLanguage(It.IsAny<object>(), out webProject)) | ||
.Returns(new LanguageSettings("C#", "C#") { Type = LanguageType.CSharp, SurroundWith = false }).Verifiable(); | ||
|
||
var result = feature.Execute(CommandIDs.SW_REGION); | ||
|
||
Assert.That(result, Is.True); | ||
_shellSelectionServiceMock.Verify(s => s.GetActiveProject()); | ||
_fileTypeResolverMock.Verify(f => f.GetCurrentLanguage(It.IsAny<object>(), out webProject)); | ||
_shellHelperServiceMock.Verify(s => s.ExecuteCommand(SurroundWithFeature.SURROUND_WITH_COMMAND, null), Times.Never); | ||
_keyboardServiceMock.Verify(k => k.Type(It.IsAny<string>()), Times.Never); | ||
_keyboardServiceMock.Verify(k => k.Type(Key.Enter), Times.Never); | ||
} | ||
|
||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.