This repository has been archived by the owner on Dec 30, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged authentication code from Seth Edwards
- Loading branch information
Showing
55 changed files
with
3,628 additions
and
49,991 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,60 +1,60 @@ | |||
using System; | using System; | ||
using NUnit.Framework; | using NUnit.Framework; | ||
|
|
||
using MongoDB.Driver; | using MongoDB.Driver; | ||
|
|
||
namespace MongoDB.Driver.Bson | namespace MongoDB.Driver.Bson | ||
{ | { | ||
[TestFixture] | [TestFixture] | ||
public class TestBsonConvert | public class TestBsonConvert | ||
{ | { | ||
[Test] | [Test] | ||
public void TestFromDocument(){ | public void TestFromDocument(){ | ||
Document doc = new Document(); | Document doc = new Document(); | ||
doc.Add("string", "test"); | doc.Add("string", "test"); | ||
doc.Add("int", 1); | doc.Add("int", 1); | ||
BsonDocument bdoc = BsonConvert.From(doc); | BsonDocument bdoc = BsonConvert.From(doc); | ||
Assert.AreEqual(2,bdoc.Count); | Assert.AreEqual(2,bdoc.Count); | ||
|
|
||
/*doc.Add("date", DateTime.MinValue); | /*doc.Add("date", DateTime.MinValue); | ||
Assert.Throws<ArgumentOutOfRangeException>( | Assert.Throws<ArgumentOutOfRangeException>( | ||
delegate {BsonConvert.From(doc);});*/ //Not in nUnit 2.4. | delegate {BsonConvert.From(doc);});*/ //Not in nUnit 2.4. | ||
|
|
||
|
|
||
} | } | ||
[Test] | [Test] | ||
public void TestFromInt(){ | public void TestFromInt(){ | ||
BsonType t = BsonConvert.From(1); | BsonType t = BsonConvert.From(1); | ||
Assert.AreEqual(typeof(BsonInteger),t.GetType()); | Assert.AreEqual(typeof(BsonInteger),t.GetType()); | ||
Assert.AreEqual(1, ((BsonInteger)t).Val); | Assert.AreEqual(1, ((BsonInteger)t).Val); | ||
} | } | ||
|
|
||
[Test] | [Test] | ||
public void TestCreate(){ | public void TestCreate(){ | ||
BsonString bs = (BsonString)BsonConvert.Create(BsonDataType.String); | BsonString bs = (BsonString)BsonConvert.Create(BsonDataType.String); | ||
Assert.IsNotNull(bs); | Assert.IsNotNull(bs); | ||
|
|
||
BsonDocument bd = (BsonDocument)BsonConvert.Create(BsonDataType.Obj); | BsonDocument bd = (BsonDocument)BsonConvert.Create(BsonDataType.Obj); | ||
Assert.IsNotNull(bd); | Assert.IsNotNull(bd); | ||
} | } | ||
|
|
||
[Test] | [Test] | ||
public void TestDBRefRoundTrip(){ | public void TestDBRefRoundTrip(){ | ||
Document source = new Document(); | Document source = new Document(); | ||
source.Append("x",1).Append("ref",new DBRef("refs","ref1")); | source.Append("x",1).Append("ref",new DBRef("refs","ref1")); | ||
BsonDocument bdoc = BsonConvert.From(source); | BsonDocument bdoc = BsonConvert.From(source); | ||
|
|
||
Document copy = (Document)bdoc.ToNative(); | Document copy = (Document)bdoc.ToNative(); | ||
|
|
||
Assert.IsTrue(copy.Contains("ref")); | Assert.IsTrue(copy.Contains("ref")); | ||
Assert.IsTrue(copy["ref"].GetType() == typeof(DBRef)); | Assert.IsTrue(copy["ref"].GetType() == typeof(DBRef)); | ||
|
|
||
DBRef sref = (DBRef)source["ref"]; | DBRef sref = (DBRef)source["ref"]; | ||
DBRef cref = (DBRef)copy["ref"]; | DBRef cref = (DBRef)copy["ref"]; | ||
|
|
||
Assert.AreEqual(sref.Id, cref.Id); | Assert.AreEqual(sref.Id, cref.Id); | ||
|
|
||
} | } | ||
|
|
||
} | } | ||
} | } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,48 +1,48 @@ | |||
/* | /* | ||
* User: scorder | * User: scorder | ||
*/ | */ | ||
|
|
||
using System; | using System; | ||
using NUnit.Framework; | using NUnit.Framework; | ||
|
|
||
namespace MongoDB.Driver.Bson | namespace MongoDB.Driver.Bson | ||
{ | { | ||
[TestFixture] | [TestFixture] | ||
public class TestBsonDate | public class TestBsonDate | ||
{ | { | ||
[Test] | [Test] | ||
public void TestPosixEpochConvertsTo1_1_1970(){ | public void TestPosixEpochConvertsTo1_1_1970(){ | ||
long epoch = 0; | long epoch = 0; | ||
BsonDate bepoch = new BsonDate(epoch); | BsonDate bepoch = new BsonDate(epoch); | ||
Assert.AreEqual(0, bepoch.Val); | Assert.AreEqual(0, bepoch.Val); | ||
} | } | ||
[Test] | [Test] | ||
public void TestNet1_1_1970IsZero(){ | public void TestNet1_1_1970IsZero(){ | ||
DateTime nepoch = new DateTime(1970,1,1,0,0,0,DateTimeKind.Utc); | DateTime nepoch = new DateTime(1970,1,1,0,0,0,DateTimeKind.Utc); | ||
BsonDate bd = new BsonDate(nepoch); | BsonDate bd = new BsonDate(nepoch); | ||
Assert.AreEqual(0, bd.Val); | Assert.AreEqual(0, bd.Val); | ||
} | } | ||
|
|
||
[Test] | [Test] | ||
public void TestConversionOfNow(){ | public void TestConversionOfNow(){ | ||
BsonDate bd1 = new BsonDate(DateTime.Now); | BsonDate bd1 = new BsonDate(DateTime.Now); | ||
BsonDate bd2 = new BsonDate(bd1.Val); | BsonDate bd2 = new BsonDate(bd1.Val); | ||
Assert.AreEqual(bd1.Val, bd2.Val, "Dates weren't the same value."); | Assert.AreEqual(bd1.Val, bd2.Val, "Dates weren't the same value."); | ||
|
|
||
} | } | ||
[Test] | [Test] | ||
public void TestToNative(){ | public void TestToNative(){ | ||
DateTime now = DateTime.Now.ToUniversalTime(); | DateTime now = DateTime.Now.ToUniversalTime(); | ||
BsonDate bd = new BsonDate(now); | BsonDate bd = new BsonDate(now); | ||
DateTime bnow = (DateTime)bd.ToNative(); | DateTime bnow = (DateTime)bd.ToNative(); | ||
Assert.AreEqual(now.Date,bnow.Date, "Native conversion of date failed."); | Assert.AreEqual(now.Date,bnow.Date, "Native conversion of date failed."); | ||
|
|
||
//.Net uses fractional milliseconds so there is a precision loss. | //.Net uses fractional milliseconds so there is a precision loss. | ||
//Just test the hour, minute, second, and milliseconds | //Just test the hour, minute, second, and milliseconds | ||
Assert.AreEqual(now.Hour, bnow.Hour, "Time differed"); | Assert.AreEqual(now.Hour, bnow.Hour, "Time differed"); | ||
Assert.AreEqual(now.Minute, bnow.Minute, "Time differed"); | Assert.AreEqual(now.Minute, bnow.Minute, "Time differed"); | ||
Assert.AreEqual(now.Second, bnow.Second, "Time differed"); | Assert.AreEqual(now.Second, bnow.Second, "Time differed"); | ||
Assert.AreEqual(now.Millisecond, bnow.Millisecond, "Time differed"); | Assert.AreEqual(now.Millisecond, bnow.Millisecond, "Time differed"); | ||
} | } | ||
} | } | ||
} | } |
Oops, something went wrong.