From ab8f6182350d523173f4e26df1e7327c407656f5 Mon Sep 17 00:00:00 2001 From: Roman Kuzmin Date: Sun, 10 Nov 2019 05:46:58 +0000 Subject: [PATCH] Fix update expressions, close #32 --- Release-Notes.md | 4 ++++ Src/Actor.cs | 4 ++++ Src/Api.cs | 2 +- Tests/Api.test.ps1 | 6 ++++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Release-Notes.md b/Release-Notes.md index 6e1c821..1039914 100644 --- a/Release-Notes.md +++ b/Release-Notes.md @@ -1,5 +1,9 @@ # Mdbc Release Notes +## v6.0.2 + +Fix update expression conversion, #32 + ## v6.0.1 **Mdbc.Dictionary and Mdbc.Collection** diff --git a/Src/Actor.cs b/Src/Actor.cs index 8865f6e..8b9ab86 100644 --- a/Src/Actor.cs +++ b/Src/Actor.cs @@ -177,6 +177,10 @@ static BsonValue ToBsonValue(object value, DocumentInput input, int depth) return ToBsonValue(value, null, depth); } } + public static BsonDocument ToBsonDocumentFromDictionary(IDictionary dictionary) + { + return ToBsonDocumentFromDictionary(null, dictionary, null, null, 0); + } //! IConvertibleToBsonDocument (e.g. Mdbc.Dictionary) must be converted before if source and properties are null static BsonDocument ToBsonDocumentFromDictionary(BsonDocument source, IDictionary dictionary, DocumentInput input, IEnumerable properties, int depth) { diff --git a/Src/Api.cs b/Src/Api.cs index e98ebc9..5098991 100644 --- a/Src/Api.cs +++ b/Src/Api.cs @@ -96,7 +96,7 @@ static bool TryBsonDocument(object value, out BsonDocument result) //! after IConvertibleToBsonDocument if (value is IDictionary dictionary) { - result = new BsonDocument(dictionary); + result = Actor.ToBsonDocumentFromDictionary(dictionary); return true; } diff --git a/Tests/Api.test.ps1 b/Tests/Api.test.ps1 index b06730d..cb167aa 100644 --- a/Tests/Api.test.ps1 +++ b/Tests/Api.test.ps1 @@ -76,3 +76,9 @@ task UpdateDefinition { equals $r1 $r2 ) | Out-String } + +task Issue32 { + $manifestEntry = [PSCustomObject]@{releaseNumber = 1; p1 = 1} + $r = [Mdbc.Api]::UpdateDefinition(@{'$set' = @{value = $manifestEntry}}) + equals $r.Render($null, $null).ToString() '{ "$set" : { "value" : { "releaseNumber" : 1, "p1" : 1 } } }' +}