diff --git a/MongoDB.FSharp.Tests/AcceptanceTests.fs b/MongoDB.FSharp.Tests/AcceptanceTests.fs index 23f7475..f3ad802 100644 --- a/MongoDB.FSharp.Tests/AcceptanceTests.fs +++ b/MongoDB.FSharp.Tests/AcceptanceTests.fs @@ -7,14 +7,14 @@ open MongoDB.Bson open MongoDB.Driver open MongoDB.Driver.Linq -open MongoDB.FSharp +open MongoDB.Driver.FSharp open System.Linq open Microsoft.FSharp.Linq open TestUtils type ObjectWithList() = - member val Id : BsonObjectId = BsonObjectId.GenerateNewId() with get, set + member val Id : BsonObjectId = BsonObjectId(ObjectId.GenerateNewId()) with get, set member val List : string list = [] with get, set type RecordType = { @@ -41,91 +41,98 @@ type DimmerSwitch = | On type ObjectWithOptions() = - member val Id : BsonObjectId = BsonObjectId.GenerateNewId() with get, set + member val Id : BsonObjectId = BsonObjectId(ObjectId.GenerateNewId()) with get, set member val Age : int option = None with get, set type ObjectWithDimmer() = - member val Id : BsonObjectId = BsonObjectId.GenerateNewId() with get, set + member val Id : BsonObjectId = BsonObjectId(ObjectId.GenerateNewId()) with get, set member val Switch : DimmerSwitch = Off with get, set type ObjectWithDimmers() = - member val Id : BsonObjectId = BsonObjectId.GenerateNewId() with get, set + member val Id : BsonObjectId = BsonObjectId(ObjectId.GenerateNewId()) with get, set member val Kitchen : DimmerSwitch = Off with get, set member val Bedroom1 : DimmerSwitch = Off with get, set member val Bedroom2 : DimmerSwitch = Off with get, set type ``When serializing lists``() = - let db = MongoDatabase.Create "mongodb://localhost/test" + let conn = new MongoClient("mongodb://localhost") + let db = conn.GetDatabase("test") do Serializers.Register() interface System.IDisposable with member this.Dispose() = - db.DropCollection "objects" |> ignore - db.DropCollection "persons" |> ignore + () + db.DropCollectionAsync "objects" |> AwaitVoidTask |> ignore + db.DropCollectionAsync "persons" |> AwaitVoidTask |> ignore /// Seems to be fixed in version 1.5 of the C# driver [] member this.``It can serialize an object with a list``() = - let collection = db.GetCollection "objects" - let obj = ObjectWithList() - obj.List <- [ "hello"; "world" ] - collection.Save obj |> ignore - - let genCollection = db.GetCollection "objects" - let fromDb = genCollection.FindOne(new QueryDocument("_id", obj.Id)) - let array = fromDb.["List"].AsBsonArray - Assert.Equal(2, array.Count) + let collection = db.GetCollection "objects" + let obj = ObjectWithList() + obj.List <- [ "hello"; "world" ] + collection.InsertOneAsync obj |> AwaitVoidTask |> Async.RunSynchronously + + let genCollection = db.GetCollection "objects" + let fromDb = genCollection.Find(fun x -> x.Id = obj.Id).FirstAsync() + |> Async.AwaitTask |> Async.RunSynchronously + let array = fromDb.List + Assert.Equal(2, array.Length) [] - member this.``It can deserialze lists``() = - let list = BsonArray([ "hello"; "world" ]) - let id = BsonObjectId.GenerateNewId() - let document = BsonDocument([ BsonElement("_id", id); BsonElement("List", list) ]) - let collection = db.GetCollection "objects" - collection.Save document |> ignore - - let collection = db.GetCollection "objects" - let fromDb = collection.FindOne(new QueryDocument("_id", id)) - let array = fromDb.List - Assert.Equal(2, array.Length) + member this.``It can deserialze lists``() = + let list = BsonArray([ "hello"; "world" ]) + let id = BsonObjectId(ObjectId.GenerateNewId()) + let document = BsonDocument([ BsonElement("_id", id); BsonElement("List", list) ]) + let collection = db.GetCollection "objects" + collection.InsertOneAsync document |> AwaitVoidTask |> Async.RunSynchronously + + let collection = db.GetCollection "objects" + let fromDb = collection.Find(fun x -> x.Id = id).FirstAsync() + |> Async.AwaitTask |> Async.RunSynchronously + let array = fromDb.List + Assert.Equal(2, array.Length) [] member this.``It can serialize records``() = - let collection = db.GetCollection "objects" - let obj = { Id = BsonObjectId.GenerateNewId(); Name = "test" } - collection.Save obj |> ignore + let collection = db.GetCollection "objects" + let obj = { Id = BsonObjectId(ObjectId.GenerateNewId()); Name = "test" } + collection.InsertOneAsync obj |> AwaitVoidTask |> ignore - let genCollection = db.GetCollection "objects" - let fromDb = genCollection.FindOne(new QueryDocument("_id", obj.Id)) - let test = fromDb.["Name"].AsString - Assert.Equal("test", test) + let fromDb = collection.Find(fun x -> x.Id = obj.Id).FirstAsync() + |> Async.AwaitTask + |> Async.RunSynchronously + Assert.Equal("test", fromDb.Name) [] member this.``It can deserialize records``() = - let id = BsonObjectId.GenerateNewId() + let id = BsonObjectId(ObjectId.GenerateNewId()) let document = BsonDocument([BsonElement("_id", id); BsonElement("Name", BsonString("value"))]) let collection = db.GetCollection "objects" - collection.Save(document) |> ignore + collection.InsertOneAsync(document) |> AwaitVoidTask |> Async.RunSynchronously let collection = db.GetCollection("objects") - let fromDb = collection.FindOneById(id) + let fromDb = collection.Find(fun x -> x.Id = id).FirstAsync() + |> Async.AwaitTask + |> Async.RunSynchronously Assert.NotNull(fromDb) Assert.Equal("value", fromDb.Name) [] member this.``It can serialize and deserialize nested records``() = let collection = db.GetCollection "persons" - let obj = { Id = BsonObjectId.GenerateNewId(); PersonName = "test"; Age = 33; Childs = [{ChildName = "Adrian"; Age = 3}] } - collection.Save obj |> ignore + let obj = { Id = BsonObjectId(ObjectId.GenerateNewId()); + PersonName = "test"; + Age = 33; + Childs = [{ChildName = "Adrian"; + Age = 3}] } + collection.InsertOneAsync obj |> AwaitVoidTask |> Async.RunSynchronously let genCollection = db.GetCollection "persons" - let person = query { - for p in genCollection.AsQueryable() do - where (p.Id = obj.Id) - select p - headOrDefault - } + let person = genCollection.Find(fun x -> x.Id = obj.Id).FirstAsync() + |> Async.AwaitTask + |> Async.RunSynchronously Assert.NotNull person Assert.Equal("test",person.PersonName) @@ -135,7 +142,7 @@ type ``When serializing lists``() = let child = person.Childs |> Seq.head Assert.Equal("Adrian", child.ChildName) - Assert.Equal(3, child.Age) + Assert.Equal(3, child.Age) [] @@ -143,13 +150,19 @@ type ``When serializing lists``() = let collection = db.GetCollection "objects" let obj = ObjectWithOptions() obj.Age <- Some 42 - collection.Save obj |> ignore + collection.InsertOneAsync obj + |> AwaitVoidTask + |> Async.RunSynchronously let collection = db.GetCollection "objects" - let fromDb = collection.FindOneById(obj.Id) + let filter = new BsonDocumentFilterDefinition<_>(new BsonDocument() + |> (fun d -> d.Add("_id",obj.Id))) + let fromDb = collection.Find(filter).FirstAsync() + |> Async.AwaitTask + |> Async.RunSynchronously let age = fromDb.GetElement("Age") Assert.NotNull(age); - Assert.Equal("Some", age.Value.AsBsonDocument.GetElement("_t").Value.AsString) + Assert.Equal("Some", age.Value.ToBsonDocument().GetElement("_t").Value.AsString) let value = age.Value.AsBsonDocument.GetElement("_v").Value Assert.True(value.IsBsonArray) let array = value.AsBsonArray @@ -158,13 +171,19 @@ type ``When serializing lists``() = [] member this.``It can serialize DimmerSwitch types``() = - let collection = db.GetCollection "objects" let obj = ObjectWithDimmer() - obj.Switch <- DimMarquee(42, "loser") - collection.Save obj |> ignore - - let collection = db.GetCollection "objects" - let fromDb = collection.FindOneById(obj.Id) + obj.Switch <- DimMarquee(42, "loser") + db.GetCollection("objects").InsertOneAsync (obj) + |> AwaitVoidTask + |> Async.RunSynchronously + + let collection = db.GetCollection "objects" + + let filter = new BsonDocumentFilterDefinition<_>(new BsonDocument() + |> (fun d -> d.Add("_id",obj.Id))) + let fromDb = collection.Find(filter).FirstAsync() + |> Async.AwaitTask + |> Async.RunSynchronously let switch = fromDb.GetElement("Switch") Assert.NotNull(switch); Assert.Equal("DimMarquee", switch.Value.AsBsonDocument.GetElement("_t").Value.AsString) @@ -177,37 +196,45 @@ type ``When serializing lists``() = [] member this.``It can deserialize option types``() = - let id = BsonObjectId.GenerateNewId() - let arrayPart = BsonArray([ BsonInt32(42) ]) - let structure = BsonDocument(BsonElement("_t", BsonString("Some")), BsonElement("_v", arrayPart)) - let document = BsonDocument(BsonElement("_id", id), BsonElement("Age", structure)) - let collection = db.GetCollection "objects" - collection.Save(document) |> ignore - - let collection = db.GetCollection "objects" - let fromDb = collection.FindOneById id - match fromDb.Age with - | Some 42 -> () - | _ -> fail "expected Some 42 but got something else" + let id = BsonObjectId(ObjectId.GenerateNewId()) + let arrayPart = BsonArray([ BsonInt32(42) ]) + let structure = BsonDocument([| BsonElement("_t", BsonString("Some")); BsonElement("_v", arrayPart) |].AsEnumerable()) + let document = BsonDocument([|BsonElement("_id", id); BsonElement("Age", structure)|].AsEnumerable()) + let collection = db.GetCollection "objects" + collection.InsertOneAsync(document) + |> AwaitVoidTask + |> ignore + + let collection = db.GetCollection "objects" + let fromDb = collection.Find(fun x -> x.Id = id).FirstAsync() + |> Async.AwaitTask + |> Async.RunSynchronously + match fromDb.Age with + | Some 42 -> () + | _ -> fail "expected Some 42 but got something else" [] member this.``We can integrate serialize & deserialize on DimmerSwitches``() = - let collection = db.GetCollection "objects" - let obj = ObjectWithDimmers() - obj.Kitchen <- Off - obj.Bedroom1 <- Dim 42 - obj.Bedroom2 <- DimMarquee(12, "when I was little...") - collection.Save obj |> ignore - - let fromDb = collection.FindOneById obj.Id - match fromDb.Kitchen with - | Off -> () - | _ -> fail "Kitchen light wasn't off" - - match fromDb.Bedroom1 with - | Dim 42 -> () - | _ -> fail "Bedroom1 light wasn't dim enough" - - match fromDb.Bedroom2 with - | DimMarquee(12, "when I was little...") -> () - | _ -> fail "Bedroom2 doesn't have the party we thought" \ No newline at end of file + let collection = db.GetCollection "objects" + let obj = ObjectWithDimmers() + obj.Kitchen <- Off + obj.Bedroom1 <- Dim 42 + obj.Bedroom2 <- DimMarquee(12, "when I was little...") + collection.InsertOneAsync obj + |> AwaitVoidTask + |> ignore + + let fromDb = collection.Find(fun x -> x.Id = obj.Id).FirstAsync() + |> Async.AwaitTask + |> Async.RunSynchronously + match fromDb.Kitchen with + | Off -> () + | _ -> fail "Kitchen light wasn't off" + + match fromDb.Bedroom1 with + | Dim 42 -> () + | _ -> fail "Bedroom1 light wasn't dim enough" + + match fromDb.Bedroom2 with + | DimMarquee(12, "when I was little...") -> () + | _ -> fail "Bedroom2 doesn't have the party we thought" \ No newline at end of file diff --git a/MongoDB.FSharp.Tests/MongoDB.FSharp.Tests.fsproj b/MongoDB.FSharp.Tests/MongoDB.FSharp.Tests.fsproj index a23ad59..a7e56b9 100644 --- a/MongoDB.FSharp.Tests/MongoDB.FSharp.Tests.fsproj +++ b/MongoDB.FSharp.Tests/MongoDB.FSharp.Tests.fsproj @@ -14,6 +14,7 @@ ..\ true + 4.3.1.0 true @@ -34,16 +35,45 @@ 3 bin\Release\MongoDB.FSharp.Tests.XML + + 11 + + + + + $(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets + + + + + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets + + + + + - + + + + + + + + + ..\packages\FSharp.Core.3.1.2.1\lib\net40\FSharp.Core.dll True - ..\packages\mongocsharpdriver.1.8.1\lib\net35\MongoDB.Bson.dll + ..\packages\MongoDB.Bson.2.0.1\lib\net45\MongoDB.Bson.dll True - ..\packages\mongocsharpdriver.1.8.1\lib\net35\MongoDB.Driver.dll + ..\packages\MongoDB.Driver.2.0.1\lib\net45\MongoDB.Driver.dll + True + + + ..\packages\MongoDB.Driver.Core.2.0.1\lib\net45\MongoDB.Driver.Core.dll True @@ -59,23 +89,12 @@ - - - - - - - - MongoDB.FSharp + + MongoDB.Driver.FSharp {7cbeb93a-1590-42db-9e40-61630e79304a} True - - 11 - - - + https://github.com/nukedbit/MongoDB.FSharp/blob/master/License.txt + https://github.com/nukedbit/MongoDB.FSharp false Silent utilities to make the official MongoDB driver feel natural to work with in F# Initial release, should work but not recommended for production - Copyright 2013 + Copyright 2015 + + + f# fsharp mongodB nosql utility diff --git a/MongoDB.FSharp.sln b/MongoDB.FSharp.sln index 384c927..f8645fa 100644 --- a/MongoDB.FSharp.sln +++ b/MongoDB.FSharp.sln @@ -1,10 +1,8 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2012 -Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "MongoDB.FSharp", "MongoDB.FSharp\MongoDB.FSharp.fsproj", "{7CBEB93A-1590-42DB-9E40-61630E79304A}" -EndProject -Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "MongoDB.FSharp.Tests", "MongoDB.FSharp.Tests\MongoDB.FSharp.Tests.fsproj", "{DE725DAC-C637-4DA7-A30D-69061D33D1B2}" -EndProject +# Visual Studio 2013 +VisualStudioVersion = 12.0.31101.0 +MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{1207C2F4-D695-48D4-A0D1-9258EC678E22}" ProjectSection(SolutionItems) = preProject .nuget\NuGet.Config = .nuget\NuGet.Config @@ -21,6 +19,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution README.md = README.md EndProjectSection EndProject +Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "MongoDB.Driver.FSharp", "MongoDB.FSharp\MongoDB.Driver.FSharp.fsproj", "{7CBEB93A-1590-42DB-9E40-61630E79304A}" +EndProject +Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "MongoDB.FSharp.Tests", "MongoDB.FSharp.Tests\MongoDB.FSharp.Tests.fsproj", "{DE725DAC-C637-4DA7-A30D-69061D33D1B2}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/MongoDB.FSharp/MongoDB.FSharp.fsproj b/MongoDB.FSharp/MongoDB.Driver.FSharp.fsproj similarity index 63% rename from MongoDB.FSharp/MongoDB.FSharp.fsproj rename to MongoDB.FSharp/MongoDB.Driver.FSharp.fsproj index 5e12d40..68e5c84 100644 --- a/MongoDB.FSharp/MongoDB.FSharp.fsproj +++ b/MongoDB.FSharp/MongoDB.Driver.FSharp.fsproj @@ -8,12 +8,13 @@ 7cbeb93a-1590-42db-9e40-61630e79304a Library MongoDB.FSharp - MongoDB.FSharp - v4.0 - MongoDB.FSharp + MongoDB.Driver.FSharp + v4.5 + MongoDB.Driver.FSharp ..\ true + 4.3.0.0 true @@ -24,6 +25,9 @@ DEBUG;TRACE 3 bin\Debug\MongoDB.FSharp.XML + Program + D:\Users\faltonis\git\catalog-monitor\CatalogMonitor.Service\bin\Debug\CatalogMonitor.Service.exe + true pdbonly @@ -34,33 +38,47 @@ 3 bin\Release\MongoDB.FSharp.XML + + 11 + + + + + $(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets + + + + + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets + + + + + - + + + + + + + + ..\packages\FSharp.Core.3.1.2.1\lib\net40\FSharp.Core.dll True - ..\packages\mongocsharpdriver.1.8.1\lib\net35\MongoDB.Bson.dll - True + ..\packages\MongoDB.Bson.2.0.1\lib\net45\MongoDB.Bson.dll - ..\packages\mongocsharpdriver.1.8.1\lib\net35\MongoDB.Driver.dll - True + ..\packages\MongoDB.Driver.2.0.1\lib\net45\MongoDB.Driver.dll + + + ..\packages\MongoDB.Driver.Core.2.0.1\lib\net45\MongoDB.Driver.Core.dll - - - - - - - - 11 - - -