|
| 1 | +(* |
| 2 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | + * you may not use this file except in compliance with the License. |
| 4 | + * You may obtain a copy of the License at |
| 5 | + * |
| 6 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | + * |
| 8 | + * Unless required by applicable law or agreed to in writing, software |
| 9 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | + * See the License for the specific language governing permissions and |
| 12 | + * limitations under the License. |
| 13 | + *) |
| 14 | + |
| 15 | +namespace FSharp.MongoDB.Bson.Tests.Serialization |
| 16 | + |
| 17 | +open MongoDB.Bson |
| 18 | +open FsUnit |
| 19 | +open NUnit.Framework |
| 20 | + |
| 21 | +module FSharpNRTSerialization = |
| 22 | + |
| 23 | + type Primitive = |
| 24 | + { String : string | null } |
| 25 | + |
| 26 | + [<Test>] |
| 27 | + let ``test serialize nullable reference (null) in a record type``() = |
| 28 | + let value = { String = null } |
| 29 | + |
| 30 | + let result = serialize value |
| 31 | + let expected = BsonDocument([ BsonElement("String", BsonNull.Value) ]) |
| 32 | + |
| 33 | + result |> should equal expected |
| 34 | + |
| 35 | + [<Test>] |
| 36 | + let ``test deserialize nullable reference (null) in a record type)``() = |
| 37 | + // FIXME: this shall support deserializing missing null value for NRT |
| 38 | + // as of now this means NRT can't be a missing value while deserializing |
| 39 | + // let doc = BsonDocument() |
| 40 | + let doc = BsonDocument([ BsonElement("String", BsonNull.Value) ]) |
| 41 | + |
| 42 | + let result = deserialize<Primitive> doc |
| 43 | + let expected = { String = null } |
| 44 | + |
| 45 | + result |> should equal expected |
| 46 | + |
| 47 | + [<Test>] |
| 48 | + let ``test serialize nullable reference (some) in a record type``() = |
| 49 | + let value = { String = "A String" } |
| 50 | + |
| 51 | + let result = serialize value |
| 52 | + let expected = BsonDocument([ BsonElement("String", BsonString "A String") ]) |
| 53 | + |
| 54 | + result |> should equal expected |
| 55 | + |
| 56 | + [<Test>] |
| 57 | + let ``test deserialize nullable reference (some) in a record type``() = |
| 58 | + let doc = BsonDocument([ BsonElement("String", BsonString "A String") ]) |
| 59 | + |
| 60 | + let result = deserialize<Primitive> doc |
| 61 | + let expected = { String = "A String" } |
| 62 | + |
| 63 | + result |> should equal expected |
0 commit comments