dotnet-dynamic-linq/PoweredSoft.DynamicLinq.Test/GroupingTests.cs

120 lines
3.3 KiB
C#
Raw Normal View History

2018-03-08 21:18:43 -05:00
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2018-03-09 00:22:12 -05:00
using PoweredSoft.DynamicLinq;
2018-03-13 22:01:21 -04:00
using PoweredSoft.DynamicLinq.Dal;
2018-03-08 21:18:43 -05:00
namespace PoweredSoft.DynamicLinq.Test
{
2018-03-12 19:00:02 -04:00
internal class TestStructureCompare : IEqualityComparer<TestStructure>
{
2018-03-12 19:00:02 -04:00
public bool Equals(TestStructure x, TestStructure y)
{
return x?.ClientId == y?.ClientId;
}
public int GetHashCode(TestStructure obj)
{
return obj.ClientId;
}
}
internal class TestStructure
{
public int ClientId { get; set; }
}
2018-03-08 21:18:43 -05:00
[TestClass]
public class GroupingTests
{
[TestMethod]
public void WantedSyntax()
2018-03-09 00:22:12 -05:00
{/*
2018-03-08 21:18:43 -05:00
var regularSyntax = TestData.Sales
2018-03-08 22:59:18 -05:00
.GroupBy(t => t.ClientId);
var dynamicSyntax = TestData.Sales
.AsQueryable()
.GroupBy("ClientId");
2018-03-09 00:22:12 -05:00
2018-03-08 22:59:18 -05:00
var regularSyntax2 = TestData.Sales
.GroupBy(t => new
2018-03-08 21:18:43 -05:00
{
2018-03-08 22:59:18 -05:00
t.ClientId,
2018-03-09 00:22:12 -05:00
B = t.NetSales
});*/
2018-03-08 22:59:18 -05:00
/*
2018-03-08 22:59:18 -05:00
var dynamicSyntax2 = TestData.Sales
.AsQueryable()
2018-03-09 00:22:12 -05:00
.GroupBy(t => t.Path("ClientId").Path("NetSales", "B"));
2018-03-08 22:59:18 -05:00
var dynamicSyntax3 = TestData.Sales
.AsQueryable()
2018-03-12 19:00:02 -04:00
.GroupBy(t => t.UseType(typeof(TestStructure)).EqualityComparer(typeof(TestStructureCompare)).Path("ClientId"));
var tryAs = dynamicSyntax3 as EnumerableQuery<IGrouping<TestStructure, MockSale>>;
var list = tryAs.Select(t => new
{
Key = t.Key,
Data = t.ToList()
}).ToList();
var list2 = TestData.Sales.GroupBy(t => new TestStructure { ClientId = t.ClientId }, new TestStructureCompare()).Select(t => new
{
Key = t.Key,
Data = t.ToList()
}).ToList();
int i = 0;*/
2018-03-08 21:18:43 -05:00
/*
2018-03-13 22:01:21 -04:00
var dynamicSyntax3 = TestData.Sales
.AsQueryable()
.GroupBy(t => t.ClientId)
.Select(t => new
{
TheClientId = t.Key,
Count = t.Count(),
});*/
BlogContext bc = null;
if (bc != null)
2018-03-08 22:59:18 -05:00
{
2018-03-13 22:01:21 -04:00
bc.Authors.GroupBy(t => new { t.LastName }).Select(t => new
{
t.Key.LastName,
Count = t.Count()
});
}
2018-03-08 22:59:18 -05:00
var dynamicSyntax2 = TestData.Sales
.AsQueryable()
.GroupBy(t => t.Path("ClientId"))
.Select(t =>
{
2018-03-13 22:01:21 -04:00
t.Key("TheClientId", "ClientId");
t.Count("Count");
/*
t.LongCount("LongCount");
t.Sum("NetSales");
t.Average("Tax", "TaxAverage");
2018-03-13 22:01:21 -04:00
t.ToList("Sales");*/
});
2018-03-13 22:01:21 -04:00
var result = dynamicSyntax2.ToObjectList();
2018-03-08 21:18:43 -05:00
}
2018-03-12 19:00:02 -04:00
private object compare(MockSale arg)
{
throw new NotImplementedException();
}
2018-03-08 21:18:43 -05:00
}
}