Skip to content

Commit

Permalink
added CodeActionsV2Facts test for loading an external refactoring (co…
Browse files Browse the repository at this point in the history
…de action)
  • Loading branch information
filipw committed Jun 7, 2017
1 parent 92d6bdc commit 4add01b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
30 changes: 28 additions & 2 deletions tests/OmniSharp.Roslyn.CSharp.Tests/CodeActionsV2Facts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,32 @@ public void Whatever()
Assert.Contains("using System;", refactorings);
}

[Fact]
public async Task Can_get_code_actions_from_external_source()
{
const string code =
@"
using System.Threading.Tasks;
public class Class1
{
public async Task Whatever()
{
awa[||]it FooAsync();
}
public Task FooAsync() => return Task.FromResult(0);
}";

var configuration = new Dictionary<string, string>
{
{ "RoslynExtensionsOptions:LocationPaths:0", TestAssets.Instance.TestBinariesFolder }
};
var refactorings = await FindRefactoringsAsync(code, configuration);

Assert.NotEmpty(refactorings);
Assert.Contains("Add ConfigureAwait(false)", refactorings.Select(x => x.Name));
}

[Fact]
public async Task Can_remove_unnecessary_usings()
{
Expand Down Expand Up @@ -128,11 +154,11 @@ private async Task<IEnumerable<string>> FindRefactoringNamesAsync(string code)
return codeActions.Select(a => a.Name);
}

private async Task<IEnumerable<OmniSharpCodeAction>> FindRefactoringsAsync(string code)
private async Task<IEnumerable<OmniSharpCodeAction>> FindRefactoringsAsync(string code, IDictionary<string, string> configurationData = null)
{
var testFile = new TestFile(BufferPath, code);

using (var host = CreateOmniSharpHost(testFile))
using (var host = CreateOmniSharpHost(new[] { testFile }, configurationData))
{
var requestHandler = host.GetRequestHandler<GetCodeActionsService>(OmniSharpEndpoints.V2.GetCodeActions);

Expand Down
13 changes: 7 additions & 6 deletions tests/TestUtility/AbstractTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ protected OmniSharpTestHost CreateEmptyOmniSharpHost()
return host;
}

protected OmniSharpTestHost CreateOmniSharpHost(string path = null, IEnumerable<KeyValuePair<string, string>> configurationData = null, bool useLegacyDotNetCli = false)
{
return OmniSharpTestHost.Create(path, this.TestOutput, configurationData, useLegacyDotNetCli);
}
protected OmniSharpTestHost CreateOmniSharpHost(string path = null, IEnumerable<KeyValuePair<string, string>> configurationData = null, bool useLegacyDotNetCli = false) =>
OmniSharpTestHost.Create(path, this.TestOutput, configurationData, useLegacyDotNetCli);

protected OmniSharpTestHost CreateOmniSharpHost(params TestFile[] testFiles) =>
CreateOmniSharpHost(testFiles, null);

protected OmniSharpTestHost CreateOmniSharpHost(params TestFile[] testFiles)
protected OmniSharpTestHost CreateOmniSharpHost(TestFile[] testFiles, IEnumerable<KeyValuePair<string, string>> configurationData)
{
var host = OmniSharpTestHost.Create(path: null, testOutput: this.TestOutput, configurationData: null);
var host = OmniSharpTestHost.Create(path: null, testOutput: this.TestOutput, configurationData: configurationData);

if (testFiles.Length > 0)
{
Expand Down
2 changes: 2 additions & 0 deletions tests/TestUtility/OmniSharpTestHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public static OmniSharpTestHost Create(string path = null, ITestOutputHelper tes
var serviceProvider = new TestServiceProvider(environment, loggerFactory, sharedTextWriter);

var omnisharpOptions = new OmniSharpOptions();
ConfigurationBinder.Bind(configuration, omnisharpOptions);

var compositionHost = Startup.CreateCompositionHost(
serviceProvider,
options: omnisharpOptions,
Expand Down

0 comments on commit 4add01b

Please sign in to comment.