forked from samus/mongodb-csharp
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
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 | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,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); | ||
|
||
} | ||
|
||
} | ||
} | ||
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); | ||
|
||
} | ||
|
||
} | ||
} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,48 @@ | ||
/* | ||
* User: scorder | ||
*/ | ||
|
||
using System; | ||
using NUnit.Framework; | ||
|
||
namespace MongoDB.Driver.Bson | ||
{ | ||
[TestFixture] | ||
public class TestBsonDate | ||
{ | ||
[Test] | ||
public void TestPosixEpochConvertsTo1_1_1970(){ | ||
long epoch = 0; | ||
BsonDate bepoch = new BsonDate(epoch); | ||
Assert.AreEqual(0, bepoch.Val); | ||
} | ||
[Test] | ||
public void TestNet1_1_1970IsZero(){ | ||
DateTime nepoch = new DateTime(1970,1,1,0,0,0,DateTimeKind.Utc); | ||
BsonDate bd = new BsonDate(nepoch); | ||
Assert.AreEqual(0, bd.Val); | ||
} | ||
|
||
[Test] | ||
public void TestConversionOfNow(){ | ||
BsonDate bd1 = new BsonDate(DateTime.Now); | ||
BsonDate bd2 = new BsonDate(bd1.Val); | ||
Assert.AreEqual(bd1.Val, bd2.Val, "Dates weren't the same value."); | ||
|
||
} | ||
[Test] | ||
public void TestToNative(){ | ||
DateTime now = DateTime.Now.ToUniversalTime(); | ||
BsonDate bd = new BsonDate(now); | ||
DateTime bnow = (DateTime)bd.ToNative(); | ||
Assert.AreEqual(now.Date,bnow.Date, "Native conversion of date failed."); | ||
|
||
//.Net uses fractional milliseconds so there is a precision loss. | ||
//Just test the hour, minute, second, and milliseconds | ||
Assert.AreEqual(now.Hour, bnow.Hour, "Time differed"); | ||
Assert.AreEqual(now.Minute, bnow.Minute, "Time differed"); | ||
Assert.AreEqual(now.Second, bnow.Second, "Time differed"); | ||
Assert.AreEqual(now.Millisecond, bnow.Millisecond, "Time differed"); | ||
} | ||
} | ||
} | ||
/* | ||
* User: scorder | ||
*/ | ||
|
||
using System; | ||
using NUnit.Framework; | ||
|
||
namespace MongoDB.Driver.Bson | ||
{ | ||
[TestFixture] | ||
public class TestBsonDate | ||
{ | ||
[Test] | ||
public void TestPosixEpochConvertsTo1_1_1970(){ | ||
long epoch = 0; | ||
BsonDate bepoch = new BsonDate(epoch); | ||
Assert.AreEqual(0, bepoch.Val); | ||
} | ||
[Test] | ||
public void TestNet1_1_1970IsZero(){ | ||
DateTime nepoch = new DateTime(1970,1,1,0,0,0,DateTimeKind.Utc); | ||
BsonDate bd = new BsonDate(nepoch); | ||
Assert.AreEqual(0, bd.Val); | ||
} | ||
|
||
[Test] | ||
public void TestConversionOfNow(){ | ||
BsonDate bd1 = new BsonDate(DateTime.Now); | ||
BsonDate bd2 = new BsonDate(bd1.Val); | ||
Assert.AreEqual(bd1.Val, bd2.Val, "Dates weren't the same value."); | ||
|
||
} | ||
[Test] | ||
public void TestToNative(){ | ||
DateTime now = DateTime.Now.ToUniversalTime(); | ||
BsonDate bd = new BsonDate(now); | ||
DateTime bnow = (DateTime)bd.ToNative(); | ||
Assert.AreEqual(now.Date,bnow.Date, "Native conversion of date failed."); | ||
|
||
//.Net uses fractional milliseconds so there is a precision loss. | ||
//Just test the hour, minute, second, and milliseconds | ||
Assert.AreEqual(now.Hour, bnow.Hour, "Time differed"); | ||
Assert.AreEqual(now.Minute, bnow.Minute, "Time differed"); | ||
Assert.AreEqual(now.Second, bnow.Second, "Time differed"); | ||
Assert.AreEqual(now.Millisecond, bnow.Millisecond, "Time differed"); | ||
} | ||
} | ||
} |
Oops, something went wrong.