Almost done testing shortcuts.

This commit is contained in:
David Lebée 2018-02-28 18:10:33 -06:00
parent c6a9aabd8a
commit 0807d7cdd7
3 changed files with 158 additions and 0 deletions

View File

@ -0,0 +1,41 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PoweredSoft.DynamicLinq.Test.Helpers
{
public static class QueryableAssert
{
private static bool _sameList<T>(IQueryable<T> a, IQueryable<T> b)
where T : class
{
if (a.Count() != b.Count())
return false;
var listA = a.ToList();
var listB = b.ToList();
for (var i = 0; i < listA.Count; i++)
{
if (listA.ElementAt(i) != listB.ElementAt(i))
return false;
}
return true;
}
public static void AreEqual<T>(IQueryable<T> a, IQueryable<T> b)
where T : class
{
Assert.IsTrue(_sameList(a, b));
}
public static void AreNotEqual<T>(IQueryable<T> a, IQueryable<T> b)
where T : class
{
Assert.IsFalse(_sameList(a, b));
}
}
}

View File

@ -61,6 +61,8 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="ComplexQueriesTests.cs" /> <Compile Include="ComplexQueriesTests.cs" />
<Compile Include="Helpers\QueryableAssert.cs" />
<Compile Include="ShortcutTests.cs" />
<Compile Include="SimpleQueriesTest.cs" /> <Compile Include="SimpleQueriesTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="HelpersTests.cs" /> <Compile Include="HelpersTests.cs" />

View File

@ -0,0 +1,115 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PoweredSoft.DynamicLinq.Extensions;
using PoweredSoft.DynamicLinq.Test.Helpers;
namespace PoweredSoft.DynamicLinq.Test
{
internal class MockPersonObject
{
public string FirstName { get; set; }
public string LastName { get; set; }
public int Age { get; set; }
}
[TestClass]
public class ShortcutTests
{
internal List<MockPersonObject> Persons = new List<MockPersonObject>
{
new MockPersonObject { FirstName = "David", LastName = "Lebee", Age = 28 },
new MockPersonObject { FirstName = "Michaela", LastName = "Vickar", Age = 27 },
new MockPersonObject { FirstName = "John", LastName = "Doe", Age = 28 },
new MockPersonObject { FirstName = "Chuck", LastName = "Norris", Age = 50 },
new MockPersonObject { FirstName = "Michael", LastName = "Jackson", Age = 58 }
};
[TestMethod]
public void Equal()
{
// test simple
var q1 = Persons.AsQueryable().Query(t => t.Equal("FirstName", "David"));
var q1b = Persons.AsQueryable().Where(t => t.FirstName == "David");
QueryableAssert.AreEqual(q1, q1b);
// test and
var q2 = Persons.AsQueryable().Query(t => t.Equal("FirstName", "David").AndEqual("LastName", "Lebee"));
var q2b = Persons.AsQueryable().Where(t => t.FirstName == "David" && t.LastName == "Lebee");
QueryableAssert.AreEqual(q2, q2b);
// test or
var q3 = Persons.AsQueryable().Query(t => t.Equal("FirstName", "David").OrEqual("FirstName", "Michaela"));
var q3b = Persons.AsQueryable().Where(t => t.FirstName == "David" || t.FirstName == "Michaela");
QueryableAssert.AreEqual(q3, q3b);
}
[TestMethod]
public void NotEqual()
{
// test simple
var q1 = Persons.AsQueryable().Query(t => t.NotEqual("FirstName", "David"));
var q1b = Persons.AsQueryable().Where(t => t.FirstName != "David");
QueryableAssert.AreEqual(q1, q1b);
// test and
var q2 = Persons.AsQueryable().Query(t => t.NotEqual("FirstName", "David").AndNotEqual("FirstName", "Michaela"));
var q2b = Persons.AsQueryable().Where(t => t.FirstName != "David" && t.FirstName != "Michaela");
QueryableAssert.AreEqual(q2, q2b);
// test or
var q3 = Persons.AsQueryable().Query(t => t.NotEqual("FirstName", "David").OrNotEqual("LastName", "Lebee"));
var q3b = Persons.AsQueryable().Where(t => t.FirstName != "David" || t.LastName != "Lebee");
QueryableAssert.AreEqual(q3, q3b);
}
[TestMethod]
public void GreatThan()
{
var q1 = Persons.AsQueryable().Query(t => t.GreaterThan("Age", 28));
var q1b = Persons.AsQueryable().Where(t => t.Age > 28);
QueryableAssert.AreEqual(q1, q1b);
}
[TestMethod]
public void GreatThanOrEqual()
{
}
[TestMethod]
public void LessThan()
{
}
[TestMethod]
public void LessThanOrEqual()
{
}
[TestMethod]
public void StartsWith()
{
}
[TestMethod]
public void EndsWith()
{
}
[TestMethod]
public void Contains()
{
}
}
}