Skip to content

Commit 8be8f88

Browse files
author
rstam
committed
CSHARP-943: Added more unit tests.
1 parent 5064821 commit 8be8f88

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

MongoDB.DriverUnitTests/MongoCollectionTests.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2178,10 +2178,12 @@ public void TestInsertBatchSmallFinalSubbatch()
21782178
[TestCase(1)]
21792179
public void TestInsertBatchSplittingNearMaxWriteBatchCount(int maxBatchCountDelta)
21802180
{
2181+
var count = _primary.MaxBatchCount + maxBatchCountDelta;
21812182
_collection.Drop();
2182-
var documents = Enumerable.Range(0, _primary.MaxBatchCount + maxBatchCountDelta).Select(n => new BsonDocument("n", n));
2183+
var documents = Enumerable.Range(0, count).Select(n => new BsonDocument("n", n));
21832184
var result = _collection.InsertBatch(documents);
21842185
Assert.AreEqual(1, result.Count()); // it's either one OP_INSERT batch or one consolidated result if emulated
2186+
Assert.AreEqual(count, _collection.Count());
21852187
}
21862188

21872189
[Test]

MongoDB.DriverUnitTests/Operations/BulkWriteOperationTests.cs

+62
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,68 @@ public void TestBatchSplittingBySizeWithErrorsUnordered()
115115
Assert.That(_collection.FindAll(), Is.EquivalentTo(expectedDocuments));
116116
}
117117

118+
[TestCase(-1)]
119+
[TestCase(0)]
120+
[TestCase(1)]
121+
public void TestBatchSplittingDeletesNearMaxWriteBatchCount(int maxBatchCountDelta)
122+
{
123+
var count = _primary.MaxBatchCount + maxBatchCountDelta;
124+
_collection.Drop();
125+
_collection.InsertBatch(Enumerable.Range(0, count).Select(n => new BsonDocument("n", n)));
126+
127+
var result = _collection.BulkWrite(new BulkWriteArgs
128+
{
129+
Requests = Enumerable.Range(0, count).Select(n => (WriteRequest)new DeleteRequest(Query.EQ("n", n)))
130+
});
131+
132+
Assert.AreEqual(count, result.DeletedCount);
133+
Assert.AreEqual(0, _collection.Count());
134+
}
135+
136+
[TestCase(-1)]
137+
[TestCase(0)]
138+
[TestCase(1)]
139+
public void TestBatchSplittingInsertsNearMaxWriteBatchCount(int maxBatchCountDelta)
140+
{
141+
var count = _primary.MaxBatchCount + maxBatchCountDelta;
142+
_collection.Drop();
143+
144+
var result = _collection.BulkWrite(new BulkWriteArgs
145+
{
146+
Requests = Enumerable.Range(0, count).Select(n => (WriteRequest)new InsertRequest(typeof(BsonDocument), new BsonDocument("n", n)))
147+
});
148+
149+
Assert.AreEqual(count, result.InsertedCount);
150+
Assert.AreEqual(count, _collection.Count());
151+
}
152+
153+
[TestCase(-1)]
154+
[TestCase(0)]
155+
[TestCase(1)]
156+
public void TestBatchSplittingUpdatesNearMaxWriteBatchCount(int maxBatchCountDelta)
157+
{
158+
var count = _primary.MaxBatchCount + maxBatchCountDelta;
159+
_collection.Drop();
160+
_collection.InsertBatch(Enumerable.Range(0, count).Select(n => new BsonDocument("n", n)));
161+
162+
var result = _collection.BulkWrite(new BulkWriteArgs
163+
{
164+
Requests = Enumerable.Range(0, count).Select(n => (WriteRequest)new UpdateRequest(Query.EQ("n", n), Update.Set("n", -1)))
165+
});
166+
167+
if (_primary.Supports(FeatureId.WriteCommands))
168+
{
169+
Assert.AreEqual(true, result.IsModifiedCountAvailable);
170+
Assert.AreEqual(count, result.ModifiedCount);
171+
}
172+
else
173+
{
174+
Assert.AreEqual(false, result.IsModifiedCountAvailable);
175+
}
176+
Assert.AreEqual(count, _collection.Count());
177+
Assert.AreEqual(count, _collection.Count(Query.EQ("n", -1)));
178+
}
179+
118180
[Test]
119181
[TestCase(false)]
120182
[TestCase(true)]

0 commit comments

Comments
 (0)