Skip to content

Commit 1ad7c09

Browse files
committed
Add and amend tests
1 parent 45424f9 commit 1ad7c09

3 files changed

+57
-34
lines changed

Diff for: tests/Tests/IndexManagement/CreateIndexSerializationTests.cs

+42
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
}

Diff for: tests/Tests/IndexManagement/GetIndexSerializationTests.cs

+1-34
Original file line numberDiff line numberDiff line change
@@ -7058,7 +7058,7 @@ public void GetIndexResponse_DeserializedCorrectly()
70587058
}
70597059

70607060
[U]
7061-
public void GetIndexResponse_DeserializedCorrectly_WhenDynamicTemplateArrayIsPresentInResponse()
7061+
public void GetIndexResponse_DeserializedCorrectly_WhenDynamicTemplatesArePresentInResponse()
70627062
{
70637063
const string json = @"{
70647064
""catalog-data-2023.01.31"": {
@@ -7091,39 +7091,6 @@ public void GetIndexResponse_DeserializedCorrectly_WhenDynamicTemplateArrayIsPre
70917091
VerifyGetIndexResponseDynamicTemplates(response);
70927092
}
70937093

7094-
[U]
7095-
public void GetIndexResponse_DeserializedCorrectly_WhenSingleDynamicTemplateIsPresentInResponse()
7096-
{
7097-
const string json = @"{
7098-
""catalog-data-2023.01.31"": {
7099-
""aliases"": {
7100-
},
7101-
""mappings"": {
7102-
""dynamic_templates"":
7103-
{
7104-
""strings_as_keyword"": {
7105-
""match_mapping_type"": ""string"",
7106-
""mapping"": {
7107-
""ignore_above"": 1024,
7108-
""type"": ""keyword""
7109-
}
7110-
}
7111-
},
7112-
""properties"": {
7113-
""@timestamp"": {
7114-
""type"": ""date""
7115-
}
7116-
}
7117-
},
7118-
""settings"": {
7119-
}
7120-
}
7121-
}";
7122-
7123-
var response = DeserializeJsonString<GetIndexResponse>(json);
7124-
VerifyGetIndexResponseDynamicTemplates(response);
7125-
}
7126-
71277094
private static void VerifyGetIndexResponseDynamicTemplates(GetIndexResponse response)
71287095
{
71297096
response.Indices.TryGetValue("catalog-data-2023.01.31", out var indexState).Should().BeTrue();
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)