-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added initial versions of select translator tests
- Loading branch information
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
...MongoFramework.Tests/Infrastructure/Linq/Translation/Translators/SelectTranslatorTests.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,57 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using MongoDB.Bson; | ||
using MongoFramework.Infrastructure.Linq.Translation.Translators; | ||
|
||
namespace MongoFramework.Tests.Infrastructure.Linq.Translation.Translators | ||
{ | ||
[TestClass] | ||
public class SelectorTranslatorTests : QueryTestBase | ||
{ | ||
[TestMethod] | ||
public void SelectProperty() | ||
{ | ||
var expression = GetExpression(q => q.Select(e => e.Id)); | ||
var result = new SelectTranslator().TranslateMethod(expression as MethodCallExpression); | ||
var expected = new BsonDocument | ||
{ | ||
{ | ||
"$project", | ||
new BsonDocument | ||
{ | ||
{ "Id", "$Id" }, | ||
{ "_id", 0 } | ||
} | ||
} | ||
}; | ||
|
||
Assert.AreEqual(expected, result); | ||
} | ||
|
||
|
||
[TestMethod] | ||
public void SelectNewAnonymousType() | ||
{ | ||
var expression = GetExpression(q => q.Select(e => new { CustomPropertyName = e.Id })); | ||
var result = new SelectTranslator().TranslateMethod(expression as MethodCallExpression); | ||
var expected = new BsonDocument | ||
{ | ||
{ | ||
"$project", | ||
new BsonDocument | ||
{ | ||
{ "CustomPropertyName", "Id" }, | ||
{ "_id", 0 } | ||
} | ||
} | ||
}; | ||
|
||
Assert.AreEqual(expected, result); | ||
} | ||
} | ||
} |