diff --git a/arangodb-net-standard.Test/DocumentApi/DocumentApiClientTest.cs b/arangodb-net-standard.Test/DocumentApi/DocumentApiClientTest.cs index 276d190d..5bf344cf 100644 --- a/arangodb-net-standard.Test/DocumentApi/DocumentApiClientTest.cs +++ b/arangodb-net-standard.Test/DocumentApi/DocumentApiClientTest.cs @@ -430,6 +430,26 @@ public async Task PostDocument_ShouldSucceed_WhenNewDocIsReturned() Assert.Equal(123, (int)response.New.test); } + [Fact] + public async Task PostDocument_ShouldSucceed_WhenNewDocIsReturnedWithDifferentType() + { + var doc = new PostDocumentMockModelNew + { + Message = "Hello" + }; + var response = await _docClient.PostDocumentAsync( + _testCollection, + doc, + new PostDocumentsQuery + { + ReturnNew = true + }); + Assert.Null(response.Old); + Assert.NotNull(response.New); + Assert.Equal(doc.Message, response.New.Message); + Assert.Equal(response._id, response.New._id); + } + [Fact] public async Task PostDocument_ShouldFail_WhenDocumentIsInvalid() { diff --git a/arangodb-net-standard.Test/DocumentApi/Models/PostDocumentMockModel.cs b/arangodb-net-standard.Test/DocumentApi/Models/PostDocumentMockModel.cs new file mode 100644 index 00000000..fa3ca7a9 --- /dev/null +++ b/arangodb-net-standard.Test/DocumentApi/Models/PostDocumentMockModel.cs @@ -0,0 +1,9 @@ +using ArangoDBNetStandard.DocumentApi.Models; + +namespace ArangoDBNetStandardTest.DocumentApi.Models +{ + public class PostDocumentMockModel : DocumentBase + { + public string Message { get; set; } + } +} diff --git a/arangodb-net-standard.Test/DocumentApi/Models/PostDocumentMockModelNew.cs b/arangodb-net-standard.Test/DocumentApi/Models/PostDocumentMockModelNew.cs new file mode 100644 index 00000000..ef2d086b --- /dev/null +++ b/arangodb-net-standard.Test/DocumentApi/Models/PostDocumentMockModelNew.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; + +namespace ArangoDBNetStandardTest.DocumentApi.Models +{ + public class PostDocumentMockModelNew + { + public string Message { get; set; } + } +} diff --git a/arangodb-net-standard/DocumentApi/DocumentApiClient.cs b/arangodb-net-standard/DocumentApi/DocumentApiClient.cs index bb04fb90..9b7a6099 100644 --- a/arangodb-net-standard/DocumentApi/DocumentApiClient.cs +++ b/arangodb-net-standard/DocumentApi/DocumentApiClient.cs @@ -55,7 +55,34 @@ public DocumentApiClient(IApiClientTransport client, IApiClientSerialization ser /// The serialization options. When the value is null the /// the serialization options should be provided by the serializer, otherwise the given options should be used. /// - public virtual async Task> PostDocumentAsync( + public virtual Task> PostDocumentAsync( + string collectionName, + T document, + PostDocumentsQuery query = null, + ApiClientSerializationOptions serializationOptions = null) + { + return PostDocumentAsync( + collectionName, + document, + query, + serializationOptions); + } + + /// + /// Post a single document with the possibility to specify a different type + /// for the new document object returned in the response. + /// + /// The type of the post object used to record a new document. + /// Type of the returned document, only applies when + /// or + /// are used. + /// + /// + /// + /// The serialization options. When the value is null the + /// the serialization options should be provided by the serializer, otherwise the given options should be used. + /// + public virtual async Task> PostDocumentAsync( string collectionName, T document, PostDocumentsQuery query = null, @@ -72,7 +99,7 @@ public virtual async Task> PostDocumentAsync( if (response.IsSuccessStatusCode) { var stream = await response.Content.ReadAsStreamAsync(); - return DeserializeJsonFromStream>(stream); + return DeserializeJsonFromStream>(stream); } throw await GetApiErrorException(response); } diff --git a/arangodb-net-standard/DocumentApi/IDocumentApiClient.cs b/arangodb-net-standard/DocumentApi/IDocumentApiClient.cs index 2e6c7272..559de4df 100644 --- a/arangodb-net-standard/DocumentApi/IDocumentApiClient.cs +++ b/arangodb-net-standard/DocumentApi/IDocumentApiClient.cs @@ -14,7 +14,7 @@ public interface IDocumentApiClient /// /// Post a single document. /// - /// + /// The type of the post object used to record a new document. /// /// /// @@ -27,6 +27,26 @@ Task> PostDocumentAsync( PostDocumentsQuery query = null, ApiClientSerializationOptions serializationOptions = null); + /// + /// Post a single document with the possibility to specify a different type + /// for the new document object returned in the response. + /// + /// The type of the post object used to record a new document. + /// Type of the returned document, only applies when + /// or + /// are used. + /// + /// + /// + /// The serialization options. When the value is null the + /// the serialization options should be provided by the serializer, otherwise the given options should be used. + /// + Task> PostDocumentAsync( + string collectionName, + T document, + PostDocumentsQuery query = null, + ApiClientSerializationOptions serializationOptions = null); + /// /// Post multiple documents in a single request. ///