public static void First(Labeled <ParallelQuery <int> > labeled, int count, int position) { // For unordered collections, which element is chosen isn't actually guaranteed, but an effect of the implementation. // If this test starts failing it should be split, and possibly mentioned in release notes. ParallelQuery <int> query = labeled.Item; Assert.Equal(0, query.First()); Assert.Equal(position, query.First(x => x >= position)); }
public static void Range_First(int start, int count) { ParallelQuery <int> query = ParallelEnumerable.Range(start, count); if (count == 0) { Assert.Throws <InvalidOperationException>(() => query.First()); } else { Assert.Equal(start, query.First()); } }
/// <summary> /// Method to find file references (more specific in the using context of this method: file references to copybooks) without a given parent folder. /// Because there is no distinct location given, the selection of the file reference is based on a searching pattern: /// If there is only one file with the given name in the cache, it's selected. If there are more than one, it's checked if only one of them ends /// with the extension *.cbl. If that is true, this file reference is selected, if not an exception is thrown. This method could also search directly /// for the filename + extension but that would cut out the possibility of loading files with functionally not correct extension like *.txt (in case their /// name is unique). /// </summary> /// <param name="programName">The name of the program the file reference is wanted for.</param> /// <returns>The file reference for the program.</returns> public FileReference GetFileReferenceWithoutKnownFolderName(string programName) { if (string.IsNullOrWhiteSpace(programName)) { return(null); } //Selecting all files with the programName in the file cache ignoring the file extension. ParallelQuery <FileReference> allFileReferencesWithGivenName = _files.AsParallel().Where(file => file.Key.Contains(programName + ".")).Select(file => file.Value); //If more than one file of that name is found, a more specific search is done, icluding the file extension. if (allFileReferencesWithGivenName.Count() > 1) { allFileReferencesWithGivenName = _files.AsParallel().Where(file => file.Key.Contains(programName + ".cbl")).Select(file => file.Value); } if (allFileReferencesWithGivenName.Count() > 1) { //If there is still more than one file, an exception is thrown, stating the fact, that a distinct file selection is impossible. throw new CopiedRessourceNotIdentifiedDistinctlyByNameException(programName); } else { //Else the found reference is returned. return(allFileReferencesWithGivenName.First()); } }
public static void First_NoMatch(Labeled <ParallelQuery <int> > labeled, int count, int position) { ParallelQuery <int> query = labeled.Item; IntegerRangeSet seen = new IntegerRangeSet(0, count); Assert.Throws <InvalidOperationException>(() => query.First(x => !seen.Add(x))); seen.AssertComplete(); }
public static void First_Empty(Labeled <ParallelQuery <int> > labeled, int count, int position) { _ = count; _ = position; ParallelQuery <int> query = labeled.Item; Assert.Throws <InvalidOperationException>(() => query.First()); }
public ActionResult SurveyReportDetails(int surveyId) { SurveyInfo surveyInfo = _surveyManager.GetCdeSurveyInfoById(surveyId); var list = _userSurveyManager.GetUserSurveyList(surveyId).FindAll(p => p.ApproveFlag == 2); List <Cde_Report> reports = _reportManager.GetReportsBySurveyId(surveyId); ParallelQuery <SysUser> parallusers = SystemUsers.AsParallel(); foreach (var item in list) { item.User = parallusers.First(p => p.UserId == item.UserId); var tmp = reports.FirstOrDefault(p => p.UserSurveyId == item.UserSurveyId); item.ReportId = tmp == null ? 0 : tmp.ReportId; } list = list.OrderByDescending(p => p.ReportId).ToList(); //foreach (Cde_Report report in reports) //{ // report.User = parallusers.First(p => p.UserId == report.UserId); //} ViewBag.surveyInfo = surveyInfo; //return View(reports); return(View(list)); }
private static void RunAllTests( TestTracker result, ParallelQuery <int> q, bool orderPreserved, string leftOpName, bool leftOrderDefined) { LogTestRun(leftOpName, "All1", orderPreserved); result.MustEqual( q.All(i => i > 100), q.ToArray().Any(i => i > 100)); LogTestRun(leftOpName, "All2", orderPreserved); result.MustEqual( q.All(i => i == 75), q.ToArray().All(i => i == 75)); LogTestRun(leftOpName, "Any1", orderPreserved); result.MustEqual( q.Any(i => i > 100), q.ToArray().Any(i => i > 100)); LogTestRun(leftOpName, "Any2", orderPreserved); result.MustEqual( q.Any(i => i == 75), q.ToArray().Any(i => i == 75)); LogTestRun(leftOpName, "Concat", orderPreserved); result.MustSequenceEqual( q.Concat(q).Concat(new int[] { 1, 2, 3 }.AsParallel()), q.Reverse().Reverse().ToArray().Concat(q.Reverse().Reverse()).Concat(new int[] { 1, 2, 3 }), leftOrderDefined && orderPreserved); LogTestRun(leftOpName, "DefaultIfEmpty", orderPreserved); result.MustSequenceEqual( q.DefaultIfEmpty(), q.ToArray().DefaultIfEmpty(), orderPreserved && leftOrderDefined); LogTestRun(leftOpName, "ElementAt", orderPreserved); IEnumerable <int> q2 = q.ToArray(); int count1 = q.Count(), count2 = q2.Count(); List <int> list1 = new List <int>(); List <int> list2 = new List <int>(); for (int i = 0; i < count1; i++) { list1.Add(q.ElementAt(i)); } for (int i = 0; i < count2; i++) { list2.Add(q2.ElementAt(i)); } result.MustSequenceEqual(list1, list2, leftOrderDefined); LogTestRun(leftOpName, "Except", orderPreserved); result.MustSequenceEqual( q.Except(Enumerable.Range(90, 50).AsParallel()), q.ToArray().Except(Enumerable.Range(90, 50)), false); LogTestRun(leftOpName, "First", orderPreserved); CheckFirstOrLast( result, q.First(), q.ToArray().First(), leftOrderDefined); LogTestRun(leftOpName, "GroupBy", orderPreserved); result.MustGroupByEqual( q.GroupBy(i => i % 5, (i, e) => new Pair <int, IEnumerable <int> >(i, e)), q.ToArray().GroupBy(i => i % 5, (i, e) => new Pair <int, IEnumerable <int> >(i, e))); LogTestRun(leftOpName, "GroupJoin", orderPreserved); result.MustSequenceEqual( q.GroupJoin(q, i => i, i => i, (i, e) => e.FirstOrDefault()), q.ToArray().GroupJoin(q.ToArray(), i => i, i => i, (i, e) => e.FirstOrDefault()), false); LogTestRun(leftOpName, "Intersect", orderPreserved); result.MustSequenceEqual( q.Intersect(Enumerable.Range(90, 50).AsParallel()), q.ToArray().Intersect(Enumerable.Range(90, 50)), false); LogTestRun(leftOpName, "Join1", orderPreserved); result.MustSequenceEqual( q.Join((new int[] { 1, 1, 2, 3, 3 }).AsParallel(), i => i, i => i, (i, j) => i + j), q.ToArray().Join(new int[] { 1, 1, 2, 3, 3 }, i => i, i => i, (i, j) => i + j), false); LogTestRun(leftOpName, "Join2", orderPreserved); result.MustSequenceEqual( q.Join((new int[] { 1, 1, 100, 3, 3 }).AsParallel(), i => new String('a', i), i => new String('a', i), (i, j) => i + j), q.ToArray().Join(new int[] { 1, 1, 100, 3, 3 }, i => new String('a', i), i => new String('a', i), (i, j) => i + j), false); LogTestRun(leftOpName, "Last", orderPreserved); CheckFirstOrLast( result, q.Last(), q.ToArray().Last(), leftOrderDefined); LogTestRun(leftOpName, "Min", orderPreserved); CheckFirstOrLast( result, q.Min(), q.ToArray().Min(), leftOrderDefined); LogTestRun(leftOpName, "Max", orderPreserved); CheckFirstOrLast( result, q.Min(), q.ToArray().Min(), leftOrderDefined); LogTestRun(leftOpName, "OrderBy-ThenBy", orderPreserved); result.MustSequenceEqual( q.Concat(q).OrderBy(i => i % 5).ThenBy(i => - i), q.ToArray().Concat(q).OrderBy(i => i % 5).ThenBy(i => - i), true); LogTestRun(leftOpName, "OrderByDescending-ThenByDescending", orderPreserved); result.MustSequenceEqual( q.Concat(q).OrderByDescending(i => i % 5).ThenByDescending(i => - i), q.ToArray().Concat(q).OrderByDescending(i => i % 5).ThenByDescending(i => - i), true); LogTestRun(leftOpName, "Reverse", orderPreserved); result.MustSequenceEqual( q.Concat(q).Reverse(), q.ToArray().Concat(q).Reverse(), orderPreserved && leftOrderDefined); LogTestRun(leftOpName, "Select", orderPreserved); result.MustSequenceEqual( q.Select(i => 5 * i - 17), q.ToArray().Select(i => 5 * i - 17), orderPreserved && leftOrderDefined); LogTestRun(leftOpName, "SelectMany", orderPreserved); result.MustSequenceEqual( q.SelectMany(i => new int[] { 1, 2, 3 }, (i, j) => i + 100 * j), q.ToArray().SelectMany(i => new int[] { 1, 2, 3 }, (i, j) => i + 100 * j), false); LogTestRun(leftOpName, "SequenceEqual", orderPreserved); if (orderPreserved && leftOrderDefined) { result.MustEqual(q.SequenceEqual(q), true); } else { // We don't check the return value as it can be either true or false q.SequenceEqual(q); } LogTestRun(leftOpName, "Skip", orderPreserved); CheckTakeSkip( result, q.Skip(10), q.ToArray().Skip(10), leftOrderDefined && orderPreserved); LogTestRun(leftOpName, "SkipWhile", orderPreserved); CheckTakeSkip( result, q.SkipWhile(i => i < 30), q.ToArray().SkipWhile(i => i < 30), leftOrderDefined && orderPreserved); LogTestRun(leftOpName, "SkipWhileIndexed", orderPreserved); CheckTakeSkip( result, q.SkipWhile((i, j) => j < 30), q.ToArray().SkipWhile((i, j) => j < 30), leftOrderDefined && orderPreserved); LogTestRun(leftOpName, "Take", orderPreserved); CheckTakeSkip( result, q.Take(10), q.ToArray().Take(10), leftOrderDefined && orderPreserved); LogTestRun(leftOpName, "TakeWhile", orderPreserved); CheckTakeSkip( result, q.TakeWhile(i => i < 30), q.ToArray().TakeWhile(i => i < 30), leftOrderDefined && orderPreserved); LogTestRun(leftOpName, "TakeWhileIndexed", orderPreserved); CheckTakeSkip( result, q.TakeWhile((i, j) => j < 30), q.ToArray().TakeWhile((i, j) => j < 30), leftOrderDefined && orderPreserved); LogTestRun(leftOpName, "Union", orderPreserved); result.MustSequenceEqual( q.Union(Enumerable.Range(90, 50).AsParallel()), q.ToArray().Union(Enumerable.Range(90, 50)), false); LogTestRun(leftOpName, "Where", orderPreserved); result.MustSequenceEqual( q.Where(i => i < 20 || i > 80), q.ToArray().Where(i => i < 20 || i > 80), orderPreserved && leftOrderDefined); LogTestRun(leftOpName, "Zip", orderPreserved); IEnumerable <KeyValuePair <int, int> > zipQ = q.Zip(q, (i, j) => new KeyValuePair <int, int>(i, j)); result.MustSequenceEqual( zipQ.Select(p => p.Key), q.Reverse().Reverse().ToArray(), orderPreserved && leftOrderDefined); result.MustSequenceEqual( zipQ.Select(p => p.Value), q.Reverse().Reverse().ToArray(), orderPreserved && leftOrderDefined); }