This repository has been archived by the owner on Dec 30, 2020. It is now read-only.
/
TestCollectionMetaData.cs
102 lines (87 loc) · 3.7 KB
/
TestCollectionMetaData.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using System;
using System.Collections.Generic;
using NUnit.Framework;
using MongoDB.Driver.Bson;
namespace MongoDB.Driver
{
[TestFixture]
public class TestCollectionMetaData : MongoTestBase
{
Database adminDb;
public override string TestCollections {
get {
return "indextests,rename,renamed";
}
}
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"));
its.Insert(createDoc("U","D","Newtown","OH"));
its.Insert(createDoc("J","E","Newport","KY"));
adminDb = DB.GetSisterDatabase("admin");
//adminDb.MetaData.AddUser(adminuser, adminpass);
}
public override void OnDispose (){
//adminDb.MetaData.RemoveUser(adminuser);
}
[Test]
public void TestGetOptions(){
CollectionMetaData cmd = DB["reads"].MetaData;
Document options = cmd.Options;
Assert.IsNotNull(options);
}
[Test]
public void TestGetIndexes(){
CollectionMetaData cmd = DB["indextests"].MetaData;
Dictionary<string, Document> indexes = cmd.Indexes;
Assert.IsNotNull(indexes);
Assert.IsTrue(indexes.Count > 0, "Should have been at least one index found.");
foreach(string key in indexes.Keys){
System.Console.WriteLine(String.Format("Key: {0} Value: {1}", key, indexes[key]));
}
}
[Test]
public void TestCreateIndex(){
CollectionMetaData cmd = DB["indextests"].MetaData;
cmd.CreateIndex("lastnames", new Document().Append("lname", IndexOrder.Ascending), false);
Dictionary<string, Document> indexes = cmd.Indexes;
Assert.IsNotNull(indexes["lastnames"]);
}
[Test]
public void TestCreateIndexNoNames(){
CollectionMetaData cmd = DB["indextests"].MetaData;
cmd.CreateIndex(new Document().Append("lname", IndexOrder.Ascending).Append("fname",IndexOrder.Ascending), true);
Dictionary<string, Document> indexes = cmd.Indexes;
Assert.IsNotNull(indexes["_lname_fname_unique_"]);
}
[Test]
public void TestDropIndex(){
CollectionMetaData cmd = DB["indextests"].MetaData;
cmd.CreateIndex("firstnames", new Document().Append("fname", IndexOrder.Ascending), false);
Dictionary<string, Document> indexes = cmd.Indexes;
Assert.IsNotNull(indexes["firstnames"]);
cmd.DropIndex("firstnames");
Assert.IsFalse(cmd.Indexes.ContainsKey("firstnames"));
}
[Test]
public void TestRename(){
DB["rename"].Insert(new Document(){{"test", "rename"}});
Assert.AreEqual(1, DB["rename"].Count());
CollectionMetaData cmd = DB["rename"].MetaData;
cmd.Rename("renamed");
Assert.IsFalse(DB.GetCollectionNames().Contains(DB.Name + ".rename"), "Shouldn't have found collection");
Assert.IsTrue(DB.GetCollectionNames().Contains(DB.Name + ".renamed"),"Should have found collection");
Assert.AreEqual(1, DB["renamed"].Count());
}
protected Document createDoc(string fname, string lname, string city, string state){
Document doc = new Document();
doc["fname"] = fname;
doc["lname"] = lname;
doc["city"] = city;
doc["state"] = state;
return doc;
}
}
}