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

108 lines
3.0 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-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-08 22:59:18 -05:00
.Select(t => new
{
TheClientId = t.Key,
Count = t.Count(),
CountClientId = t.Count(t2 => t2.ClientId > 1),
LongCount = t.LongCount(),
NetSales = t.Sum(t2 => t2.NetSales),
TaxAverage = t.Average(t2 => t2.Tax),
Sales = t.ToList()
});*/
var dynamicSyntax2 = TestData.Sales
.AsQueryable()
.GroupBy(t => t.Path("ClientId"))
.Select(t =>
{
t.Key("TheClientId", "ClientId");
t.Count("Count");
t.LongCount("LongCount");
t.Sum("NetSales");
t.Average("Tax", "TaxAverage");
t.ToList("Sales");
});
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
}
}