Skip to content

Commit 7ee1590

Browse files
committed
add option for record
1 parent 8cf1d8e commit 7ee1590

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

tests/FSharp.MongoDB.Bson.Tests/Serialization/FSharpOptionSerializationTests.fs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,30 @@ open NUnit.Framework
2121

2222
module FSharpOptionSerialization =
2323

24+
type Record =
25+
{ Value: string }
26+
2427
type Primitive =
2528
{ Bool : bool option
2629
Int : int option
2730
String : string option
28-
Float : float option }
31+
Float : float option
32+
Record: Record option }
2933

3034
[<Test>]
3135
let ``test serialize optional primitives (none) in a record type``() =
3236
let value = { Bool = None
3337
Int = None
3438
String = None
35-
Float = None }
39+
Float = None
40+
Record = None }
3641

3742
let result = serialize value
3843
let expected = BsonDocument([ BsonElement("Bool", BsonNull.Value)
3944
BsonElement("Int", BsonNull.Value)
4045
BsonElement("String", BsonNull.Value)
41-
BsonElement("Float", BsonNull.Value) ])
46+
BsonElement("Float", BsonNull.Value)
47+
BsonElement("Record", BsonNull.Value) ])
4248

4349
result |> should equal expected
4450

@@ -50,7 +56,8 @@ module FSharpOptionSerialization =
5056
let expected = { Bool = None
5157
Int = None
5258
String = None
53-
Float = None }
59+
Float = None
60+
Record = None }
5461

5562
result |> should equal expected
5663

@@ -59,13 +66,15 @@ module FSharpOptionSerialization =
5966
let value = { Bool = Some false
6067
Int = Some 0
6168
String = Some "0.0"
62-
Float = Some 0.0 }
69+
Float = Some 0.0
70+
Record = Some { Value = "value" } }
6371

6472
let result = serialize value
6573
let expected = BsonDocument([ BsonElement("Bool", BsonBoolean false)
6674
BsonElement("Int", BsonInt32 0)
6775
BsonElement("String", BsonString "0.0")
68-
BsonElement("Float", BsonDouble 0.0) ])
76+
BsonElement("Float", BsonDouble 0.0)
77+
BsonElement("Record", BsonDocument([ BsonElement("Value", "value") ])) ])
6978

7079
result |> should equal expected
7180

@@ -74,12 +83,14 @@ module FSharpOptionSerialization =
7483
let doc = BsonDocument([ BsonElement("Bool", BsonBoolean true)
7584
BsonElement("Int", BsonInt32 1)
7685
BsonElement("String", BsonString "1.0")
77-
BsonElement("Float", BsonDouble 1.0) ])
86+
BsonElement("Float", BsonDouble 1.0)
87+
BsonElement("Record", BsonDocument([ BsonElement("Value", "value") ])) ])
7888

7989
let result = deserialize<Primitive> doc
8090
let expected = { Bool = Some true
8191
Int = Some 1
8292
String = Some "1.0"
83-
Float = Some 1.0 }
93+
Float = Some 1.0
94+
Record = Some { Value = "value" } }
8495

8596
result |> should equal expected

0 commit comments

Comments
 (0)