add: 添加项目
parent
33550302ba
commit
297ee21dd8
@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ElasticSearchStudy.Core\ElasticSearchStudy.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,29 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
|
||||
<PackageReference Include="xunit" Version="2.4.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="3.1.2">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ElasticSearchStudy.Core\ElasticSearchStudy.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,97 @@
|
||||
using Elastic.Transport;
|
||||
using Elastic.Transport.Diagnostics;
|
||||
using Elastic.Transport.Extensions;
|
||||
using Elastic.Transport.Products;
|
||||
|
||||
using Elastic.Clients.Elasticsearch;
|
||||
using Xunit.Abstractions;
|
||||
using ElasticSearchStudy.Core;
|
||||
|
||||
namespace ElasticSearchStudy.UnitTest
|
||||
{
|
||||
public class UseElasticSearchTest
|
||||
{
|
||||
private ITestOutputHelper _output;
|
||||
|
||||
public UseElasticSearchTest(ITestOutputHelper outputHelper)
|
||||
{
|
||||
_output = outputHelper;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Test()
|
||||
{
|
||||
var elasticSetting = new ElasticsearchClientSettings(new Uri("https://localhost:9200"))
|
||||
.CertificateFingerprint("F8:B0:ED:80:2C:1C:6C:76:6E:CC:21:3A:CD:91:C3:C8:C7:77:D4:41:F4:71:50:FB:E7:0E:66:0D:71:8C:F3:1A")
|
||||
.Authentication(new BasicAuthentication("elastic", "3JI3QjRtjW8-Tl1q=mVx"));
|
||||
|
||||
ElasticsearchClient client = new ElasticsearchClient(elasticSetting);
|
||||
|
||||
var pingResponse = client.Ping();
|
||||
|
||||
if (pingResponse.IsSuccess())
|
||||
{
|
||||
_output.WriteLine($"ÇëÇó³É¹¦,{pingResponse.DebugInformation}");
|
||||
}
|
||||
else
|
||||
{
|
||||
_output.WriteLine("ÇëÇóʧ°Ü");
|
||||
}
|
||||
|
||||
Assert.True(pingResponse.IsSuccess());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateIndex_Test()
|
||||
{
|
||||
var elasticSetting = new ElasticsearchClientSettings(new Uri("https://localhost:9200"))
|
||||
.CertificateFingerprint("F8:B0:ED:80:2C:1C:6C:76:6E:CC:21:3A:CD:91:C3:C8:C7:77:D4:41:F4:71:50:FB:E7:0E:66:0D:71:8C:F3:1A")
|
||||
.Authentication(new BasicAuthentication("elastic", "3JI3QjRtjW8-Tl1q=mVx"))
|
||||
;
|
||||
|
||||
ElasticsearchClient client = new ElasticsearchClient(elasticSetting);
|
||||
|
||||
|
||||
var tweet = new Tweet
|
||||
{
|
||||
Id = 1,
|
||||
User = "stevejgordon",
|
||||
PostDate = DateTime.Now,
|
||||
Message = "Trying out the client, so far so good?"
|
||||
};
|
||||
|
||||
var response = client.Index(tweet, "tweet-index");
|
||||
|
||||
if (response.IsValidResponse)
|
||||
{
|
||||
Console.WriteLine($"Index document with ID {response.Id} succeeded.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetDoc_Test()
|
||||
{
|
||||
var elasticSetting = new ElasticsearchClientSettings(new Uri("https://localhost:9200"))
|
||||
.CertificateFingerprint("F8:B0:ED:80:2C:1C:6C:76:6E:CC:21:3A:CD:91:C3:C8:C7:77:D4:41:F4:71:50:FB:E7:0E:66:0D:71:8C:F3:1A")
|
||||
.Authentication(new BasicAuthentication("elastic", "3JI3QjRtjW8-Tl1q=mVx"));
|
||||
|
||||
ElasticsearchClient client = new ElasticsearchClient(elasticSetting);
|
||||
|
||||
var tweet = new Tweet
|
||||
{
|
||||
Id = 2,
|
||||
User = "stevejgordon",
|
||||
PostDate = new DateTime(2009, 11, 15),
|
||||
Message = "Trying out the client, so far so good?"
|
||||
};
|
||||
|
||||
var response = client.Create<Tweet>(tweet, "my-tweet-index",3);
|
||||
|
||||
if (response.IsValidResponse)
|
||||
{
|
||||
_output.WriteLine($"Index document with ID {response.Id} succeeded.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
global using Xunit;
|
Loading…
Reference in New Issue