From 80e3dc32f7f7f4909b00a723a08669b1b22848f1 Mon Sep 17 00:00:00 2001 From: Pierre-Yves FARE Date: Sun, 18 Apr 2021 15:17:17 +0100 Subject: [PATCH] Fix ShardKeys property by using collection type instead of string. fix #313 --- .../CollectionApi/CollectionApiClientTest.cs | 22 +++++++++++++++++-- .../Models/GetCollectionPropertiesResponse.cs | 5 +++-- .../Models/PostCollectionBody.cs | 6 +++-- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/arangodb-net-standard.Test/CollectionApi/CollectionApiClientTest.cs b/arangodb-net-standard.Test/CollectionApi/CollectionApiClientTest.cs index 7addfecf..c54770da 100644 --- a/arangodb-net-standard.Test/CollectionApi/CollectionApiClientTest.cs +++ b/arangodb-net-standard.Test/CollectionApi/CollectionApiClientTest.cs @@ -112,17 +112,35 @@ public async Task PostCollectionAsync_ShouldSucceed_WhenEdgeCollection() var response = await _collectionApi.PostCollectionAsync( new PostCollectionBody { - Name = "MyEdgeCollection", + Name = nameof(PostCollectionAsync_ShouldSucceed_WhenEdgeCollection), Type = CollectionType.Edge }); Assert.False(response.Error); Assert.NotNull(response.Id); - Assert.Equal("MyEdgeCollection", response.Name); + Assert.Equal( + nameof(PostCollectionAsync_ShouldSucceed_WhenEdgeCollection), + response.Name); Assert.Equal("traditional", response.KeyOptions.Type); Assert.Equal(CollectionType.Edge, response.Type); // 2 is document collection, 3 is edge collection } + [Fact] + public async Task PostCollectionAsync_ShouldSucceed_WhenSharding() + { + var response = await _collectionApi.PostCollectionAsync( + new PostCollectionBody + { + Name = nameof(PostCollectionAsync_ShouldSucceed_WhenSharding), + NumberOfShards = 4, + ShardKeys = new string[] { "country" }, + ReplicationFactor = 2 + }); + + Assert.False(response.Error); + Assert.NotNull(response.Id); + } + [Fact] public async Task PostCollectionAsync_ShouldUseQueryParameter() { diff --git a/arangodb-net-standard/CollectionApi/Models/GetCollectionPropertiesResponse.cs b/arangodb-net-standard/CollectionApi/Models/GetCollectionPropertiesResponse.cs index 8cdcabdb..a91b8602 100644 --- a/arangodb-net-standard/CollectionApi/Models/GetCollectionPropertiesResponse.cs +++ b/arangodb-net-standard/CollectionApi/Models/GetCollectionPropertiesResponse.cs @@ -1,4 +1,5 @@ -using System.Net; +using System.Collections.Generic; +using System.Net; namespace ArangoDBNetStandard.CollectionApi.Models { @@ -47,7 +48,7 @@ public class GetCollectionPropertiesResponse /// which document attributes are used to determine the target shard for documents. /// This option is meaningless in a single server setup. /// - public string ShardKeys { get; set; } + public IEnumerable ShardKeys { get; set; } /// /// In a cluster, this attribute determines how many copies diff --git a/arangodb-net-standard/CollectionApi/Models/PostCollectionBody.cs b/arangodb-net-standard/CollectionApi/Models/PostCollectionBody.cs index e123c3a7..daf20d93 100644 --- a/arangodb-net-standard/CollectionApi/Models/PostCollectionBody.cs +++ b/arangodb-net-standard/CollectionApi/Models/PostCollectionBody.cs @@ -1,4 +1,6 @@ -namespace ArangoDBNetStandard.CollectionApi.Models +using System.Collections.Generic; + +namespace ArangoDBNetStandard.CollectionApi.Models { public class PostCollectionBody { @@ -93,7 +95,7 @@ public class PostCollectionBody /// Values of shard key attributes cannot be changed once set. /// This option is meaningless in a single server setup. /// - public string ShardKeys { get; set; } + public IEnumerable ShardKeys { get; set; } /// /// This attribute specifies the name of the sharding strategy to use for the collection.