Skip to content

Commit 43a73db

Browse files
author
Sridhar Nanjundeswaran
committed
Fix unit tests that are failing due to order of results from server. also enhance test to clearly show secondary sort
1 parent cf75794 commit 43a73db

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

MongoDB.DriverUnitTests/Builders/SortByBuilderTests.cs

+12-12
Original file line numberDiff line numberDiff line change
@@ -109,25 +109,25 @@ public void TestMetaText()
109109
{
110110
{ "_id", 3 },
111111
{ "textfield", "over the lazy brown dog and brown cat" },
112+
{ "z", 4 }
113+
});
114+
collection.Insert(new BsonDocument
115+
{
116+
{ "_id", 4 },
117+
{ "textfield", "over the lazy brown dog and brown cat" },
112118
{ "z", 3 }
113119
});
114120

115121
var query = Query.Text("brown");
116122
var fields = Fields.MetaText("relevance");
117-
var cursor = collection.FindAs<BsonDocument>(query).SetFields(fields);
118-
var result = cursor.ToArray();
119-
Assert.AreEqual(3, result.Length);
120-
Assert.AreEqual(1, result[0]["_id"].AsInt32);
121-
Assert.AreEqual(2, result[1]["_id"].AsInt32);
122-
Assert.AreEqual(3, result[2]["_id"].AsInt32);
123-
124123
var sortBy = SortBy.MetaText("relevance").Descending("z");
125-
cursor = collection.FindAs<BsonDocument>(query).SetFields(fields).SetSortOrder(sortBy);
126-
result = cursor.ToArray();
127-
Assert.AreEqual(3, result.Length);
124+
var cursor = collection.FindAs<BsonDocument>(query).SetFields(fields).SetSortOrder(sortBy);
125+
var result = cursor.ToArray();
126+
Assert.AreEqual(4, result.Length);
128127
Assert.AreEqual(3, result[0]["_id"].AsInt32);
129-
Assert.AreEqual(2, result[1]["_id"].AsInt32);
130-
Assert.AreEqual(1, result[2]["_id"].AsInt32);
128+
Assert.AreEqual(4, result[1]["_id"].AsInt32);
129+
Assert.AreEqual(2, result[2]["_id"].AsInt32);
130+
Assert.AreEqual(1, result[3]["_id"].AsInt32);
131131
}
132132
}
133133
}

MongoDB.DriverUnitTests/Builders/SortByBuilderTypedTests.cs

+12-12
Original file line numberDiff line numberDiff line change
@@ -138,25 +138,25 @@ public void TestMetaText()
138138
{
139139
Id = 3,
140140
T = "over the lazy brown dog and brown cat",
141+
z = 4
142+
});
143+
collection.Insert(new Test
144+
{
145+
Id = 4,
146+
T = "over the lazy brown dog and brown cat",
141147
z = 3
142148
});
143149

144150
var query = Query.Text("brown");
145151
var fields = Fields<Test>.MetaText(y => y.R);
146-
var cursor = collection.FindAs<BsonDocument>(query).SetFields(fields);
147-
var result = cursor.ToArray();
148-
Assert.AreEqual(3, result.Length);
149-
Assert.AreEqual(1, result[0]["_id"].AsInt32);
150-
Assert.AreEqual(2, result[1]["_id"].AsInt32);
151-
Assert.AreEqual(3, result[2]["_id"].AsInt32);
152-
153152
var sortBy = SortBy<Test>.MetaText(y => y.R).Descending(y => y.z);
154-
cursor = collection.FindAs<BsonDocument>(query).SetFields(fields).SetSortOrder(sortBy);
155-
result = cursor.ToArray();
156-
Assert.AreEqual(3, result.Length);
153+
var cursor = collection.FindAs<BsonDocument>(query).SetFields(fields).SetSortOrder(sortBy);
154+
var result = cursor.ToArray();
155+
Assert.AreEqual(4, result.Length);
157156
Assert.AreEqual(3, result[0]["_id"].AsInt32);
158-
Assert.AreEqual(2, result[1]["_id"].AsInt32);
159-
Assert.AreEqual(1, result[2]["_id"].AsInt32);
157+
Assert.AreEqual(4, result[1]["_id"].AsInt32);
158+
Assert.AreEqual(2, result[2]["_id"].AsInt32);
159+
Assert.AreEqual(1, result[3]["_id"].AsInt32);
160160
}
161161
}
162162
}

0 commit comments

Comments
 (0)