Skip to content

Commit

Permalink
Merge with master
Browse files Browse the repository at this point in the history
  • Loading branch information
MNie committed Jun 6, 2021
2 parents cd1bd46 + 3b190c7 commit c4d4a8f
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 29 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ bin/
obj/
/packages/
.idea
.ionide
.ionide
.localDB
5 changes: 4 additions & 1 deletion BagnoDB.sln.DotSettings.user
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/Environment/AssemblyExplorer/XmlDocument/@EntryValue">&lt;AssemblyExplorer&gt;
&lt;Assembly Path="/Users/mniegrzybowski/.nuget/packages/xunit.extensibility.execution/2.4.0/lib/netstandard2.0/xunit.execution.dotnet.dll" /&gt;
&lt;/AssemblyExplorer&gt;</s:String></wpf:ResourceDictionary>
&lt;/AssemblyExplorer&gt;</s:String>
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=91ab0c00_002D97f9_002D42b7_002Db58d_002D7f8ebdedcb02/@EntryIndexedValue">&lt;SessionState ContinuousTestingIsOn="False" ContinuousTestingMode="0" FrameworkVersion="{x:Null}" IsLocked="False" Name="All tests from Solution" PlatformMonoPreference="{x:Null}" PlatformType="{x:Null}" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
&lt;Solution /&gt;
&lt;/SessionState&gt;</s:String></wpf:ResourceDictionary>
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# BagnoDB
# BagnoDB
* NuGet Status

| | BagnoDB | BagnoDB.Serializator |
|---|---|---|
| nuget | [![NuGet](https://buildstats.info/nuget/BagnoDB?includePreReleases=true)](https://www.nuget.org/packages/BagnoDB) | [![NuGet](https://buildstats.info/nuget/BagnoDB.Serializator?includePreReleases=true)](https://www.nuget.org/packages/BagnoDB.Serializator) |


F# wrapper over MongoDB.Driver.

Expand Down
4 changes: 2 additions & 2 deletions src/BagnoDB.Serializator/BagnoDB.Serializator.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.0.9</Version>
<Version>0.0.11</Version>
<Authors>Michał Niegrzybowski</Authors>
<Company>Michał Niegrzybowski - MNie</Company>
<PackageId>BagnoDB.Serializator</PackageId>
Expand All @@ -30,7 +30,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="MongoDB.Bson" Version="2.10.2" />
<PackageReference Include="MongoDB.Bson" Version="2.10.4" />
</ItemGroup>

</Project>
3 changes: 2 additions & 1 deletion src/BagnoDB.Serializator/OptionSerializer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ type OptionSerializer<'TOption when 'TOption: equality>() =

let (case, args) =
let value =
if (typeOfArg.IsPrimitive) then
let isDecimalValueNull = (typeOfArg = typeof<decimal> && context.Reader.CurrentBsonType = BsonType.Null)
if typeOfArg.IsPrimitive || isDecimalValueNull then
BsonSerializer.Deserialize(context.Reader, typeof<obj>)
else
BsonSerializer.Deserialize(context.Reader, typeOfArg)
Expand Down
4 changes: 2 additions & 2 deletions src/BagnoDB/BagnoDB.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.0.9</Version>
<Version>0.0.11</Version>
<Authors>Michał Niegrzybowski</Authors>
<Company>Michał Niegrzybowski - MNie</Company>
<PackageId>BagnoDB</PackageId>
Expand All @@ -30,7 +30,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="2.10.2" />
<PackageReference Include="MongoDB.Driver" Version="2.10.4" />
</ItemGroup>

</Project>
9 changes: 8 additions & 1 deletion src/BagnoDB/Serialization.fs
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
namespace BagnoDB

open MongoDB.Bson.Serialization
open MongoDB.Bson.Serialization.Serializers

module Serialization =
let bson bsonSerializer =
BsonSerializer.RegisterSerializationProvider bsonSerializer
BsonSerializer.RegisterSerializationProvider bsonSerializer

let typedBson<'TType> bsonSerializer =
BsonSerializer.RegisterSerializer<'TType> bsonSerializer

let decimal () =
BsonSerializer.RegisterSerializer(typeof<decimal>, DecimalSerializer MongoDB.Bson.BsonType.Decimal128)
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="coverlet.collector" Version="1.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="coverlet.collector" Version="1.2.1" />
<PackageReference Include="Unquote" Version="5.0.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="Unquote" Version="5.0.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="coverlet.collector" Version="1.2.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="coverlet.collector" Version="1.2.1" />
</ItemGroup>

<ItemGroup>
Expand Down
70 changes: 62 additions & 8 deletions tests/BagnoDB.Serializator.IntegrationTests/Tests.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace BagnoDB.Serializator.Tests

open System.Threading
open System
open Xunit
open Swensen.Unquote
open BagnoDB
Expand Down Expand Up @@ -45,7 +46,22 @@ type SmallestPossibleRecord =
Foo: Union
}

type RecordOfOptionTypes = {
Boolean: bool option
Decimal: decimal option
float: float option
Int32: Int32 option
Int64: Int64 option
}

type SerializatorTests() =
do
Serialization.bson (BagnoSerializationProvider ())
Conventions.create
|> Conventions.add (OptionConvention ())
|> Conventions.add (RecordConvention ())
|> Conventions.build "F# Type Conventions"

let database = "BagnoDB_Serializator_IntegrationTests"

let config = {
Expand All @@ -61,14 +77,6 @@ type SerializatorTests() =
Connection.host config
|> Connection.database database
|> Connection.collection collection

Conventions.create
|> Conventions.add (OptionConvention ())
|> Conventions.add (RecordConvention ())
|> Conventions.build "F# Type Conventions"

Serialization.bson (BagnoSerializationProvider ())

connection

[<Fact>]
Expand Down Expand Up @@ -140,3 +148,49 @@ type SerializatorTests() =
let! saved = con |> Query.filter CancellationToken.None filterOpt wildcard
testCase =! (saved |> Seq.head)
} |> Async.RunSynchronously

[<Fact>]
member _.``record with optional type None should be serialized/deserialized correctly`` () =
let wildcard = Filter.empty
let testCase: RecordOfOptionTypes = {
Boolean = None
Decimal = None
float = None
Int32 = None
Int64 = None
}

let con = connection "RecordOptionType_None_Tests"
let delOpt = DeleteOptions()
let insOpt = InsertOneOptions()
let filterOpt = FindOptions<RecordOfOptionTypes>()

async {
let! _ = con |> Query.deleteMany CancellationToken.None delOpt wildcard
do! con |> Query.insertOne CancellationToken.None insOpt testCase
let! saved = con |> Query.filter CancellationToken.None filterOpt wildcard
testCase =! (saved |> Seq.head)
} |> Async.RunSynchronously

[<Fact>]
member _.``record with optional type fields all Some value should be serialized/deserialized correctly`` () =
let wildcard = Filter.empty
let testCase: RecordOfOptionTypes = {
Boolean = Some true
Decimal = Some 1M
float = Some 1.0
Int32 = Some 1
Int64 = Some 1L
}

let con = connection "RecordOptionType_Some_Tests"
let delOpt = DeleteOptions()
let insOpt = InsertOneOptions()
let filterOpt = FindOptions<RecordOfOptionTypes>()

async {
let! _ = con |> Query.deleteMany CancellationToken.None delOpt wildcard
do! con |> Query.insertOne CancellationToken.None insOpt testCase
let! saved = con |> Query.filter CancellationToken.None filterOpt wildcard
testCase =! (saved |> Seq.head)
} |> Async.RunSynchronously
8 changes: 4 additions & 4 deletions tests/BagnoDB.Tests/BagnoDB.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="coverlet.collector" Version="1.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="coverlet.collector" Version="1.2.1" />
<PackageReference Include="Unquote" Version="5.0.0" />
</ItemGroup>

Expand Down

0 comments on commit c4d4a8f

Please sign in to comment.