Skip to content

Commit bc9e75f

Browse files
committed
Fix tests that fail if database has not already been created.
1 parent ab4874d commit bc9e75f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

tests/MongoDB.Driver.Legacy.Tests/Linq/ExplainTests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public ExplainTests()
4444
[Fact]
4545
public void TestExplainFromLinqQueryEqualsExplainFromCursor()
4646
{
47+
EnsureCollectionExists();
4748
var linqExplain = _collection.AsQueryable<C>().Where(c => c.X == 2 && c.Y == 1).Take(1).Explain();
4849
var queryExplain = _collection.FindAs<C>(Query.And(Query.EQ("X", 2), Query.EQ("Y", 1))).SetLimit(1).Explain();
4950

@@ -63,6 +64,7 @@ public void TestExplainFromLinqQueryEqualsExplainFromCursor()
6364
[Fact]
6465
public void TestVerboseExplainFromLinqQueryEqualsVerboseExplainFromCursor()
6566
{
67+
EnsureCollectionExists();
6668
var linqExplain = _collection.AsQueryable<C>().Where(c => c.X == 2 && c.Y == 1).Take(1).Explain(true);
6769
var queryExplain = _collection.FindAs<C>(Query.And(Query.EQ("X", 2), Query.EQ("Y", 1))).SetLimit(1).Explain(true);
6870

@@ -82,6 +84,7 @@ public void TestVerboseExplainFromLinqQueryEqualsVerboseExplainFromCursor()
8284
[Fact]
8385
public void TestDistinctQueryCannotBeExplained()
8486
{
87+
EnsureCollectionExists();
8588
Assert.Throws<NotSupportedException>(()=> _collection.AsQueryable<C>().Select(c=>c.X).Distinct().Explain());
8689
}
8790

@@ -91,6 +94,13 @@ public void TestTakeZeroQueriesCannotBeExplained()
9194
Assert.Throws<NotSupportedException>(() => _collection.AsQueryable<C>().Take(0).Explain());
9295
}
9396

97+
// private methods
98+
private void EnsureCollectionExists()
99+
{
100+
var document = new BsonDocument("x", 1);
101+
_collection.Insert(document);
102+
}
103+
94104
private void RemoveMatchingElements(BsonValue value, Regex regex)
95105
{
96106
if (value.BsonType == BsonType.Document)

0 commit comments

Comments
 (0)