|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Text; |
| 5 | +using System.Threading.Tasks; |
| 6 | +using NFluent; |
| 7 | +using Xunit; |
| 8 | + |
| 9 | +namespace System.Linq.Dynamic.Core.Tests.MikArea |
| 10 | +{ |
| 11 | + public class Dictionary |
| 12 | + { |
| 13 | + public class Customer |
| 14 | + { |
| 15 | + public string City { get; set; } |
| 16 | + public Dictionary<string, Order> Orders { get; set; } |
| 17 | + public string CompanyName { get; set; } |
| 18 | + public string Phone { get; set; } |
| 19 | + } |
| 20 | + public class Order |
| 21 | + { |
| 22 | + } |
| 23 | + |
| 24 | + [Fact] |
| 25 | + public void Test_ContainsKey_1() |
| 26 | + { |
| 27 | + List<Customer> customers = new List<Customer>() |
| 28 | + { |
| 29 | + new Customer() { City = "ZZZ1", CompanyName = "ZZZ", Orders = new Dictionary<string, Order>() }, |
| 30 | + new Customer() { City = "ZZZ2", CompanyName = "ZZZ", Orders = new Dictionary<string, Order>() }, |
| 31 | + new Customer() { City = "ZZZ3", CompanyName = "ZZZ", Orders = new Dictionary<string, Order>() } |
| 32 | + }; |
| 33 | + customers.ForEach(x => x.Orders.Add(x.City + "TEST", new Order())); |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | + var data = customers.AsQueryable() |
| 38 | + .Where("Orders.ContainsKey(\"ZZZ2TEST\")") |
| 39 | + .OrderBy("CompanyName") |
| 40 | + .Select("new(City as City, Phone)").ToDynamicList(); |
| 41 | + |
| 42 | + Check.That("ZZZ2").IsEqualTo((string)data.First().City); |
| 43 | + } |
| 44 | + |
| 45 | + [Fact] |
| 46 | + public void Test_ContainsKey_2() |
| 47 | + { |
| 48 | + List<Customer> customers = new List<Customer>() |
| 49 | + { |
| 50 | + new Customer() { City = "ZZZ1", CompanyName = "ZZZ", Orders = new Dictionary<string, Order>() }, |
| 51 | + new Customer() { City = "ZZZ2", CompanyName = "ZZZ", Orders = new Dictionary<string, Order>() }, |
| 52 | + new Customer() { City = "ZZZ3", CompanyName = "ZZZ", Orders = new Dictionary<string, Order>() } |
| 53 | + }; |
| 54 | + customers.ForEach(x => x.Orders.Add(x.City + "TEST", new Order())); |
| 55 | + |
| 56 | + |
| 57 | + |
| 58 | + var data = customers.AsQueryable() |
| 59 | + .Where("Orders.ContainsKey(it.City + \"TEST\")") |
| 60 | + .OrderBy("City") |
| 61 | + .Select("new(City as City, Phone)").ToDynamicList(); |
| 62 | + |
| 63 | + Check.That("ZZZ1").IsEqualTo((string)data.First().City); |
| 64 | + Check.That(3).IsEqualTo(data.Count); |
| 65 | + } |
| 66 | + } |
| 67 | +} |
0 commit comments