|
1 | 1 | using System; |
| 2 | +using System.Collections.Generic; |
2 | 3 | using Elasticsearch.Net; |
| 4 | +using FluentAssertions; |
3 | 5 | using Nest; |
4 | 6 | using Tests.Framework; |
5 | 7 | using Tests.Framework.Integration; |
@@ -33,5 +35,130 @@ protected override LazyResponses ClientUsage() => Calls( |
33 | 35 | { |
34 | 36 | IgnoreUnavailable = true |
35 | 37 | }; |
| 38 | + |
| 39 | + protected override void ExpectResponse(IGetMappingResponse response) |
| 40 | + { |
| 41 | + response.IsValid.Should().BeTrue(); |
| 42 | + |
| 43 | + var visitor = new TestVisitor(); |
| 44 | + response.Accept(visitor); |
| 45 | + |
| 46 | + visitor.CountsShouldContainKeyAndCountBe("type", 2); |
| 47 | + visitor.CountsShouldContainKeyAndCountBe("object", 3); |
| 48 | + visitor.CountsShouldContainKeyAndCountBe("date", 5); |
| 49 | + visitor.CountsShouldContainKeyAndCountBe("string", 18); |
| 50 | + visitor.CountsShouldContainKeyAndCountBe("ip", 2); |
| 51 | + visitor.CountsShouldContainKeyAndCountBe("number", 3); |
| 52 | + visitor.CountsShouldContainKeyAndCountBe("geo_point", 3); |
| 53 | + visitor.CountsShouldContainKeyAndCountBe("completion", 3); |
| 54 | + visitor.CountsShouldContainKeyAndCountBe("nested", 2); |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + internal class TestVisitor : IMappingVisitor |
| 59 | + { |
| 60 | + public TestVisitor() |
| 61 | + { |
| 62 | + Counts = new Dictionary<string, int>(); |
| 63 | + } |
| 64 | + |
| 65 | + public int Depth { get; set; } |
| 66 | + |
| 67 | + public Dictionary<string, int> Counts { get; } |
| 68 | + |
| 69 | + private void Increment(string key) |
| 70 | + { |
| 71 | + if (!Counts.ContainsKey(key)) |
| 72 | + { |
| 73 | + Counts.Add(key, 1); |
| 74 | + } |
| 75 | + Counts[key] += 1; |
| 76 | + } |
| 77 | + |
| 78 | + public void CountsShouldContainKeyAndCountBe(string key, int count) |
| 79 | + { |
| 80 | + this.Counts.ContainsKey(key).Should().BeTrue(); |
| 81 | + this.Counts[key].Should().Be(count); |
| 82 | + } |
| 83 | + |
| 84 | + public void Visit(DateProperty mapping) |
| 85 | + { |
| 86 | + Increment("date"); |
| 87 | + } |
| 88 | + |
| 89 | + public void Visit(BinaryProperty mapping) |
| 90 | + { |
| 91 | + Increment("binary"); |
| 92 | + } |
| 93 | + |
| 94 | + public void Visit(NestedProperty mapping) |
| 95 | + { |
| 96 | + Increment("nested"); |
| 97 | + } |
| 98 | + |
| 99 | + public void Visit(GeoPointProperty mapping) |
| 100 | + { |
| 101 | + Increment("geo_point"); |
| 102 | + } |
| 103 | + |
| 104 | + public void Visit(AttachmentProperty mapping) |
| 105 | + { |
| 106 | + Increment("attachment"); |
| 107 | + } |
| 108 | + |
| 109 | + public void Visit(CompletionProperty mapping) |
| 110 | + { |
| 111 | + Increment("completion"); |
| 112 | + } |
| 113 | + |
| 114 | + public void Visit(TokenCountProperty mapping) |
| 115 | + { |
| 116 | + Increment("token_count"); |
| 117 | + } |
| 118 | + |
| 119 | + public void Visit(Murmur3HashProperty mapping) |
| 120 | + { |
| 121 | + Increment("murmur3"); |
| 122 | + } |
| 123 | + |
| 124 | + public void Visit(NumberProperty mapping) |
| 125 | + { |
| 126 | + Increment("number"); |
| 127 | + } |
| 128 | + |
| 129 | + public void Visit(GeoShapeProperty mapping) |
| 130 | + { |
| 131 | + Increment("geo_shape"); |
| 132 | + } |
| 133 | + |
| 134 | + public void Visit(IpProperty mapping) |
| 135 | + { |
| 136 | + Increment("ip"); |
| 137 | + } |
| 138 | + |
| 139 | + public void Visit(ObjectProperty mapping) |
| 140 | + { |
| 141 | + Increment("object"); |
| 142 | + } |
| 143 | + |
| 144 | + public void Visit(BooleanProperty mapping) |
| 145 | + { |
| 146 | + Increment("boolean"); |
| 147 | + } |
| 148 | + |
| 149 | + public void Visit(NumberType mapping) |
| 150 | + { |
| 151 | + throw new InvalidOperationException("NumberType should never be called"); |
| 152 | + } |
| 153 | + |
| 154 | + public void Visit(StringProperty mapping) |
| 155 | + { |
| 156 | + Increment("string"); |
| 157 | + } |
| 158 | + |
| 159 | + public void Visit(TypeMapping mapping) |
| 160 | + { |
| 161 | + Increment("type"); |
| 162 | + } |
36 | 163 | } |
37 | 164 | } |
0 commit comments