public void WithPreviousTest([ValueSource("list0")] QueryArg arg) { var list = arg.ToList(); if (list.Count == 0) { Assert.That(arg.ToQuery().WithPrevious().Count(), Is.EqualTo(0)); Assert.That(arg.ToQuery().WithPrevious(includeStart: true).Count(), Is.EqualTo(0)); } else if (list.Count == 1) { Assert.That(arg.ToQuery().WithPrevious().Count(), Is.EqualTo(0)); Assert.That(arg.ToQuery().WithPrevious(includeStart: true).Count(), Is.EqualTo(1)); } else { Assert.That(arg.ToQuery().WithPrevious().Count(p => p.hasPrev), Is.EqualTo(list.Count - 1)); Assert.That(arg.ToQuery().WithPrevious(includeStart: true).Count(p => !p.hasPrev), Is.EqualTo(1)); Assert.That(arg.ToQuery().WithPrevious(includeStart: true).Count(p => p.hasPrev), Is.EqualTo(list.Count - 1)); } int index = 0; foreach (var pair in arg.ToQuery().WithPrevious()) { Assert.That(pair.prev, Is.EqualTo(list[index])); index++; } }
public void ContainsTest([ValueSource("list0")] QueryArg arg) { Assert.That(arg.ToQuery().Contains(3), Is.EqualTo( arg.ToList().Contains(3))); Assert.That(arg.ToQuery().Contains(9), Is.EqualTo( arg.ToList().Contains(9))); }
public void AllTest([ValueSource("list0")] QueryArg arg) { Assert.That(arg.ToQuery().All(i => i < 5), Is.EqualTo( arg.ToList().All(i => i < 5))); Assert.That(arg.ToQuery().All(i => i != 8), Is.EqualTo( arg.ToList().All(i => i != 8))); }
public void SelectManyTest([ValueSource("list0")] QueryArg arg0, [ValueSource("list0")] QueryArg arg1) { Assert.That(arg0.ToQuery().SelectMany(i => arg1.ToQuery().Select(j => j * i)).ToList(), Is.EquivalentTo( arg0.ToList().SelectMany(i => arg1.ToList().Select(j => j * i)).ToList())); Assert.That(arg0.ToQuery().SelectMany(i => arg1.ToList().Select(j => j * i).ToList()).ToList(), Is.EquivalentTo( arg0.ToList().SelectMany(i => arg1.ToList().Select(j => j * i)).ToList())); }
public void CountTests([ValueSource("list0")] QueryArg arg) { Assert.That(arg.ToQuery().Count(), Is.EqualTo( arg.ToList().Count())); Assert.That(arg.ToQuery().Count(i => i % 2 == 0), Is.EqualTo( arg.ToList().Count(i => i % 2 == 0))); }
public void ConcatTest([ValueSource("list0")] QueryArg arg0, [ValueSource("list0")] QueryArg arg1) { Assert.That(arg0.ToQuery().Concat(arg1.ToList()).ToList(), Is.EquivalentTo( arg0.ToList().Concat(arg1.ToList()).ToList())); Assert.That(arg0.ToQuery().Concat(arg1.ToQuery()).ToList(), Is.EquivalentTo( arg0.ToList().Concat(arg1.ToList()).ToList())); }
public void IndexOfTests([ValueSource("list0")] QueryArg arg) { Assert.That(arg.ToQuery().IndexOf(3), Is.EqualTo( arg.ToList().IndexOf(3))); Assert.That(arg.ToQuery().IndexOf(100), Is.EqualTo( arg.ToList().IndexOf(100))); }
public void MultiFirstTest([ValueSource("list0")] QueryArg arg) { var q = arg.ToQuery(); q.FirstOrDefault(); Assert.That(() => q.FirstOrDefault(), Throws.InvalidOperationException); }
public void SortTest([ValueSource("list0")] QueryArg arg) { var expected = arg.ToList(); expected.Sort(); Assert.That(arg.ToQuery().Sort().ToList(), Is.EquivalentTo( expected)); }
public void WithIndicesTest([ValueSource("list0")] QueryArg arg) { int index = 0; foreach (var item in arg.ToQuery().WithIndices()) { Assert.That(item.index, Is.EqualTo(index)); Assert.That(item.value, Is.EqualTo(arg.ToList()[index])); index++; } }
public void AverageTest([ValueSource("list0")] QueryArg arg0) { if (arg0.ToList().Count == 0) { Assert.Ignore("Ignore empty queries for average test."); return; } Assert.That(arg0.ToQuery().Select(t => (double)t).Average(), Is.EqualTo( arg0.ToList().Average()).Within(0.001).Percent); }
public void SumTests([ValueSource("list0")] QueryArg arg) { if (arg.ToList().Count == 0) { Assert.Ignore("Ignore empty queries for sum tests."); return; } Assert.That(arg.ToQuery().Sum(), Is.EqualTo( arg.ToList().Sum())); }
public void ForeachTest([ValueSource("list0")] QueryArg arg0, [ValueSource("list1")] QueryArg arg1) { List <int> actual = new List <int>(); foreach (var item in arg0.ToQuery().Concat(arg1.ToQuery())) { actual.Add(item); } Assert.That(actual, Is.EquivalentTo( arg0.ToList().Concat(arg1.ToList()).ToList())); }
public void FirstOrDefaultTests([ValueSource("list0")] QueryArg arg) { Assert.That(arg.ToQuery().FirstOrDefault(), Is.EqualTo( arg.ToList().FirstOrDefault())); Assert.That(arg.ToQuery().FirstOrDefault(i => i % 2 == 0), Is.EqualTo( arg.ToList().FirstOrDefault(i => i % 2 == 0))); Assert.That(arg.ToQuery().FirstOrDefault(i => i > 10), Is.EqualTo( arg.ToList().FirstOrDefault(i => i > 10))); }
public void Repeat([ValueSource("list0")] QueryArg arg, [Values(0, 1, 2, 3, 100)] int repetitions) { List <int> list = new List <int>(); for (int i = 0; i < repetitions; i++) { list.AddRange(arg.ToList()); } Assert.That(arg.ToQuery().Repeat(repetitions).ToList(), Is.EquivalentTo( list)); }
public void ElementAtTest([ValueSource("list0")] QueryArg arg, [Values(0, 3, 100)] int index) { var list = arg.ToList(); if (index >= list.Count) { Assert.That(() => arg.ToQuery().ElementAt(index), Throws.InstanceOf <IndexOutOfRangeException>()); } else { Assert.That(arg.ToQuery().ElementAt(index), Is.EqualTo( arg.ToList().ElementAt(index))); } }
public void FoldTest([ValueSource("list0")] QueryArg arg) { var list = arg.ToList(); if (list.Count == 0) { Assert.That(() => arg.ToQuery().Fold((a, b) => a + b), Throws.InvalidOperationException); } else { Assert.That(arg.ToQuery().Fold((a, b) => a + b), Is.EqualTo( arg.ToList().Sum())); } }
public void LastTests([ValueSource("list0")] QueryArg arg) { var list = arg.ToList(); if (list.Count == 0) { Assert.That(() => arg.ToQuery().Last(), Throws.InvalidOperationException); } else { Assert.That(arg.ToQuery().Last(), Is.EqualTo( arg.ToList().Last())); } Assert.That(arg.ToQuery().LastOrDefault(), Is.EqualTo( arg.ToList().LastOrDefault())); }
/// <summary> /// 获取两票列表 /// </summary> /// <param name="type">1:操作票;2:工作票</param> /// <param name="begin_date">格式:yyyyMMdd 默认为当天</param> /// <param name="end_date">跨度最大一个月</param> /// <returns></returns> public BaseTran <tickets> GetTicketsList(string type, string begin_date, string end_date) { BaseTran <tickets> recv = new BaseTran <tickets>(); string path = "api/tickets"; string url = BaseUri + path; QueryArg query = new QueryArg(); query.Add("type", type); query.Add("begin_date", begin_date); query.Add("end_date", end_date); url += query.GetQueryString(); recv = GetEntityList <tickets>(url); if (recv.data == null) { recv.data = new List <tickets>(); } return(recv); }
public void ZipTest([ValueSource("list0")] QueryArg arg0, [ValueSource("list1")] QueryArg arg1) { var list0 = arg0.ToList(); var list1 = arg1.ToList(); List <string> expected = new List <string>(); for (int i = 0; i < Mathf.Min(list0.Count, list1.Count); i++) { expected.Add(list0[i].ToString() + list1[i].ToString()); } Assert.That(arg0.ToQuery().Zip(arg1.ToQuery(), (a, b) => a.ToString() + b.ToString()).ToList(), Is.EquivalentTo( expected)); Assert.That(arg0.ToQuery().Zip(arg1.ToList(), (a, b) => a.ToString() + b.ToString()).ToList(), Is.EquivalentTo( expected)); }
public void MultiForeachTest([ValueSource("list0")] QueryArg arg) { List <int> a = new List <int>(); List <int> b = new List <int>(); var q = arg.ToQuery(); foreach (var item in q) { a.Add(item); } Assert.That(() => { foreach (var item in q) { b.Add(item); } }, Throws.InvalidOperationException); }
public void WithPreviousOffsetTest([ValueSource("list0")] QueryArg arg) { var list = arg.ToList(); if (list.Count == 0) { Assert.That(arg.ToQuery().WithPrevious(offset: 4).Count(), Is.EqualTo(0)); Assert.That(arg.ToQuery().WithPrevious(offset: 4, includeStart: true).Count(), Is.EqualTo(0)); } else if (list.Count == 1) { Assert.That(arg.ToQuery().WithPrevious(offset: 4).Count(), Is.EqualTo(0)); Assert.That(arg.ToQuery().WithPrevious(offset: 4, includeStart: true).Count(), Is.EqualTo(1)); } else { Assert.That(arg.ToQuery().WithPrevious(offset: 4).Count(), Is.EqualTo(Mathf.Max(0, list.Count - 4))); Assert.That(arg.ToQuery().WithPrevious(offset: list.Count + 1).Count(), Is.EqualTo(0)); Assert.That(arg.ToQuery().WithPrevious(offset: int.MaxValue).Count(), Is.EqualTo(0)); } Assert.That(Values.Range(0, 10).WithPrevious(offset: 2).All(i => i.value - i.prev == 2)); }
public void FirstTests([ValueSource("list0")] QueryArg arg) { var list = arg.ToList(); if (list.Count == 0) { Assert.That(() => arg.ToQuery().First(), Throws.InvalidOperationException); } else { Assert.That(arg.ToQuery().First(), Is.EqualTo( arg.ToList().First())); } if (list.Where(i => i % 2 == 0).Count() == 0) { Assert.That(() => arg.ToQuery().Where(i => i % 2 == 0).First(), Throws.InvalidOperationException); } else { Assert.That(arg.ToQuery().First(i => i % 2 == 0), Is.EqualTo( arg.ToList().First(i => i % 2 == 0))); } }
/// <summary> /// 获取两票列表 /// </summary> /// <param name="type">1:操作票;2:工作票</param> /// <param name="begin_date">格式:yyyyMMdd 默认为当天</param> /// <param name="end_date">跨度最大一个月</param> /// <returns></returns> public BaseTran <tickets> GetTicketsList(string type, string begin_date, string end_date) { BaseTran <tickets> recv = new BaseTran <tickets>(); try { string path = "api/tickets"; string url = BaseUri + path; QueryArg query = new QueryArg(); query.Add("type", type); query.Add("begin_date", begin_date); query.Add("end_date", end_date); url += query.GetQueryString(); recv = GetEntityList <tickets>(url); if (recv.data == null) { recv.data = new List <tickets>(); } foreach (tickets item in recv.data) { int nFlag = 0; if (item.type == 1) { OperationTicket ot = bll.OperationTickets.DbSet.Where(p => p.Abutment_Id == item.id).FirstOrDefault(); if (ot == null) { ot = new OperationTicket(); ot.OperationStartTime = DateTime.Now; ot.OperationEndTime = DateTime.Now.AddDays(1); nFlag = 1; } ot.Abutment_Id = item.id; ot.No = item.code; if (nFlag == 1) { bll.OperationTickets.Add(ot); } else { bll.OperationTickets.Edit(ot); } } else { WorkTicket wt = bll.WorkTickets.DbSet.Where(p => p.Abutment_Id == item.id).FirstOrDefault(); if (wt == null) { wt = new WorkTicket(); wt.StartTimeOfPlannedWork = DateTime.Now; wt.EndTimeOfPlannedWork = DateTime.Now.AddDays(1); nFlag = 1; } wt.Abutment_Id = item.id; wt.No = item.code; if (nFlag == 1) { bll.WorkTickets.Add(wt); } else { bll.WorkTickets.Edit(wt); } } } } catch (Exception ex) { string messgae = ex.Message; } return(recv); }
public void OrderByDescendingTest([ValueSource("list0")] QueryArg arg) { Assert.That(arg.ToQuery().OrderByDescending(i => i).ToList(), Is.EquivalentTo( arg.ToList().OrderByDescending(i => i).ToList())); }
public void AnyTest([ValueSource("list0")] QueryArg arg) { Assert.That(arg.ToQuery().Any(i => i == 4), Is.EqualTo( arg.ToList().Query().Any(i => i == 4))); }
public void SelectTest([ValueSource("list0")] QueryArg arg) { Assert.That(arg.ToQuery().Select(i => i * 23).ToList(), Is.EquivalentTo( arg.ToList().Select(i => i * 23).ToList())); }
public void WhereTest([ValueSource("list0")] QueryArg arg) { Assert.That(arg.ToQuery().Where(i => i % 2 == 0).ToList(), Is.EquivalentTo( arg.ToList().Where(i => i % 2 == 0).ToList())); }
public void SkipTest([ValueSource("list0")] QueryArg arg) { Assert.That(arg.ToQuery().Skip(3).ToList(), Is.EquivalentTo( arg.ToList().Skip(3).ToList())); }
public void TakeWhileTest([ValueSource("list0")] QueryArg arg) { Assert.That(arg.ToQuery().TakeWhile(i => i < 4).ToList(), Is.EquivalentTo( arg.ToList().TakeWhile(i => i < 4).ToList())); }