コード例 #1
0
        public void TestBatchSplittingBySizeWithErrorsOrdered()
        {
            _collection.Drop();

            var documents = new BsonDocument[8];
            for (var i = 0; i < 6; i++)
            {
                documents[i] = new BsonDocument { { "_id", i }, { "a", new string('x', 4 * 1024 * 1024) } };
            }
            documents[6] = new BsonDocument("_id", 0); // will fail
            documents[7] = new BsonDocument("_id", 100);

            var bulk = _collection.InitializeOrderedBulkOperation();
            for (var i = 0; i < 8; i++)
            {
                bulk.Insert(documents[i]);
            }
            var exception = Assert.Throws<BulkWriteException>(() => { bulk.Execute(); });
            var result = exception.Result;

            Assert.IsNull(exception.WriteConcernError);
            Assert.AreEqual(1, exception.WriteErrors.Count);
            var writeError = exception.WriteErrors[0];
            Assert.AreEqual(6, writeError.Index);
            Assert.AreEqual(11000, writeError.Code);

            var expectedResult = new ExpectedResult
            {
                InsertedCount = 6,
                ProcessedRequestsCount = 7,
                RequestCount = 8
            };
            CheckExpectedResult(expectedResult, result);

            var expectedDocuments = documents.Take(6);
            Assert.That(_collection.FindAll(), Is.EqualTo(expectedDocuments));
        }