generated from SwissLife-OSS/template
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added MongoDB Profiling Helpers (#63)
- Loading branch information
Showing
22 changed files
with
894 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using MongoDB.Driver; | ||
using Snapshooter.Xunit; | ||
using Squadron; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace MongoDB.Prime.Extensions.Tests | ||
{ | ||
public class FindFluentExtensionsTests : IClassFixture<MongoResource> | ||
{ | ||
private readonly IMongoDatabase _mongoDatabase; | ||
|
||
public FindFluentExtensionsTests(MongoResource mongoResource) | ||
{ | ||
_mongoDatabase = mongoResource.CreateDatabase(); | ||
} | ||
|
||
[Fact] | ||
public void PrintQuery_PrintOneSingleQuery_OriginalMongoDbQueryPrinted() | ||
{ | ||
// Arrange | ||
IMongoCollection<Bar> barCollection = | ||
_mongoDatabase.GetCollection<Bar>(); | ||
|
||
// Act | ||
string mongodbQuery = barCollection | ||
.Find<Bar>(bar => bar.Name == "Bar1" || bar.Id == "1234") | ||
.Limit(5) | ||
.PrintQuery(); | ||
|
||
// Assert | ||
Snapshot.Match(mongodbQuery); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace MongoDB.Prime.Extensions.Tests | ||
{ | ||
public class Bar | ||
{ | ||
public Bar(string name) | ||
{ | ||
Name = name; | ||
} | ||
|
||
public string Id { get; set; } | ||
|
||
public string Name { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace MongoDB.Prime.Extensions.Tests | ||
{ | ||
public class Foo | ||
{ | ||
public Foo(string name) | ||
{ | ||
Name = name; | ||
} | ||
|
||
public string Id { get; set; } | ||
public string Name { get; set; } | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/Prime.Extensions.Tests/MongoCollectionExtensionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using MongoDB.Driver; | ||
using Snapshooter.Xunit; | ||
using Squadron; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace MongoDB.Prime.Extensions.Tests | ||
{ | ||
public class MongoCollectionExtensionsTests : IClassFixture<MongoResource> | ||
{ | ||
private readonly IMongoDatabase _mongoDatabase; | ||
|
||
public MongoCollectionExtensionsTests(MongoResource mongoResource) | ||
{ | ||
_mongoDatabase = mongoResource.CreateDatabase(); | ||
} | ||
|
||
[Fact(Skip = "not ready yet.")] | ||
public async Task Explain_ExplainSingleQuery_SuccessfullyExplained() | ||
{ | ||
// Arrange | ||
IMongoCollection<Bar> barCollection = | ||
_mongoDatabase.GetCollection<Bar>(); | ||
|
||
FindOptions findOptions = new FindOptions | ||
{ | ||
Collation = new Collation( | ||
locale: "en", | ||
strength: CollationStrength.Secondary) | ||
}; | ||
|
||
FilterDefinition<Bar> filter = | ||
Builders<Bar>.Filter.And( | ||
Builders<Bar>.Filter.Eq(u => u.Id, "1234"), | ||
Builders<Bar>.Filter.Eq(b => b.Name, "NN")); | ||
|
||
// Act | ||
string? mongodbExplain = barCollection.Explain(filter, findOptions); | ||
|
||
// Assert | ||
Snapshot.Match(mongodbExplain); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...FindFluentExtensionsTests.PrintQuery_PrintOneSingleQuery_OriginalMongoDbQueryPrinted.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
find({ "$or" : [{ "Name" : "Bar1" }, { "_id" : "1234" }] }).limit(5) |
34 changes: 34 additions & 0 deletions
34
...onFindExtensionsTests.FindIds_FindDuplicatedBarIdsAsynchronously_ReturnsDistinctBars.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[ | ||
{ | ||
"Key": "a1c9e3e8-b448-42da-a684-716932903041", | ||
"Value": { | ||
"Id": "a1c9e3e8-b448-42da-a684-716932903041", | ||
"Name": "Bar1", | ||
"Value": "Value1" | ||
} | ||
}, | ||
{ | ||
"Key": "a1c9e3e8-b448-42da-a684-716932903044", | ||
"Value": { | ||
"Id": "a1c9e3e8-b448-42da-a684-716932903044", | ||
"Name": "Bar4", | ||
"Value": "Value4" | ||
} | ||
}, | ||
{ | ||
"Key": "a1c9e3e8-b448-42da-a684-716932903046", | ||
"Value": { | ||
"Id": "a1c9e3e8-b448-42da-a684-716932903046", | ||
"Name": "Bar6", | ||
"Value": "Value6" | ||
} | ||
}, | ||
{ | ||
"Key": "a1c9e3e8-b448-42da-a684-716932903047", | ||
"Value": { | ||
"Id": "a1c9e3e8-b448-42da-a684-716932903047", | ||
"Name": "Bar7", | ||
"Value": "Value7" | ||
} | ||
} | ||
] |
26 changes: 26 additions & 0 deletions
26
...ionFindExtensionsTests.FindIds_FindDuplicatedBarIdsSynchronously_ReturnsDistinctBars.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[ | ||
{ | ||
"Key": "a1c9e3e8-b448-42da-a684-716932903041", | ||
"Value": { | ||
"Id": "a1c9e3e8-b448-42da-a684-716932903041", | ||
"Name": "Bar1", | ||
"Value": "Value1" | ||
} | ||
}, | ||
{ | ||
"Key": "a1c9e3e8-b448-42da-a684-716932903044", | ||
"Value": { | ||
"Id": "a1c9e3e8-b448-42da-a684-716932903044", | ||
"Name": "Bar4", | ||
"Value": "Value4" | ||
} | ||
}, | ||
{ | ||
"Key": "a1c9e3e8-b448-42da-a684-716932903046", | ||
"Value": { | ||
"Id": "a1c9e3e8-b448-42da-a684-716932903046", | ||
"Name": "Bar6", | ||
"Value": "Value6" | ||
} | ||
} | ||
] |
34 changes: 34 additions & 0 deletions
34
...oCollectionFindExtensionsTests.FindIds_FindFourBarIdsAsynchronously_ReturnsRightBars.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[ | ||
{ | ||
"Key": "a1c9e3e8-b448-42da-a684-716932903043", | ||
"Value": { | ||
"Id": "a1c9e3e8-b448-42da-a684-716932903043", | ||
"Name": "Bar3", | ||
"Value": "Value3" | ||
} | ||
}, | ||
{ | ||
"Key": "a1c9e3e8-b448-42da-a684-716932903044", | ||
"Value": { | ||
"Id": "a1c9e3e8-b448-42da-a684-716932903044", | ||
"Name": "Bar4", | ||
"Value": "Value4" | ||
} | ||
}, | ||
{ | ||
"Key": "a1c9e3e8-b448-42da-a684-716932903045", | ||
"Value": { | ||
"Id": "a1c9e3e8-b448-42da-a684-716932903045", | ||
"Name": "Bar5", | ||
"Value": "Value5" | ||
} | ||
}, | ||
{ | ||
"Key": "a1c9e3e8-b448-42da-a684-716932903046", | ||
"Value": { | ||
"Id": "a1c9e3e8-b448-42da-a684-716932903046", | ||
"Name": "Bar6", | ||
"Value": "Value6" | ||
} | ||
} | ||
] |
34 changes: 34 additions & 0 deletions
34
...goCollectionFindExtensionsTests.FindIds_FindFourBarIdsSynchronously_ReturnsRightBars.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[ | ||
{ | ||
"Key": "a1c9e3e8-b448-42da-a684-716932903043", | ||
"Value": { | ||
"Id": "a1c9e3e8-b448-42da-a684-716932903043", | ||
"Name": "Bar3", | ||
"Value": "Value3" | ||
} | ||
}, | ||
{ | ||
"Key": "a1c9e3e8-b448-42da-a684-716932903044", | ||
"Value": { | ||
"Id": "a1c9e3e8-b448-42da-a684-716932903044", | ||
"Name": "Bar4", | ||
"Value": "Value4" | ||
} | ||
}, | ||
{ | ||
"Key": "a1c9e3e8-b448-42da-a684-716932903045", | ||
"Value": { | ||
"Id": "a1c9e3e8-b448-42da-a684-716932903045", | ||
"Name": "Bar5", | ||
"Value": "Value5" | ||
} | ||
}, | ||
{ | ||
"Key": "a1c9e3e8-b448-42da-a684-716932903046", | ||
"Value": { | ||
"Id": "a1c9e3e8-b448-42da-a684-716932903046", | ||
"Name": "Bar6", | ||
"Value": "Value6" | ||
} | ||
} | ||
] |
Oops, something went wrong.