Skip to content

Commit 4295786

Browse files
committed
Add test
1 parent 45424f9 commit 4295786

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

tests/Tests/IndexManagement/CreateIndexSerializationTests.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using Elastic.Clients.Elasticsearch.Analysis;
66
using Elastic.Clients.Elasticsearch.IndexManagement;
7+
using Elastic.Clients.Elasticsearch.Mapping;
78
using Elastic.Clients.Elasticsearch.QueryDsl;
89
using System.Collections.Generic;
910
using System.Threading.Tasks;
@@ -83,4 +84,45 @@ public async Task CreateIndexWithAnalysisSettings_SerializesCorrectly()
8384
var objectJson = await SerializeAndGetJsonStringAsync(createRequest);
8485
objectJson.Should().Be(json);
8586
}
87+
88+
[U]
89+
public async Task CreateIndexWithDynamicTemplates_SerializesCorrectly()
90+
{
91+
var myTemplate = new DynamicTemplate
92+
{
93+
PathMatch = "testPathMatch",
94+
Mapping = new KeywordProperty()
95+
};
96+
97+
var descriptor = new CreateIndexRequestDescriptor("test")
98+
.Mappings(m => m
99+
.DynamicTemplates(new[]
100+
{
101+
new Dictionary<string, DynamicTemplate>
102+
{
103+
{ "testTemplateName", myTemplate }
104+
}
105+
}));
106+
107+
var json = await SerializeAndGetJsonStringAsync(descriptor);
108+
109+
await Verifier.VerifyJson(json);
110+
111+
var createRequest = new CreateIndexRequest("test")
112+
{
113+
Mappings = new TypeMapping
114+
{
115+
DynamicTemplates = new[]
116+
{
117+
new Dictionary<string, DynamicTemplate>
118+
{
119+
{ "testTemplateName", myTemplate }
120+
}
121+
}
122+
}
123+
};
124+
125+
var objectJson = await SerializeAndGetJsonStringAsync(createRequest);
126+
objectJson.Should().Be(json);
127+
}
86128
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
mappings: {
3+
dynamic_templates: [
4+
{
5+
testTemplateName: {
6+
mapping: {
7+
type: keyword
8+
},
9+
path_match: testPathMatch
10+
}
11+
}
12+
]
13+
}
14+
}

0 commit comments

Comments
 (0)