Skip to content

Commit e70386a

Browse files
committed
Added TranslateInstantiation tests
1 parent edc471f commit e70386a

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

tests/MongoFramework.Tests/Infrastructure/Querying/ExpressionTranslationTests.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,5 +240,46 @@ public void TranslateConditional_ExternalConstants()
240240
};
241241
Assert.AreEqual(expected, result);
242242
}
243+
244+
[TestMethod]
245+
public void TranslateInstantiation_Anonymous()
246+
{
247+
var expression = GetTransform(e => new
248+
{
249+
e.Id,
250+
MyNumber = e.SingleNumber
251+
});
252+
var result = ExpressionTranslation.TranslateInstantiation(expression);
253+
var expected = new BsonDocument
254+
{
255+
{ "Id", "Id" },
256+
{ "MyNumber", "SingleNumber" }
257+
};
258+
Assert.AreEqual(expected, result);
259+
}
260+
261+
[TestMethod]
262+
public void TranslateInstantiation_RealType()
263+
{
264+
var expression = GetTransform(e => new QueryTestModel
265+
{
266+
Id = e.Id,
267+
SingleNumber = e.SingleNumber
268+
});
269+
var result = ExpressionTranslation.TranslateInstantiation(expression);
270+
var expected = new BsonDocument
271+
{
272+
{ "Id", "Id" },
273+
{ "SingleNumber", "SingleNumber" }
274+
};
275+
Assert.AreEqual(expected, result);
276+
}
277+
278+
[TestMethod, ExpectedException(typeof(ArgumentException))]
279+
public void TranslateInstantiation_InvalidExpression()
280+
{
281+
var expression = GetTransform(e => e.SingleNumber);
282+
ExpressionTranslation.TranslateInstantiation(expression);
283+
}
243284
}
244285
}

tests/MongoFramework.Tests/Infrastructure/Querying/QueryTestBase.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,10 @@ protected static Expression GetConditional(Expression<Func<QueryTestModel, bool>
3939
{
4040
return ExpressionTranslation.UnwrapLambda(expression);
4141
}
42+
43+
protected static Expression GetTransform<TResult>(Expression<Func<QueryTestModel, TResult>> expression)
44+
{
45+
return ExpressionTranslation.UnwrapLambda(expression);
46+
}
4247
}
4348
}

0 commit comments

Comments
 (0)