Permalink
Browse files

Huge change. Refectored Collections to use generics but append still …

…Document overloads to show the user that he also can pass Documents here.
  • Loading branch information...
1 parent d0d0779 commit b6d2bd9cf0da7c90e80b3ab98d46d83b1a728a08 @lanwin lanwin committed Mar 12, 2010
View
@@ -12,14 +12,16 @@ public class GridFile{
public string Name {
get { return name; }
}
-
- private IMongoCollection files;
- public IMongoCollection Files{
+
+ private IMongoCollection<Document> files;
+ public IMongoCollection<Document> Files
+ {
get { return this.files; }
}
- private IMongoCollection chunks;
- public IMongoCollection Chunks{
+ private IMongoCollection<Document> chunks;
+ public IMongoCollection<Document> Chunks
+ {
get { return this.chunks; }
}
@@ -16,9 +16,9 @@ namespace MongoDB.GridFS
/// </remarks>
public class GridFileStream : Stream
{
-
- private IMongoCollection files;
- private IMongoCollection chunks;
+
+ private IMongoCollection<Document> files;
+ private IMongoCollection<Document> chunks;
private Document chunk;
private bool chunkDirty;
private long chunkLower = -1;
@@ -68,8 +68,9 @@ public class GridFileStream : Stream
}
}
#endregion
-
- public GridFileStream(GridFileInfo gridfileinfo,IMongoCollection files, IMongoCollection chunks, FileAccess access){
+
+ public GridFileStream(GridFileInfo gridfileinfo, IMongoCollection<Document> files, IMongoCollection<Document> chunks, FileAccess access)
+ {
switch (access){
case FileAccess.Read:
canRead = true;
@@ -11,13 +11,13 @@ namespace MongoDB.Linq.Tests {
public class TestMongoDocumentQuerySyntax {
private IMongoQuery queryable;
- private Mock<IMongoCollection> collectionMock;
+ private Mock<IMongoCollection<Document>> collectionMock;
private Mock<ICursor<Document>> cursorMock;
[SetUp]
public void Setup() {
Debug.WriteLine("initializing queryable");
- collectionMock = new Mock<IMongoCollection>();
+ collectionMock = new Mock<IMongoCollection<Document>>();
cursorMock = new Mock<ICursor<Document>>();
collectionMock.Setup(c => c.Find(It.IsAny<Document>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<Document>())).Returns(cursorMock.Object);
queryable = new MongoQuery(new MongoQueryProvider(collectionMock.Object));
@@ -11,13 +11,13 @@ namespace MongoDB.Linq.Tests {
public class TestQueryParsing {
private IMongoQuery queryable;
- private Mock<IMongoCollection> collectionMock;
+ private Mock<IMongoCollection<Document>> collectionMock;
private Mock<ICursor<Document>> cursorMock;
[SetUp]
public void Setup() {
Debug.WriteLine("initializing queryable");
- collectionMock = new Mock<IMongoCollection>();
+ collectionMock = new Mock<IMongoCollection<Document>>();
cursorMock = new Mock<ICursor<Document>>();
collectionMock.Setup(c => c.Find(It.IsAny<Document>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<Document>())).Returns(cursorMock.Object);
queryable = new MongoQuery(new MongoQueryProvider(collectionMock.Object));
@@ -5,7 +5,7 @@ namespace MongoDB.Linq
{
public static class MongoLinqEx
{
- public static IMongoQuery AsQueryable<T>(this T collection) where T : IMongoCollection
+ public static IMongoQuery AsQueryable<T>(this T collection) where T : IMongoCollection<Document>
{
return new MongoQuery(new MongoQueryProvider(collection));
}
@@ -13,9 +13,10 @@ private struct Result {
public bool IsFirstCall;
}
- private readonly IMongoCollection collection;
+ private readonly IMongoCollection<Document> collection;
- public MongoQueryProvider(IMongoCollection collection) {
+ public MongoQueryProvider(IMongoCollection<Document> collection)
+ {
this.collection = collection;
}
@@ -16,14 +16,14 @@ public class TestCollection : MongoTestBase
}
public override void OnInit (){
- IMongoCollection finds = DB["finds"];
+ IMongoCollection<Document> finds = DB["finds"];
for(int j = 1; j < 100; j++){
finds.Insert(new Document(){{"x", 4},{"h", "hi"},{"j", j}});
}
for(int j = 100; j < 105; j++){
finds.Insert(new Document(){{"x", 4},{"n", 1},{"j", j}});
}
- IMongoCollection charreads = DB["charreads"];
+ IMongoCollection<Document> charreads = DB["charreads"];
charreads.Insert(new Document(){{"test", "1234" + pound + "56"}});
}
@@ -95,7 +95,7 @@ public class TestCollection : MongoTestBase
}
[Test]
public void TestFindWhereEquivalency(){
- IMongoCollection col = DB["finds"];
+ IMongoCollection<Document> col = DB["finds"];
Document lt = new Document().Append("j", new Document().Append("$lt", 5));
string where = "this.j < 5";
Document explicitWhere = new Document().Append("$where", new Code(where));
@@ -137,7 +137,7 @@ private int CountDocs(ICursor<Document> cur)
[Test]
public void TestSimpleInsert(){
- IMongoCollection inserts = DB["inserts"];
+ IMongoCollection<Document> inserts = DB["inserts"];
Document indoc = new Document();
indoc["song"] = "Palmdale";
indoc["artist"] = "Afroman";
@@ -152,7 +152,7 @@ private int CountDocs(ICursor<Document> cur)
[Test]
public void TestReallySimpleInsert(){
- IMongoCollection inserts = DB["inserts"];
+ IMongoCollection<Document> inserts = DB["inserts"];
Document indoc = new Document();
indoc["y"] = 1;
indoc["x"] = 2;
@@ -165,7 +165,7 @@ private int CountDocs(ICursor<Document> cur)
[Test]
public void TestPoundSymbolInsert(){
- IMongoCollection inserts = DB["inserts"];
+ IMongoCollection<Document> inserts = DB["inserts"];
Document indoc = new Document().Append("x","1234" + pound + "56").Append("y",1);;
inserts.Insert(indoc);
@@ -176,7 +176,7 @@ private int CountDocs(ICursor<Document> cur)
[Test]
public void TestArrayInsert(){
- IMongoCollection inserts = DB["inserts"];
+ IMongoCollection<Document> inserts = DB["inserts"];
Document indoc1 = new Document();
indoc1["song"] = "The Axe";
indoc1["artist"] = "Tinsley Ellis";
@@ -201,7 +201,7 @@ private int CountDocs(ICursor<Document> cur)
[Test]
public void TestInsertOfArray(){
OidGenerator ogen = new OidGenerator();
- IMongoCollection inserts = DB["inserts"];
+ IMongoCollection<Document> inserts = DB["inserts"];
Document album = new Document();
album["_id"] = ogen.Generate();
album["artist"] = "Popa Chubby";
@@ -223,7 +223,7 @@ private int CountDocs(ICursor<Document> cur)
[Test]
public void TestDelete(){
- IMongoCollection deletes = DB["deletes"];
+ IMongoCollection<Document> deletes = DB["deletes"];
Document doc = new Document();
doc["y"] = 1;
doc["x"] = 2;
@@ -243,7 +243,7 @@ private int CountDocs(ICursor<Document> cur)
[Test]
public void TestUpdateUpsertNotExisting(){
- IMongoCollection updates = DB["updates"];
+ IMongoCollection<Document> updates = DB["updates"];
Document doc = new Document();
doc["First"] = "Sam";
doc["Last"] = "CorderNE";
@@ -257,7 +257,7 @@ private int CountDocs(ICursor<Document> cur)
[Test]
public void TestUpdateUpsertExisting(){
- IMongoCollection updates = DB["updates"];
+ IMongoCollection<Document> updates = DB["updates"];
Document doc = new Document();
doc["First"] = "Mtt";
doc["Last"] = "Brewer";
@@ -281,7 +281,7 @@ private int CountDocs(ICursor<Document> cur)
[Test]
public void TestUpdateMany(){
- IMongoCollection updates = DB["updates"];
+ IMongoCollection<Document> updates = DB["updates"];
updates.Insert(new Document().Append("Last", "Cordr").Append("First","Sam"));
updates.Insert(new Document().Append("Last", "Cordr").Append("First","Sam2"));
@@ -316,7 +316,7 @@ private int CountDocs(ICursor<Document> cur)
[Test]
public void TestCount(){
- IMongoCollection counts = DB["counts"];
+ IMongoCollection<Document> counts = DB["counts"];
int top = 100;
for(int i = 0; i < top; i++){
counts.Insert(new Document().Append("Last", "Cordr").Append("First","Sam").Append("cnt", i));
@@ -327,7 +327,7 @@ private int CountDocs(ICursor<Document> cur)
[Test]
public void TestCountWithSpec(){
- IMongoCollection counts = DB["counts_spec"];
+ IMongoCollection<Document> counts = DB["counts_spec"];
counts.Insert(new Document().Append("Last", "Cordr").Append("First","Sam").Append("cnt", 1));
counts.Insert(new Document().Append("Last", "Cordr").Append("First","Sam").Append("cnt", 2));
counts.Insert(new Document().Append("Last", "Corder").Append("First","Sam").Append("cnt", 3));
@@ -340,7 +340,7 @@ private int CountDocs(ICursor<Document> cur)
[Test]
public void TestCountInvalidCollection(){
- IMongoCollection counts = DB["counts_wtf"];
+ IMongoCollection<Document> counts = DB["counts_wtf"];
Assert.AreEqual(0, counts.Count());
}
}
@@ -17,8 +17,8 @@ public class TestCollectionMetaData : MongoTestBase
}
}
- public override void OnInit (){
- IMongoCollection its = DB["indextests"];
+ public override void OnInit (){
+ IMongoCollection<Document> its = DB["indextests"];
its.Insert(createDoc("S","A","Anderson","OH"));
its.Insert(createDoc("T","B","Delhi","OH"));
its.Insert(createDoc("F","B","Cincinnati","OH"));
@@ -17,8 +17,8 @@ public class TestCollectionSafeMode : MongoTestBase
[Test]
- public void TestBadInsert(){
- IMongoCollection col = InitCollection("safeinsert");
+ public void TestBadInsert(){
+ IMongoCollection<Document> col = InitCollection("safeinsert");
bool thrown = false;
try{
col.Insert(new Document {{"x",1},{"y",2}},true);
@@ -31,8 +31,8 @@ public class TestCollectionSafeMode : MongoTestBase
}
[Test]
- public void TestBadUpdate(){
- IMongoCollection col = InitCollection("safeupdate");
+ public void TestBadUpdate(){
+ IMongoCollection<Document> col = InitCollection("safeupdate");
bool thrown = false;
try{
col.Update(new Document {{"x", 1}}, new Document{{"x",2}},true);
@@ -48,8 +48,8 @@ public class TestCollectionSafeMode : MongoTestBase
}
[Test]
- public void TestMultiUpdate(){
- IMongoCollection col = InitCollection("safemupdate");
+ public void TestMultiUpdate(){
+ IMongoCollection<Document> col = InitCollection("safemupdate");
Document newy = new Document(){{"y", 2}};
col.UpdateAll(newy, new Document(){{"y",1}},true);
Assert.AreEqual(5, col.Count(newy));
@@ -66,10 +66,11 @@ public class TestCollectionSafeMode : MongoTestBase
Assert.Fail(String.Format("Wrong exception thrown: {0}", e.GetType().Name));
}
Assert.IsTrue(thrown, "Exception not thrown.");
- }
-
- protected IMongoCollection InitCollection(string name){
- IMongoCollection col = DB[name];
+ }
+
+ protected IMongoCollection<Document> InitCollection(string name)
+ {
+ IMongoCollection<Document> col = DB[name];
col.MetaData.CreateIndex(new Document{{"x", IndexOrder.Ascending}}, true);
for(int x = 0; x < 5; x++){
col.Insert(new Document{{"x", x}, {"y", 1}});
@@ -32,9 +32,9 @@ public class TestConcurrency :MongoTestBase
//[Test]
public void TestMultiThreadedWrites (){
Mongo db = new Mongo();
- db.Connect();
-
- IMongoCollection col = DB["threadinserts"];
+ db.Connect();
+
+ IMongoCollection<Document> col = DB["threadinserts"];
List<string> identifiers = new List<string>{"A", "B", "C", "D"};
List<Thread> threads = new List<Thread>();
@@ -89,9 +89,9 @@ public class TestConcurrency :MongoTestBase
[Test]
public void TestMultiThreadedReadsAndWrites(){
Mongo db = new Mongo();
- db.Connect();
-
- IMongoCollection col = DB["threadreadinserts"];
+ db.Connect();
+
+ IMongoCollection<Document> col = DB["threadreadinserts"];
List<string> identifiers = new List<string>{"A", "B", "C", "D"};
List<string> colnames = new List<string>{"threadsmallreads", "threadsmallreads",
@@ -146,8 +146,8 @@ public class TestConcurrency :MongoTestBase
public class Inserter{
public int Iterations{get; set;}
public int Count{get;set;}
- public String Identifier{get; set;}
- public IMongoCollection Collection{get; set;}
+ public String Identifier{get; set;}
+ public IMongoCollection<Document> Collection { get; set; }
public void DoInserts(){
for(int x = 0; x < this.Iterations; x++){
@@ -164,8 +164,8 @@ public class Inserter{
public class Reader{
public int Iterations{get; set;}
- public int Count{get;set;}
- public IMongoCollection Collection{get; set;}
+ public int Count{get;set;}
+ public IMongoCollection<Document> Collection { get; set; }
public void DoReads(){
for(int x = 0; x < this.Iterations; x++){
@@ -18,13 +18,13 @@ public class TestCursor : MongoTestBase
public override void OnInit (){
//smallreads
- IMongoCollection smallreads = DB["smallreads"];
+ IMongoCollection<Document> smallreads = DB["smallreads"];
for(int j = 1; j < 5; j++){
smallreads.Insert(new Document(){{"x", 4},{"j", j}});
}
smallreads.Insert(new Document(){{"x", 4}, {"j", 5}, {"n", 1}});
-
- IMongoCollection reads = DB["reads"];
+
+ IMongoCollection<Document> reads = DB["reads"];
for(int j = 1; j < 10000; j++){
reads.Insert(new Document(){{"x", 4},{"h", "hi"},{"j", j}});
}
@@ -95,7 +95,7 @@ public void TestCanReadAndKillCursor()
[Test]
public void TestSort(){
- IMongoCollection sorts = DB["sorts"];
+ IMongoCollection<Document> sorts = DB["sorts"];
int[] randoms = new int[]{4,6,8,9,1,3,2,5,7,0};
foreach(int x in randoms){
sorts.Insert(new Document().Append("x", randoms[x]));
@@ -125,7 +125,7 @@ public void TestCanReadAndKillCursor()
[Test]
public void TestHint(){
- IMongoCollection reads = DB["reads"];
+ IMongoCollection<Document> reads = DB["reads"];
Document hint = new Document().Append("x",IndexOrder.Ascending);
Document exp = reads.FindAll().Hint(hint).Explain();
Oops, something went wrong.

0 comments on commit b6d2bd9

Please sign in to comment.