|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using Elastic.Xunit.XunitPlumbing; |
| 4 | +using FluentAssertions; |
| 5 | +using Nest; |
| 6 | +using Tests.ClientConcepts.HighLevel.CovariantHits; |
| 7 | +using Tests.Core.Extensions; |
| 8 | +using Tests.Core.ManagedElasticsearch.Clusters; |
| 9 | +using Tests.Domain; |
| 10 | +using Tests.Framework.EndpointTests.TestState; |
| 11 | +using Tests.Mapping.Types; |
| 12 | + |
| 13 | +namespace Tests.Mapping.Meta |
| 14 | +{ |
| 15 | + [SkipVersion("<7.6.0", "Meta added in Elasticsearch 7.6.0")] |
| 16 | + public class MetaMappingApiTests |
| 17 | + : PropertyTestsBase |
| 18 | + { |
| 19 | + public MetaMappingApiTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage) { } |
| 20 | + |
| 21 | + protected override Func<PropertiesDescriptor<Project>, IPromise<IProperties>> FluentProperties => p => p |
| 22 | + .Number(n => n |
| 23 | + .Name(nn => nn.Rank) |
| 24 | + .Type(NumberType.Integer) |
| 25 | + .Meta(m => m |
| 26 | + .Add("unit", "popularity") |
| 27 | + ) |
| 28 | + ); |
| 29 | + protected override IProperties InitializerProperties => new Properties<Project> |
| 30 | + { |
| 31 | + { n => n.Rank, new NumberProperty(NumberType.Integer) |
| 32 | + { |
| 33 | + Meta = new Dictionary<string, string> |
| 34 | + { |
| 35 | + { "unit", "popularity" } |
| 36 | + } |
| 37 | + } |
| 38 | + } |
| 39 | + }; |
| 40 | + |
| 41 | + protected override void ExpectResponse(PutMappingResponse response) |
| 42 | + { |
| 43 | + base.ExpectResponse(response); |
| 44 | + |
| 45 | + // check the meta shows up in get mapping API |
| 46 | + var getMappingResponse = Client.Indices.GetMapping<Project>(m => m.Index(CallIsolatedValue)); |
| 47 | + getMappingResponse.IsValid.Should().BeTrue(); |
| 48 | + var mappingMeta = getMappingResponse.Indices[CallIsolatedValue].Mappings.Properties["rank"].Meta; |
| 49 | + mappingMeta.Should().NotBeNull().And.ContainKey("unit"); |
| 50 | + mappingMeta["unit"].Should().Be("popularity"); |
| 51 | + |
| 52 | + // check the meta shows up in field capabilities API |
| 53 | + var fieldCapsResponse = Client.FieldCapabilities(CallIsolatedValue, f => f |
| 54 | + .Fields<Project>(ff => ff.Rank) |
| 55 | + ); |
| 56 | + fieldCapsResponse.IsValid.Should().BeTrue(); |
| 57 | + var meta = fieldCapsResponse.Fields["rank"].Integer.Meta; |
| 58 | + meta.Should().NotBeNull().And.ContainKey("unit"); |
| 59 | + meta["unit"].Should().BeEquivalentTo("popularity"); |
| 60 | + } |
| 61 | + } |
| 62 | +} |
0 commit comments