Skip to content

Upgrade to .NET 6 and latest MongoDB.Driver #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
12 changes: 12 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"paket": {
"version": "6.2.1",
"commands": [
"paket"
]
}
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ local.properties
.classpath
.settings/
.loadpath
.idea/

# External tool builders
.externalToolBuilders/
Expand Down
557 changes: 557 additions & 0 deletions .paket/Paket.Restore.targets

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions MongoDB.FSharp.BackwardCompatTests/BackwardCompatTest.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module ``Acceptance Tests``

open Mongo2Go
open MongoDB.Bson
open MongoDB.Driver
open MongoDB.FSharp
open Xunit

module TestUtils =
let newBsonObjectId() = ObjectId.GenerateNewId() |> BsonObjectId

let findById id (collection: IMongoCollection<BsonDocument>) =
let filter = FilterDefinition<BsonDocument>.op_Implicit(BsonDocument("_id", id))
collection.Find(filter).ToList() |> Seq.head

open TestUtils

type ObjectWithOptions() =
member val Id : BsonObjectId = newBsonObjectId() with get, set
member val Age : int option = None with get, set

type ``Backward compatibility tests``() =
let runner = MongoDbRunner.Start()
let db = MongoClient(runner.ConnectionString).GetDatabase("IntegrationTest")
do Serializers.Register({ UseOptionNull = false })

interface System.IDisposable with
member this.Dispose() = runner.Dispose()

[<Fact>]
member this.``It can serialize option types``() =
let collection = db.GetCollection<ObjectWithOptions> "objects"
let obj = ObjectWithOptions()
obj.Age <- Some 42
collection.InsertOne obj

let collection = db.GetCollection<BsonDocument> "objects"
let fromDb = collection |> findById obj.Id
let age = fromDb.GetElement("Age")
Assert.NotNull(age);
Assert.Equal<string>("Some", age.Value.AsBsonDocument.GetElement("_t").Value.AsString)
let value = age.Value.AsBsonDocument.GetElement("_v").Value
Assert.True(value.IsBsonArray)
let array = value.AsBsonArray
Assert.Equal(1, array.Count)
Assert.Equal(42, array.[0].AsInt32)

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
<GenerateProgramFile>false</GenerateProgramFile>
</PropertyGroup>
<ItemGroup>
<Compile Include="Tests.fs" />
<Compile Include="BackwardCompatTest.fs" />
<Compile Include="Program.fs" />
<Content Include="paket.references" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MongoDB.FSharp\MongoDB.FSharp.fsproj" />
</ItemGroup>
<Import Project="..\.paket\Paket.Restore.targets" />
</Project>
1 change: 1 addition & 0 deletions MongoDB.FSharp.BackwardCompatTests/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module Program = let [<EntryPoint>] main _ = 0
8 changes: 8 additions & 0 deletions MongoDB.FSharp.BackwardCompatTests/Tests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Tests

open System
open Xunit

[<Fact>]
let ``My test`` () =
Assert.True(true)
6 changes: 6 additions & 0 deletions MongoDB.FSharp.BackwardCompatTests/paket.references
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FSharp.Core
xunit
unquote
Mongo2Go
Microsoft.NET.Test.Sdk
xunit.runner.visualstudio
Loading