forked from samus/mongodb-csharp
/
TestDatabaseMetaData.cs
97 lines (72 loc) · 3.16 KB
/
TestDatabaseMetaData.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
using System;
using System.Collections.Generic;
using NUnit.Framework;
namespace MongoDB.Driver
{
[TestFixture]
public class TestDatabaseMetaData
{
Mongo db = new Mongo();
[Test]
public void TestCreateCollectionNoOptions(){
Database tests = db["tests"];
tests.MetaData.CreateCollection("creatednoopts");
List<String> names = tests.GetCollectionNames();
Assert.IsTrue(names.Contains("tests.creatednoopts"));
}
[Test]
public void TestCreateCollectionWithOptions(){
Database tests = db["tests"];
Document options = new Document().Append("capped",true).Append("size",10000);
tests.MetaData.CreateCollection("createdcapped",options);
List<String> names = tests.GetCollectionNames();
Assert.IsTrue(names.Contains("tests.createdcapped"));
}
[Test]
public void TestCreateCollectionWithInvalidOptions(){
Database tests = db["tests"];
Document options = new Document().Append("invalidoption",true);
tests.MetaData.CreateCollection("createdinvalid",options);
List<String> names = tests.GetCollectionNames();
Assert.IsTrue(names.Contains("tests.createdinvalid"));
}
[Test]
public void TestDropCollection(){
Database tests = db["tests"];
bool dropped = tests.MetaData.DropCollection("todrop");
Assert.IsTrue(dropped,"Dropped was false");
List<String> names = tests.GetCollectionNames();
Assert.IsFalse(names.Contains("tests.todrop"));
}
[Test]
public void TestDropInvalidCollection(){
Database tests = db["tests"];
bool thrown = false;
try{
tests.MetaData.DropCollection("todrop_notexists");
}catch(MongoCommandException){
thrown = true;
}
Assert.IsTrue(thrown,"Command exception should have been thrown");
List<String> names = tests.GetCollectionNames();
Assert.IsFalse(names.Contains("tests.todrop_notexists"));
}
[TestFixtureSetUp]
public void Init(){
db.Connect();
initDB();
}
[TestFixtureTearDown]
public void Dispose(){
db.Disconnect();
}
protected void initDB(){
//drop any previously created collections.
db["tests"]["$cmd"].FindOne(new Document().Append("drop","creatednoopts"));
db["tests"]["$cmd"].FindOne(new Document().Append("drop","createdcapped"));
db["tests"]["$cmd"].FindOne(new Document().Append("drop","createdinvalid"));
//Add any new ones to work on.
db["tests"]["$cmd"].FindOne(new Document().Append("create","todrop"));
}
}
}