forked from samus/mongodb-csharp
/
TestBsonConvert.cs
60 lines (46 loc) · 1.83 KB
/
TestBsonConvert.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using NUnit.Framework;
using MongoDB.Driver;
namespace MongoDB.Driver.Bson
{
[TestFixture]
public class TestBsonConvert
{
[Test]
public void TestFromDocument(){
Document doc = new Document();
doc.Add("string", "test");
doc.Add("int", 1);
BsonDocument bdoc = BsonConvert.From(doc);
Assert.AreEqual(2,bdoc.Count);
/*doc.Add("date", DateTime.MinValue);
Assert.Throws<ArgumentOutOfRangeException>(
delegate {BsonConvert.From(doc);});*/ //Not in nUnit 2.4.
}
[Test]
public void TestFromInt(){
BsonType t = BsonConvert.From(1);
Assert.AreEqual(typeof(BsonInteger),t.GetType());
Assert.AreEqual(1, ((BsonInteger)t).Val);
}
[Test]
public void TestCreate(){
BsonString bs = (BsonString)BsonConvert.Create(BsonDataType.String);
Assert.IsNotNull(bs);
BsonDocument bd = (BsonDocument)BsonConvert.Create(BsonDataType.Obj);
Assert.IsNotNull(bd);
}
[Test]
public void TestDBRefRoundTrip(){
Document source = new Document();
source.Append("x",1).Append("ref",new DBRef("refs","ref1"));
BsonDocument bdoc = BsonConvert.From(source);
Document copy = (Document)bdoc.ToNative();
Assert.IsTrue(copy.Contains("ref"));
Assert.IsTrue(copy["ref"].GetType() == typeof(DBRef));
DBRef sref = (DBRef)source["ref"];
DBRef cref = (DBRef)copy["ref"];
Assert.AreEqual(sref.Id, cref.Id);
}
}
}