Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="Unquote" Version="7.0.1" />
</ItemGroup>

</Project>
42 changes: 21 additions & 21 deletions tests/FSharp.MongoDB.Bson.Tests/FSharpListSerializationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

open MongoDB.Bson

open FsUnit
open NUnit.Framework
open Swensen.Unquote

module FSharpListSerialization =

Expand All @@ -28,55 +28,55 @@
let ``test serialize an empty list``() =
let value = { Ints = [] }

let result = <@ serialize value @>
let result = serialize value
let expected = BsonDocument("Ints", BsonArray List.empty<int>)

test <@ %result = expected @>
result |> should equal expected

[<Test>]
let ``test deserialize an empty list``() =
let doc = BsonDocument("Ints", BsonArray List.empty<int>)

let result = <@ deserialize doc typeof<Record> @>
let result = deserialize doc typeof<Record>
let expected = { Ints = [] }

test <@ %result = expected @>
result |> should equal expected

[<Test>]
let ``test serialize a list of one element``() =
let value = { Ints = [ 0 ] }

let result = <@ serialize value @>
let result = serialize value
let expected = BsonDocument("Ints", BsonArray [ 0 ])

test <@ %result = expected @>
result |> should equal expected

[<Test>]
let ``test deserialize a list of one element``() =
let doc = BsonDocument("Ints", BsonArray [ 0 ])

let result = <@ deserialize doc typeof<Record> @>
let result = deserialize doc typeof<Record>
let expected = { Ints = [ 0 ] }

test <@ %result = expected @>
result |> should equal expected

[<Test>]
let ``test serialize a list of multiple elements``() =
let value = { Ints = [ 1; 2; 3 ] }

let result = <@ serialize value @>
let result = serialize value
let expected = BsonDocument("Ints", BsonArray [ 1; 2; 3 ])

test <@ %result = expected @>
result |> should equal expected

[<Test>]
let ``test deserialize a list of multiple elements``() =
let doc = BsonDocument("Ints", BsonArray [ 1; 2; 3 ])

let result = <@ deserialize doc typeof<Record> @>
let result = deserialize doc typeof<Record>
let expected = { Ints = [ 1; 2; 3 ] }

test <@ %result = expected @>
result |> should equal expected

module OptionType =

Expand All @@ -86,19 +86,19 @@
let ``test serialize a list of optional strings``() =
let value = { MaybeStrings = [ Some "a"; None; Some "z" ] }

let result = <@ serialize value @>
let result = serialize value
let expected = BsonDocument("MaybeStrings", BsonArray [ "a"; null; "z" ])

Check warning on line 90 in tests/FSharp.MongoDB.Bson.Tests/FSharpListSerializationTests.fs

View workflow job for this annotation

GitHub Actions / build

Nullness warning: The type 'string' does not support 'null'.

test <@ %result = expected @>
result |> should equal expected

[<Test>]
let ``test deserialize a list of optional strings``() =
let doc = BsonDocument("MaybeStrings", BsonArray [ "a"; null; "z" ])

Check warning on line 96 in tests/FSharp.MongoDB.Bson.Tests/FSharpListSerializationTests.fs

View workflow job for this annotation

GitHub Actions / build

Nullness warning: The type 'string' does not support 'null'.

let result = <@ deserialize doc typeof<Record> @>
let result = deserialize doc typeof<Record>
let expected = { MaybeStrings = [ Some "a"; None; Some "z" ] }

test <@ %result = expected @>
result |> should equal expected

module RecordType =

Expand All @@ -114,7 +114,7 @@
{ Key = "b"; Value = 2 }
{ Key = "c"; Value = 3 } ] }

let result = <@ serialize value @>
let result = serialize value
let expected =
BsonDocument(
"Elements",
Expand All @@ -125,7 +125,7 @@
BsonDocument [ BsonElement("Key", BsonString "c")
BsonElement("Value", BsonInt32 3) ] ])

test <@ %result = expected @>
result |> should equal expected

[<Test>]
let ``test deserialize a list of record types``() =
Expand All @@ -139,9 +139,9 @@
BsonDocument [ BsonElement("Key", BsonString "c")
BsonElement("Value", BsonInt32 3) ] ])

let result = <@ deserialize doc typeof<Record> @>
let result = deserialize doc typeof<Record>
let expected = { Elements = [ { Key = "a"; Value = 1 }
{ Key = "b"; Value = 2 }
{ Key = "c"; Value = 3 } ] }

test <@ %result = expected @>
result |> should equal expected
26 changes: 13 additions & 13 deletions tests/FSharp.MongoDB.Bson.Tests/FSharpMapSerializationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ namespace FSharp.MongoDB.Bson.Tests.Serialization

open MongoDB.Bson

open FsUnit
open NUnit.Framework
open Swensen.Unquote

module FSharpMapSerialization =

Expand All @@ -35,13 +35,13 @@ module FSharpMapSerialization =
String = Map.empty<string, string>
Float = Map.empty<string, float> }

let result = <@ serialize value @>
let result = serialize value
let expected = BsonDocument([ BsonElement("Bool", BsonDocument())
BsonElement("Int", BsonDocument())
BsonElement("String", BsonDocument())
BsonElement("Float", BsonDocument()) ])

test <@ %result = expected @>
result |> should equal expected

[<Test>]
let ``test deserialize an empty map``() =
Expand All @@ -50,13 +50,13 @@ module FSharpMapSerialization =
BsonElement("String", BsonDocument())
BsonElement("Float", BsonDocument()) ])

let result = <@ deserialize doc typeof<Primitive> @>
let result = deserialize doc typeof<Primitive>
let expected = { Bool = Map.empty<string, bool>
Int = Map.empty<string, int>
String = Map.empty<string, string>
Float = Map.empty<string, float> }

test <@ %result = expected @>
result |> should equal expected

[<Test>]
let ``test serialize a map of one element``() =
Expand All @@ -65,13 +65,13 @@ module FSharpMapSerialization =
String = Map.ofList<string, string> [ ("a", "0.0") ]
Float = Map.ofList<string, float> [ ("a", 0.0) ] }

let result = <@ serialize value @>
let result = serialize value
let expected = BsonDocument([ BsonElement("Bool", BsonDocument("a", BsonBoolean false))
BsonElement("Int", BsonDocument("a", BsonInt32 0))
BsonElement("String", BsonDocument("a", BsonString "0.0"))
BsonElement("Float", BsonDocument("a", BsonDouble 0.0)) ])

test <@ %result = expected @>
result |> should equal expected

[<Test>]
let ``test deserialize a map of one element``() =
Expand All @@ -80,13 +80,13 @@ module FSharpMapSerialization =
BsonElement("String", BsonDocument("a", BsonString "0.0"))
BsonElement("Float", BsonDocument("a", BsonDouble 0.0)) ])

let result = <@ deserialize doc typeof<Primitive> @>
let result = deserialize doc typeof<Primitive>
let expected = { Bool = Map.ofList<string, bool> [ ("a", false) ]
Int = Map.ofList<string, int> [ ("a", 0) ]
String = Map.ofList<string, string> [ ("a", "0.0") ]
Float = Map.ofList<string, float> [ ("a", 0.0) ] }

test <@ %result = expected @>
result |> should equal expected

[<Test>]
let ``test serialize a map of multiple elements``() =
Expand All @@ -96,7 +96,7 @@ module FSharpMapSerialization =
String = Map.ofList<string, string> [ ("a", "0.0"); ("b", "1.0"); ("c", "2.0") ]
Float = Map.ofList<string, float> [ ("a", 0.0); ("b", 1.0); ("c", 2.0) ] }

let result = <@ serialize value @>
let result = serialize value
let expected =
BsonDocument(
[ BsonElement("Bool", BsonDocument([ BsonElement("a", BsonBoolean false)
Expand All @@ -112,7 +112,7 @@ module FSharpMapSerialization =
BsonElement("b", BsonDouble 1.0)
BsonElement("c", BsonDouble 2.0) ])) ])

test <@ %result = expected @>
result |> should equal expected

[<Test>]
let ``test deserialize a map of multiple elements``() =
Expand All @@ -131,11 +131,11 @@ module FSharpMapSerialization =
BsonElement("b", BsonDouble 1.0)
BsonElement("c", BsonDouble 2.0) ])) ])

let result = <@ deserialize doc typeof<Primitive> @>
let result = deserialize doc typeof<Primitive>
let expected =
{ Bool = Map.ofList<string, bool> [ ("a", false); ("b", true); ("c", false) ]
Int = Map.ofList<string, int> [ ("a", 0); ("b", 1); ("c", 2) ]
String = Map.ofList<string, string> [ ("a", "0.0"); ("b", "1.0"); ("c", "2.0") ]
Float = Map.ofList<string, float> [ ("a", 0.0); ("b", 1.0); ("c", 2.0) ] }

test <@ %result = expected @>
result |> should equal expected
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ namespace FSharp.MongoDB.Bson.Tests.Serialization

open MongoDB.Bson

open FsUnit
open NUnit.Framework
open Swensen.Unquote

module FSharpOptionSerialization =

Expand All @@ -35,22 +35,22 @@ module FSharpOptionSerialization =
String = None
Float = None }

let result = <@ serialize value @>
let result = serialize value
let expected = BsonDocument()

test <@ %result = expected @>
result |> should equal expected

[<Test>]
let ``test deserialize optional primitives (none) in a record type)``() =
let doc = BsonDocument()

let result = <@ deserialize doc typeof<Primitive> @>
let result = deserialize doc typeof<Primitive>
let expected = { Bool = None
Int = None
String = None
Float = None }

test <@ %result = expected @>
result |> should equal expected

[<Test>]
let ``test serialize optional primitives (some) in a record type``() =
Expand All @@ -59,13 +59,13 @@ module FSharpOptionSerialization =
String = Some "0.0"
Float = Some 0.0 }

let result = <@ serialize value @>
let result = serialize value
let expected = BsonDocument([ BsonElement("Bool", BsonBoolean false)
BsonElement("Int", BsonInt32 0)
BsonElement("String", BsonString "0.0")
BsonElement("Float", BsonDouble 0.0) ])

test <@ %result = expected @>
result |> should equal expected

[<Test>]
let ``test deserialize optional primitives (some) in a record type``() =
Expand All @@ -74,10 +74,10 @@ module FSharpOptionSerialization =
BsonElement("String", BsonString "1.0")
BsonElement("Float", BsonDouble 1.0) ])

let result = <@ deserialize doc typeof<Primitive> @>
let result = deserialize doc typeof<Primitive>
let expected = { Bool = Some true
Int = Some 1
String = Some "1.0"
Float = Some 1.0 }

test <@ %result = expected @>
result |> should equal expected
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ namespace FSharp.MongoDB.Bson.Tests.Serialization

open MongoDB.Bson

open FsUnit
open NUnit.Framework
open Swensen.Unquote

module FSharpRecordSerialization =

Expand All @@ -35,13 +35,13 @@ module FSharpRecordSerialization =
String = "0.0"
Float = 0.0 }

let result = <@ serialize value @>
let result = serialize value
let expected = BsonDocument([ BsonElement("Bool", BsonBoolean false)
BsonElement("Int", BsonInt32 0)
BsonElement("String", BsonString "0.0")
BsonElement("Float", BsonDouble 0.0) ])

test <@ %result = expected @>
result |> should equal expected

[<Test>]
let ``test deserialize primitives in a record type``() =
Expand All @@ -50,13 +50,13 @@ module FSharpRecordSerialization =
BsonElement("String", BsonString "1.0")
BsonElement("Float", BsonDouble 1.0) ])

let result = <@ deserialize doc typeof<Primitive> @>
let result = deserialize doc typeof<Primitive>
let expected = { Bool = true
Int = 1
String = "1.0"
Float = 1.0 }

test <@ %result = expected @>
result |> should equal expected

module BindingFlags =

Expand All @@ -66,16 +66,16 @@ module FSharpRecordSerialization =
let ``test serialize an internal record type``() =
let value = { Field = 0 }

let result = <@ serialize value @>
let result = serialize value
let expected = BsonDocument("Field", BsonInt32 0)

test <@ %result = expected @>
result |> should equal expected

[<Test>]
let ``test deserialize an internal record type``() =
let doc = BsonDocument("Field", BsonInt32 1)

let result = <@ deserialize doc typeof<InternalRecord> @>
let result = deserialize doc typeof<InternalRecord>
let expected = { Field = 1 }

test <@ %result = expected @>
result |> should equal expected
Loading
Loading