|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using Elasticsearch.Net; |
| 5 | +using FluentAssertions; |
| 6 | +using Nest; |
| 7 | +using Tests.Framework; |
| 8 | +using Tests.Framework.Integration; |
| 9 | +using Tests.Framework.MockData; |
| 10 | +using Xunit; |
| 11 | + |
| 12 | +namespace Tests.Document.Multiple.Bulk |
| 13 | +{ |
| 14 | + public class BulkInvalidVersionApiTests : ApiIntegrationTestBase<WritableCluster, IBulkResponse, IBulkRequest, BulkDescriptor, BulkRequest> |
| 15 | + { |
| 16 | + public BulkInvalidVersionApiTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage) { } |
| 17 | + protected override LazyResponses ClientUsage() => Calls( |
| 18 | + fluent: (client, f) => client.Bulk(f), |
| 19 | + fluentAsync: (client, f) => client.BulkAsync(f), |
| 20 | + request: (client, r) => client.Bulk(r), |
| 21 | + requestAsync: (client, r) => client.BulkAsync(r) |
| 22 | + ); |
| 23 | + |
| 24 | + protected override bool ExpectIsValid => false; |
| 25 | + protected override int ExpectStatusCode => 400; |
| 26 | + protected override HttpMethod HttpMethod => HttpMethod.POST; |
| 27 | + protected override string UrlPath => $"/{CallIsolatedValue}/_bulk"; |
| 28 | + |
| 29 | + protected override bool SupportsDeserialization => false; |
| 30 | + |
| 31 | + protected override object ExpectJson { get; } = new object[] |
| 32 | + { |
| 33 | + new Dictionary<string, object>{ { "index", new { _type="project", _id = Project.Instance.Name } } }, |
| 34 | + Project.InstanceAnonymous, |
| 35 | + new Dictionary<string, object>{ { "index", new { _type="project", _id = Project.Instance.Name, _version = 0 } } }, |
| 36 | + Project.InstanceAnonymous, |
| 37 | + }; |
| 38 | + |
| 39 | + protected override void ExpectResponse(IBulkResponse response) |
| 40 | + { |
| 41 | + response.IsValid.Should().BeFalse(); |
| 42 | + response.ServerError.Should().NotBeNull(); |
| 43 | + response.ServerError.Status.Should().Be(400); |
| 44 | + response.ServerError.Error.Type.Should().Be("action_request_validation_exception"); |
| 45 | + response.ServerError.Error.Reason.Should().EndWith("illegal version value [0] for version type [INTERNAL];"); |
| 46 | + } |
| 47 | + |
| 48 | + protected override Func<BulkDescriptor, IBulkRequest> Fluent => d => d |
| 49 | + .Index(CallIsolatedValue) |
| 50 | + .Index<Project>(i => i.Document(Project.Instance)) |
| 51 | + .Index<Project>(i => i.Version(0).Document(Project.Instance)); |
| 52 | + |
| 53 | + |
| 54 | + protected override BulkRequest Initializer => new BulkRequest(CallIsolatedValue) |
| 55 | + { |
| 56 | + Operations = new List<IBulkOperation> |
| 57 | + { |
| 58 | + new BulkIndexOperation<Project>(Project.Instance), |
| 59 | + new BulkIndexOperation<Project>(Project.Instance) { Version = 0 } |
| 60 | + } |
| 61 | + }; |
| 62 | + } |
| 63 | +} |
0 commit comments