Browse Source

Implemented CSHARP-295. SetMaxDocuments now takes a long. Added some unit tests.

pull/66/merge
rstam 14 years ago
parent
commit
3b872aeeb9
  1. 4
      Driver/Builders/CollectionOptionsBuilder.cs
  2. 7
      Driver/Core/CommandResults/CollectionStatsResult.cs
  3. 38
      DriverOnlineTests/Core/MongoCollectionTests.cs
  4. 4
      DriverUnitTests/Builders/CollectionOptionsBuilderTests.cs

4
Driver/Builders/CollectionOptionsBuilder.cs

@ -67,7 +67,7 @@ namespace MongoDB.Driver.Builders {
/// <param name="value">The max number of documents.</param>
/// <returns>The builder (so method calls can be chained).</returns>
public static CollectionOptionsBuilder SetMaxDocuments(
int value
long value
) {
return new CollectionOptionsBuilder().SetMaxDocuments(value);
}
@ -142,7 +142,7 @@ namespace MongoDB.Driver.Builders {
/// <param name="value">The max number of documents.</param>
/// <returns>The builder (so method calls can be chained).</returns>
public CollectionOptionsBuilder SetMaxDocuments(
int value
long value
) {
document["max"] = value;
return this;

7
Driver/Core/CommandResults/CollectionStatsResult.cs

@ -102,6 +102,13 @@ namespace MongoDB.Driver {
get { return response["lastExtentSize"].ToInt64(); }
}
/// <summary>
/// Gets the index count.
/// </summary>
public long MaxDocuments {
get { return response["max", 0].AsInt32; }
}
/// <summary>
/// Gets the namespace.
/// </summary>

38
DriverOnlineTests/Core/MongoCollectionTests.cs

@ -71,6 +71,44 @@ namespace MongoDB.DriverOnlineTests {
Assert.AreEqual(1, count);
}
[Test]
public void TestCreateCollection() {
var collection = database["testcreatecollection"];
collection.Drop();
Assert.IsFalse(collection.Exists());
database.CreateCollection("testcreatecollection");
Assert.IsTrue(collection.Exists());
collection.Drop();
}
[Test]
public void TestCreateCollectionSetCappedSetMaxDocuments() {
var collection = database["testcreatecollection"];
collection.Drop();
Assert.IsFalse(collection.Exists());
var options = CollectionOptions.SetCapped(true).SetMaxDocuments(1000);
database.CreateCollection("testcreatecollection", options);
Assert.IsTrue(collection.Exists());
var stats = collection.GetStats();
Assert.IsTrue(stats.IsCapped);
Assert.IsTrue(stats.MaxDocuments == 1000);
collection.Drop();
}
[Test]
public void TestCreateCollectionSetCappedSetMaxSize() {
var collection = database["testcreatecollection"];
collection.Drop();
Assert.IsFalse(collection.Exists());
var options = CollectionOptions.SetCapped(true).SetMaxSize(10000000);
database.CreateCollection("testcreatecollection", options);
Assert.IsTrue(collection.Exists());
var stats = collection.GetStats();
Assert.IsTrue(stats.IsCapped);
Assert.IsTrue(stats.StorageSize >= 10000000);
collection.Drop();
}
[Test]
public void TestCreateIndex() {
collection.DropAllIndexes();

4
DriverUnitTests/Builders/CollectionOptionsBuilderTests.cs

@ -33,7 +33,7 @@ namespace MongoDB.DriverUnitTests.Builders {
.SetCapped(true)
.SetMaxDocuments(100)
.SetMaxSize(2000);
var expected = "{ 'autoIndexId' : true, 'capped' : true, 'max' : 100, 'size' : NumberLong(2000) }".Replace("'", "\"");
var expected = "{ 'autoIndexId' : true, 'capped' : true, 'max' : NumberLong(100), 'size' : NumberLong(2000) }".Replace("'", "\"");
Assert.AreEqual(expected, options.ToJson());
}
@ -68,7 +68,7 @@ namespace MongoDB.DriverUnitTests.Builders {
[Test]
public void TestSetMaxDocuments() {
var options = CollectionOptions.SetMaxDocuments(100);
var expected = "{ 'max' : 100 }".Replace("'", "\"");
var expected = "{ 'max' : NumberLong(100) }".Replace("'", "\"");
Assert.AreEqual(expected, options.ToJson());
}

Loading…
Cancel
Save