Skip to content

Commit 9f8d37e

Browse files
author
rstam
committed
CSHARP-797: More unit tests.
1 parent d3f89f1 commit 9f8d37e

File tree

3 files changed

+801
-216
lines changed

3 files changed

+801
-216
lines changed

MongoDB.DriverUnitTests/Builders/QueryBuilderTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,12 @@ public class QueryBuilderTests
2929
{
3030
private MongoServer _server;
3131
private MongoDatabase _database;
32-
private MongoDatabase _adminDatabase;
3332
private MongoServerInstance _primary;
3433

3534
[TestFixtureSetUp]
3635
public void TestFixtureSetup()
3736
{
3837
_server = Configuration.TestServer;
39-
_adminDatabase = _server.GetDatabase("admin");
4038
_database = Configuration.TestDatabase;
4139
_primary = _server.Primary;
4240
}

MongoDB.DriverUnitTests/Builders/UpdateBuilderTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using System.Collections.Generic;
1818
using MongoDB.Bson;
1919
using MongoDB.Bson.Serialization.Attributes;
20+
using MongoDB.Driver;
2021
using MongoDB.Driver.Builders;
2122
using NUnit.Framework;
2223

@@ -69,11 +70,19 @@ private class C
6970
public int X = 0;
7071
}
7172

73+
private MongoCollection<BsonDocument> _collection;
74+
7275
private C _a = new C { X = 1 };
7376
private C _b = new C { X = 2 };
7477
private BsonDocument _docA1 = new BsonDocument("a", 1);
7578
private BsonDocument _docA2 = new BsonDocument("a", 2);
7679

80+
[TestFixtureSetUp]
81+
public void TestFixtureSetup()
82+
{
83+
_collection = Configuration.TestCollection;
84+
}
85+
7786
[Test]
7887
public void TestAddToSet()
7988
{
@@ -840,6 +849,18 @@ public void TestReplace()
840849
Assert.AreEqual(expected, update.ToJson());
841850
}
842851

852+
[Explicit]
853+
[Test]
854+
public void TestReplaceWithInvalidFieldName()
855+
{
856+
_collection.Drop();
857+
_collection.Insert(new BsonDocument { { "_id", 1 }, { "x", 1 } });
858+
859+
var query = Query.EQ("_id", 1);
860+
var update = Update.Replace(new BsonDocument { { "_id", 1 }, { "$x", 1 } });
861+
Assert.Throws<BsonSerializationException>(() => { _collection.Update(query, update); });
862+
}
863+
843864
[Test]
844865
public void TestReplace_Typed()
845866
{

0 commit comments

Comments
 (0)