Skip to content

Commit

Permalink
Added initial versions of select translator tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Turnerj committed Dec 17, 2020
1 parent c6670c1 commit 9713d20
Showing 1 changed file with 57 additions and 0 deletions.
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);
}
}
}

0 comments on commit 9713d20

Please sign in to comment.