using Masuit.Tools.Mapping; using Masuit.Tools.Mapping.Extensions; using Masuit.Tools.UnitTest.Mapping.ClassTests; using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Linq; using System.Linq.Expressions; namespace Masuit.Tools.UnitTest.Mapping.Extentions { [TestClass] public class QueryableExtentionsTest { [ClassInitialize] public static void Init(TestContext context) { Clean(); ExpressionMapper.CreateMap().ForMember(s => s.PropString1, d => d.PropString2).ReverseMap(); ExpressionMapper.Initialize(); } [ClassCleanup] public static void Clean() { ExpressionMapper.Reset(); } [TestMethod, TestCategory("Extentions")] public void OrderBy_Success() { Init(null); QueryableImplTest expected = new QueryableImplTest(); IQueryable actual = expected.OrderBy("PropInt1"); Assert.IsTrue(CheckExpressionMethod(actual.Expression, nameof(QueryableExtentions.OrderBy))); } [TestMethod, TestCategory("Extentions")] public void OrderByDescending_Success() { QueryableImplTest expected = new QueryableImplTest(); IQueryable actual = expected.OrderByDescending("PropInt1"); Assert.IsTrue(CheckExpressionMethod(actual.Expression, nameof(QueryableExtentions.OrderByDescending))); } [TestMethod, TestCategory("Extentions")] public void ThenBy_Success() { ExpressionMapper.CreateMap().ForMember(s => s.PropString1, d => d.PropString2); ExpressionMapper.Initialize(); QueryableImplTest expected = new QueryableImplTest(); IQueryable actual = expected.OrderByDescending("PropInt1").ThenBy("PropInt1"); Assert.IsTrue(CheckExpressionMethod(actual.Expression, nameof(QueryableExtentions.ThenBy))); } [TestMethod, TestCategory("Extentions")] public void ThenByDescending_Success() { Init(null); QueryableImplTest expected = new QueryableImplTest(); IQueryable actual = expected.OrderByDescending("PropInt1").ThenByDescending("PropInt1"); Assert.IsTrue(CheckExpressionMethod(actual.Expression, nameof(QueryableExtentions.ThenByDescending))); } private bool CheckExpressionMethod(Expression expression, string methodeName) { if (expression.NodeType == ExpressionType.Call) { return (expression as MethodCallExpression).Method.Name == methodeName; } return false; } } }