Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merged authentication code from Seth Edwards
  • Loading branch information
samus committed Sep 15, 2009
1 parent f648d7e commit 06e5fc2
Show file tree
Hide file tree
Showing 55 changed files with 3,628 additions and 49,991 deletions.
120 changes: 60 additions & 60 deletions MongoDB.Net-Tests/Bson/TestBsonConvert.cs
@@ -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);

}

}
}
96 changes: 48 additions & 48 deletions MongoDB.Net-Tests/Bson/TestBsonDate.cs
@@ -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");
}
}
}

0 comments on commit 06e5fc2

Please sign in to comment.