Browse Source
Implemented CSHARP-307. Insert, InsertBatch and Save now throw a more appropriate exception when passed a null document.
pull/66/merge
Implemented CSHARP-307. Insert, InsertBatch and Save now throw a more appropriate exception when passed a null document.
pull/66/merge

3 changed files with 90 additions and 0 deletions
-
21Driver/Core/MongoCollection.cs
-
1DriverOnlineTests/DriverOnlineTests.csproj
-
68DriverOnlineTests/Jira/CSharp307Tests.cs
@ -0,0 +1,68 @@ |
|||
/* Copyright 2010-2011 10gen Inc. |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using NUnit.Framework; |
|||
|
|||
using MongoDB.Bson; |
|||
using MongoDB.Driver; |
|||
using MongoDB.Driver.Builders; |
|||
|
|||
namespace MongoDB.DriverOnlineTests.Jira { |
|||
[TestFixture] |
|||
public class CSharp307Tests { |
|||
private MongoServer server; |
|||
private MongoDatabase database; |
|||
private MongoCollection<BsonDocument> collection; |
|||
|
|||
[TestFixtureSetUp] |
|||
public void TestFixtureSetup() { |
|||
server = MongoServer.Create("mongodb://localhost/?safe=true"); |
|||
database = server["onlinetests"]; |
|||
collection = database["testcollection"]; |
|||
collection.Drop(); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestInsertNullDocument() { |
|||
BsonDocument document = null; |
|||
var ex = Assert.Catch<ArgumentNullException>(() => collection.Insert(document)); |
|||
Assert.AreEqual("document", ex.ParamName); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestInsertNullBatch() { |
|||
BsonDocument[] batch = null; |
|||
var ex = Assert.Catch<ArgumentNullException>(() => collection.InsertBatch(batch)); |
|||
Assert.AreEqual("documents", ex.ParamName); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestInsertBatchWithNullDocument() { |
|||
BsonDocument[] batch = new BsonDocument[] { null }; |
|||
Assert.Throws<ArgumentException>(() => collection.InsertBatch(batch), "Batch contains one or more null documents."); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestSaveNullDocument() { |
|||
BsonDocument document = null; |
|||
var ex = Assert.Catch<ArgumentNullException>(() => collection.Save(document)); |
|||
Assert.AreEqual("document", ex.ParamName); |
|||
} |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue