Permalink
Browse files

Fix #CSHARP-59 FindAndModify(object document, object spec, object sor…

…t) causes stack-overflow.
  • Loading branch information...
1 parent e8b3b74 commit 20fa57ec655fe0e54ccb734bddd19efd97eb2ee1 @lanwin lanwin committed Aug 27, 2010
Showing with 52 additions and 53 deletions.
  1. +51 −51 source/MongoDB.Tests/IntegrationTests/TestCollection.cs
  2. +1 −2 source/MongoDB/MongoCollection_1.cs
@@ -192,57 +192,57 @@ public void TestFindWhereEquivalency()
Assert.AreEqual(4, CountDocs(col.Find(explicitWhere)), "Explicit where didn't return 4 docs");
Assert.AreEqual(4, CountDocs(col.Find(funcDoc)), "Function where didn't return 4 docs");
}
-
- [Test]
- public void TestFindAndModifyReturnsOldDocument() {
- IMongoCollection collection = DB["find_and_modify"];
- Document person = new Document().Append("First", "Sally").Append("Last", "Simmons");
- collection.Insert(person);
-
- Document spec = new Document().Append("_id", person["_id"]);
- Document loaded = collection.FindAndModify(new Document().Append("First", "Jane"), spec);
-
- Assert.AreEqual("Sally", loaded["First"]);
- }
-
- [Test]
- public void TestFindAndModifyReturnsNewDocument() {
- IMongoCollection collection = DB["find_and_modify"];
- Document person = new Document().Append("First", "Susie").Append("Last", "O'Hara");
- collection.Insert(person);
-
- Document spec = new Document().Append("_id", person["_id"]);
- Document loaded = collection.FindAndModify(new Document().Append("First", "Darlene"), spec, true);
-
- Assert.AreEqual("Darlene", loaded["First"]);
- }
-
- [Test]
- public void TestFindAndModifySortsResults() {
- IMongoCollection collection = DB["find_and_modify"];
- Document doc1 = new Document().Append("handled", false).Append("priority", 1).Append("value", "Test 1");
- Document doc2 = new Document().Append("handled", false).Append("priority", 2).Append("value", "Test 2");
- collection.Insert(doc1);
- collection.Insert(doc2);
-
- Document update = new Document().Append("handled", true);
- Document spec = new Document().Append("handled", false);
- Document sort = new Document().Append("priority", -1);
- Document loaded = collection.FindAndModify(update, spec, sort, true);
-
- Assert.AreEqual(true, loaded["handled"]);
- Assert.AreEqual(doc2["priority"], loaded["priority"]);
- Assert.AreEqual(doc2["value"], loaded["value"]);
- }
-
- [Test]
- public void TestFindAndModifyReturnNullForNoRecordFound() {
- IMongoCollection collection = DB["find_and_modify"];
- Document spec = new Document().Append("FirstName", "Noone");
- Document loaded = collection.FindAndModify(new Document().Append("First", "Darlene"), spec, true);
-
- Assert.IsNull(loaded, "Should return null for no document found");
- }
+
+ [Test]
+ public void TestFindAndModifyReturnsOldDocument() {
+ IMongoCollection collection = DB["find_and_modify"];
+ Document person = new Document().Append("First", "Sally").Append("Last", "Simmons");
+ collection.Insert(person);
+
+ Document spec = new Document().Append("_id", person["_id"]);
+ Document loaded = collection.FindAndModify(new Document().Append("First", "Jane"), spec);
+
+ Assert.AreEqual("Sally", loaded["First"]);
+ }
+
+ [Test]
+ public void TestFindAndModifyReturnsNewDocument() {
+ IMongoCollection collection = DB["find_and_modify"];
+ Document person = new Document().Append("First", "Susie").Append("Last", "O'Hara");
+ collection.Insert(person);
+
+ Document spec = new Document().Append("_id", person["_id"]);
+ Document loaded = collection.FindAndModify(new Document().Append("First", "Darlene"), spec, true);
+
+ Assert.AreEqual("Darlene", loaded["First"]);
+ }
+
+ [Test]
+ public void TestFindAndModifySortsResults() {
+ IMongoCollection collection = DB["find_and_modify"];
+ Document doc1 = new Document().Append("handled", false).Append("priority", 1).Append("value", "Test 1");
+ Document doc2 = new Document().Append("handled", false).Append("priority", 2).Append("value", "Test 2");
+ collection.Insert(doc1);
+ collection.Insert(doc2);
+
+ Document update = new Document().Append("handled", true);
+ Document spec = new Document().Append("handled", false);
+ Document sort = new Document().Append("priority", -1);
+ Document loaded = collection.FindAndModify(update, spec, sort, true);
+
+ Assert.AreEqual(true, loaded["handled"]);
+ Assert.AreEqual(doc2["priority"], loaded["priority"]);
+ Assert.AreEqual(doc2["value"], loaded["value"]);
+ }
+
+ [Test]
+ public void TestFindAndModifyReturnNullForNoRecordFound() {
+ IMongoCollection collection = DB["find_and_modify"];
+ Document spec = new Document().Append("FirstName", "Noone");
+ Document loaded = collection.FindAndModify(new Document().Append("First", "Darlene"), spec, true);
+
+ Assert.IsNull(loaded, "Should return null for no document found");
+ }
[Test]
public void TestInsertBulkLargerThan4MBOfDocuments()
@@ -7,7 +7,6 @@
using MongoDB.Protocol;
using MongoDB.Results;
using MongoDB.Util;
-using MongoDB.Configuration.Mapping.Model;
namespace MongoDB
{
@@ -183,7 +182,7 @@ public T FindOne(string javascriptWhere)
/// <returns>A <see cref="Document"/></returns>
/// <see cref="IndexOrder"/>
public T FindAndModify(object document, object spec, object sort){
- return FindAndModify(document, spec, sort);
+ return FindAndModify(document, spec, sort, false);
}
/// <summary>

0 comments on commit 20fa57e

Please sign in to comment.