-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
78a7880
commit 4d8c203
Showing
10 changed files
with
174 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,35 @@ public ElasticsearchService({|#1:IElasticClient|} client) | |
await VerifyCS.VerifyAnalyzerAsync(test, expected1, expected2); | ||
} | ||
|
||
[TestMethod] | ||
public async Task TestNestUsageAsClass() | ||
{ | ||
var test = | ||
@" | ||
using Nest; | ||
public class ElasticsearchService | ||
{ | ||
private readonly {|#0:ElasticClient|} _client; | ||
public ElasticsearchService({|#1:ElasticClient|} client) | ||
{ | ||
_client = client; | ||
} | ||
}"; | ||
|
||
var expected1 = VerifyCS | ||
.Diagnostic("ELS001") | ||
.WithLocation(0) | ||
.WithArguments("ElasticClient"); | ||
|
||
var expected2 = VerifyCS | ||
.Diagnostic("ELS001") | ||
.WithLocation(1) | ||
.WithArguments("ElasticClient"); | ||
|
||
await VerifyCS.VerifyAnalyzerAsync(test, expected1, expected2); | ||
} | ||
|
||
//Diagnostic and CodeFix both triggered and checked for | ||
[TestMethod] | ||
public async Task TestCodeFix() | ||
|
@@ -114,6 +143,52 @@ public ElasticsearchService( ElasticsearchClient client) | |
|
||
await VerifyCS.VerifyCodeFixAsync(test, [expected1, expected2], fixtest); | ||
} | ||
|
||
[TestMethod] | ||
public async Task TestCodeFixWithSettings() | ||
{ | ||
var test = """ | ||
using Nest; | ||
public class ElasticsearchService | ||
{ | ||
private readonly {|#0:ElasticClient|} _client; | ||
public ElasticsearchService() | ||
{ | ||
var settings = new ConnectionSettings(new Uri("https://elastic:[email protected]:9200/")); | ||
_client = new {|#1:ElasticClient|}(settings); | ||
} | ||
} | ||
"""; | ||
|
||
var fixtest = """ | ||
using Elastic.Clients.Elasticsearch; | ||
public class ElasticsearchService | ||
{ | ||
private readonly ElasticsearchClient _client; | ||
public ElasticsearchService() | ||
{ | ||
var settings = new ElasticsearchClientSettings(new Uri("https://elastic:[email protected]:9200/")); | ||
_client = new ElasticsearchClient(settings); | ||
} | ||
} | ||
"""; | ||
|
||
var expected1 = VerifyCS | ||
.Diagnostic("ELS001") | ||
.WithLocation(0) | ||
.WithArguments("ElasticClient"); | ||
|
||
var expected2 = VerifyCS | ||
.Diagnostic("ELS001") | ||
.WithLocation(1) | ||
.WithArguments("ElasticClient"); | ||
|
||
await VerifyCS.VerifyCodeFixAsync(test, [expected1, expected2], fixtest); | ||
} | ||
} | ||
|
||
public static class VerifyCS | ||
|
@@ -149,7 +224,7 @@ string fixedSource | |
test.TestState.AdditionalReferences.Add(s_nestReference); | ||
test.TestState.AdditionalReferences.Add(s_elasticReference); | ||
test.ExpectedDiagnostics.AddRange(expected); | ||
// we need this becaues of | ||
// we need this becaues of | ||
// error CS1705: Assembly 'Elastic.Clients.Elasticsearch' with identity 'Elastic.Clients.Elasticsearch, Version=8.0.0.0, Culture=neutral, PublicKeyToken=96c599bbe3e70f5d' uses 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' which has a higher version than referenced assembly 'System.Runtime' with identity 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' | ||
test.CompilerDiagnostics = CompilerDiagnostics.None; | ||
return test.RunAsync(); | ||
|
2 changes: 1 addition & 1 deletion
2
analyzer/Nall.NEST.MigtarionAnalyzer.Vsix/source.extension.vsixmanifest
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,22 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.0.31903.59 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Playground", "Playground.csproj", "{CF7AE166-9099-4DCE-995B-85842C623790}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{CF7AE166-9099-4DCE-995B-85842C623790}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{CF7AE166-9099-4DCE-995B-85842C623790}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{CF7AE166-9099-4DCE-995B-85842C623790}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{CF7AE166-9099-4DCE-995B-85842C623790}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
EndGlobal |
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 |
---|---|---|
@@ -1,15 +1,35 @@ | ||
using System.Text.Json; | ||
#pragma warning disable CS8321 // Local function is declared but never used | ||
|
||
using System.Text.Json; | ||
using Elastic.Clients.Elasticsearch; | ||
using Elastic.Transport; | ||
using Nest; | ||
|
||
// ElasticClient -> ElasticsearchClient | ||
// IElasticClient -> ElasticsearchClient | ||
// ConnectionSettings -> ElasticsearchClientSettings | ||
|
||
var settings = new ConnectionSettings(new Uri("https://elastic:[email protected]:9200/")) | ||
.DisableDirectStreaming() | ||
.ServerCertificateValidationCallback(CertificateValidations.AllowAll); | ||
|
||
var client = new ElasticClient(settings); | ||
IElasticClient client = new ElasticClient(settings); | ||
|
||
var nodeInfo = await client.Nodes.InfoAsync(); | ||
|
||
Console.WriteLine( | ||
JsonSerializer.Serialize(nodeInfo, new JsonSerializerOptions { WriteIndented = true }) | ||
); | ||
|
||
static IElasticClient Create1(ConnectionSettings settings) | ||
{ | ||
return new ElasticClient(settings); | ||
} | ||
static ElasticClient Create2(ConnectionSettings settings) | ||
{ | ||
return new ElasticClient(settings); | ||
} | ||
static ElasticsearchClient Create3(ElasticsearchClientSettings settings) | ||
{ | ||
return new ElasticsearchClient(settings); | ||
} |
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