better test :) for now.

This commit is contained in:
David Lebée 2018-03-21 22:27:03 -05:00
parent 8f35c2a377
commit be22a2a0dd

View File

@ -1,5 +1,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.VisualStudio.TestTools.UnitTesting;
using PoweredSoft.DynamicLinq.Dal.Pocos; using PoweredSoft.DynamicLinq.Dal.Pocos;
using PoweredSoft.DynamicLinq.Test.Helpers;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -8,49 +9,72 @@ using System.Threading.Tasks;
namespace PoweredSoft.DynamicLinq.Test namespace PoweredSoft.DynamicLinq.Test
{ {
public class Mock
{
public int Id { get; set; }
public int ForeignId { get; set; }
public decimal Total { get; set; }
public List<MockB> Bs { get; set; } = new List<MockB>();
}
public class MockB
{
public List<string> FirstNames { get; set; }
}
[TestClass] [TestClass]
public class SelectTests public class SelectTests
{ {
[TestMethod] [TestMethod]
public void TestSelect() public void TestSelect()
{ {
var regularSyntaxA = TestData.Authors var list = new List<Mock>()
{
new Mock{
Id = 1,
ForeignId = 1,
Total = 100,
Bs = new List<MockB>() {
new MockB { FirstNames = new List<string>{"David", "John" } }
}
},
};
var regularSyntaxA = list
.AsQueryable() .AsQueryable()
.Select(t => new .Select(t => new
{ {
Id = t.Id, Id = t.Id,
AuthorFirstName = t.FirstName, FirstNames = t.Bs.SelectMany(t2 => t2.FirstNames).ToList(),
AuthorLastName = t.LastName, FirstNamesLists = t.Bs.Select(t2 => t2.FirstNames).ToList()
Posts = t.Posts.ToList(),
Comments = t.Posts.Select(t2 => t2.Comments).ToList(),
Comments2 = t.Posts.SelectMany(t2 => t2.Comments).ToList()
}); });
//var regularSyntax = regularSyntaxA.ToList(); var regularSyntax = regularSyntaxA.ToList();
var dynamicSyntax = TestData.Authors var dynamicSyntax = list
.AsQueryable() .AsQueryable()
.Select(t => .Select(t =>
{ {
t.Path("Id"); t.Path("Id");
t.Path("FirstName", "AuthorFirstName"); t.PathToList("Bs.FirstNames", "FirstNames", SelectCollectionHandling.SelectMany);
t.Path("LastName", "AuthorLastName"); t.PathToList("Bs.FirstNames", "FirstNamesLists", SelectCollectionHandling.Select);
t.PathToList("Posts");
t.PathToList("Posts.Comments");
t.PathToList("Posts.Comments", "Comments2", SelectCollectionHandling.SelectMany);
}) })
.ToDynamicClassList(); .ToDynamicClassList();
/*
Assert.AreEqual(regularSyntax.Count, dynamicSyntax.Count); Assert.AreEqual(regularSyntax.Count, dynamicSyntax.Count);
for(var i = 0; i < regularSyntax.Count; i++) for(var i = 0; i < regularSyntax.Count; i++)
{ {
Assert.AreEqual(regularSyntax[i].Id, dynamicSyntax[i].GetDynamicPropertyValue<long>("Id")); Assert.AreEqual(regularSyntax[i].Id, dynamicSyntax[i].GetDynamicPropertyValue<int>("Id"));
Assert.AreEqual(regularSyntax[i].AuthorFirstName, dynamicSyntax[i].GetDynamicPropertyValue<string>("AuthorFirstName")); QueryableAssert.AreEqual(regularSyntax[i].FirstNames.AsQueryable(), dynamicSyntax[i].GetDynamicPropertyValue<List<string>>("FirstNames").AsQueryable());
Assert.AreEqual(regularSyntax[i].AuthorLastName, dynamicSyntax[i].GetDynamicPropertyValue<string>("AuthorLastName"));
Helpers.QueryableAssert.AreEqual(regularSyntax[i].Posts.AsQueryable(), dynamicSyntax[i].GetDynamicPropertyValue<List<Post>>("Posts").AsQueryable());
//Helpers.QueryableAssert.AreEqual(regularSyntax[i].Comments.AsQueryable(), dynamicSyntax[i].GetDynamicPropertyValue<List<Comment>>("Comments").AsQueryable()); var left = regularSyntax[i].FirstNamesLists;
}*/ var right = dynamicSyntax[i].GetDynamicPropertyValue<List<List<string>>>("FirstNamesLists");
Assert.AreEqual(left.Count, right.Count);
for(var j = 0; j < left.Count; j++)
QueryableAssert.AreEqual(left[j].AsQueryable(), right[j].AsQueryable());
}
} }
[TestMethod] [TestMethod]