diff --git a/PoweredSoft.DynamicLinq.Test/GroupingTests.cs b/PoweredSoft.DynamicLinq.Test/GroupingTests.cs new file mode 100644 index 0000000..ef9df7a --- /dev/null +++ b/PoweredSoft.DynamicLinq.Test/GroupingTests.cs @@ -0,0 +1,44 @@ +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 +{ + [TestClass] + public class GroupingTests + { + [TestMethod] + public void WantedSyntax() + { + var regularSyntax = TestData.Sales + .GroupBy(t => t.ClientId) + .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 dynamicSyntax = TestData.Sales + .GroupBy("ClientId") + .Select(t => + { + t.PropertyFromKey("TheClientId", "ClientId"); + t.Count("Count"); + // don't have to implement right away. + t.Count("CountClientId", "ClientId", ConditionOperators.GreaterThan, 1); + t.LongCount("LongCount"); + t.Sum("NetSales"); + t.Average("TaxAverage", "Tax"); + t.ToList("Sales"); + });*/ + } + } +} diff --git a/PoweredSoft.DynamicLinq.Test/ShortcutTests.cs b/PoweredSoft.DynamicLinq.Test/ShortcutTests.cs index 5ef4809..9025dda 100644 --- a/PoweredSoft.DynamicLinq.Test/ShortcutTests.cs +++ b/PoweredSoft.DynamicLinq.Test/ShortcutTests.cs @@ -7,15 +7,6 @@ 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 { diff --git a/PoweredSoft.DynamicLinq.Test/TestData.cs b/PoweredSoft.DynamicLinq.Test/TestData.cs index 01aedf5..2c93f42 100644 --- a/PoweredSoft.DynamicLinq.Test/TestData.cs +++ b/PoweredSoft.DynamicLinq.Test/TestData.cs @@ -7,6 +7,31 @@ using System.Threading.Tasks; namespace PoweredSoft.DynamicLinq.Test { + internal class MockPersonObject + { + public string FirstName { get; set; } + + public string LastName { get; set; } + + public int Age { get; set; } + } + + internal class MockSale + { + public long Id { get; set; } + public long ClientId { get; set; } + public MockClient Client { get; set; } + public decimal GrossSales { get; set; } + public decimal NetSales { get; set; } + public decimal Tax { get; set; } + } + + internal class MockClient + { + public long Id { get; set; } + public string Name { get; set; } + } + internal static class TestData { static readonly internal List Persons = new List @@ -18,6 +43,28 @@ namespace PoweredSoft.DynamicLinq.Test new MockPersonObject { FirstName = "Michael", LastName = "Jackson", Age = 58 } }; + static readonly internal List Clients = new List + { + new MockClient { Id = 1, Name = "ACME INC."}, + new MockClient { Id = 2, Name = "MSLINK" }, + new MockClient { Id = 3, Name = "COOL GUYS TBD"}, + new MockClient { Id = 4, Name = "SOME LLC YEAH!" } + }; + + static readonly internal List Sales = new List + { + new MockSale { Id = 1, ClientId = 1, Client = Clients.First(t => t.Id == 1), GrossSales = 1000M, NetSales = 890.0M, Tax = 20M }, + new MockSale { Id = 2, ClientId = 1, Client = Clients.First(t => t.Id == 1), GrossSales = 1100M, NetSales = 180.0M, Tax = 0M }, + new MockSale { Id = 3, ClientId = 2, Client = Clients.First(t => t.Id == 2), GrossSales = 1200M, NetSales = 920.0M, Tax = 3M }, + new MockSale { Id = 4, ClientId = 2, Client = Clients.First(t => t.Id == 2), GrossSales = 1330M, NetSales = 800.0M, Tax = 120M }, + new MockSale { Id = 5, ClientId = 1, Client = Clients.First(t => t.Id == 1), GrossSales = 1400M, NetSales = 990.0M, Tax = 20M }, + new MockSale { Id = 6, ClientId = 3, Client = Clients.First(t => t.Id == 3), GrossSales = 1500M, NetSales = 290.0M, Tax = 200M }, + new MockSale { Id = 7, ClientId = 3, Client = Clients.First(t => t.Id == 3), GrossSales = 1600M, NetSales = 230.0M, Tax = 240M }, + new MockSale { Id = 8, ClientId = 3, Client = Clients.First(t => t.Id == 3), GrossSales = 1700M, NetSales = 330.0M, Tax = 210M }, + new MockSale { Id = 9, ClientId = 1, Client = Clients.First(t => t.Id == 1), GrossSales = 1800M, NetSales = 890.0M, Tax = 290M }, + new MockSale { Id = 10, ClientId = 4, Client = Clients.First(t => t.Id == 4), GrossSales = 1900M, NetSales = 490.0M, Tax = 270M } + }; + static readonly internal List Posts = new List() { new Post