public async Task GET() { Guid testId = Guid.Empty; MultiLineTextEdit multiLineTextEdit = null; var isAsyncComplete = false; var hasError = false; EnqueueConditional(() => isAsyncComplete); await Setup(); try { var allMultiLineTexts = await MultiLineTextList.GetAllAsync(); testId = allMultiLineTexts.First().Id; multiLineTextEdit = await MultiLineTextEdit.GetMultiLineTextEditAsync(testId); } catch { hasError = true; } finally { EnqueueCallback( () => Assert.IsFalse(hasError), () => Assert.IsNotNull(multiLineTextEdit), () => Assert.IsTrue(multiLineTextEdit.Lines.Count >= 2), () => Assert.AreEqual(testId, multiLineTextEdit.Id) ); EnqueueTestComplete(); Teardown(); isAsyncComplete = true; } }
/// <summary> /// Gets all songs in DB for this user, and calls PopulateItems. /// </summary> private async Task StartPopulateAllSongsAsync() { #region Thinking var targetId = Guid.NewGuid(); History.Events.ThinkingAboutTargetEvent.Publish(targetId); #endregion var allMultiLineTexts = await MultiLineTextList.GetAllAsync(); History.Events.ThinkedAboutTargetEvent.Publish(targetId); #region Sort MLT by Title Comparison (Comparison<MultiLineTextEdit> comparison = (a, b) =>) Comparison <MultiLineTextEdit> comparison = (a, b) => { //WE'RE GOING TO TEST CHAR ORDER IN ALPHABET string aTitle = a.Title.ToLower(); string bTitle = b.Title.ToLower(); //IF THEY'RE THE SAME TITLES IN LOWER CASE, THEN THEY ARE EQUAL if (aTitle == bTitle) { return(0); } //ONLY NEED TO TEST CHARACTERS UP TO LENGTH int shorterTitleLength = aTitle.Length; bool aIsShorter = true; if (bTitle.Length < shorterTitleLength) { shorterTitleLength = bTitle.Length; aIsShorter = false; } int result = 0; //assume a and b are equal (though we know they aren't if we've reached this point) for (int i = 0; i < shorterTitleLength; i++) { if (aTitle[i] < bTitle[i]) { result = -1; break; } else if (aTitle[i] > bTitle[i]) { result = 1; break; } } //IF THEY ARE STILL EQUAL, THEN THE SHORTER PRECEDES THE LONGER if (result == 0) { if (aIsShorter) { result = -1; } else { result = 1; } } return(result); }; #endregion ModelList = allMultiLineTexts; List <MultiLineTextEdit> songs = null; #region Thinking (try..) targetId = Guid.NewGuid(); History.Events.ThinkingAboutTargetEvent.Publish(targetId); try { #endregion songs = (from multiLineText in allMultiLineTexts where multiLineText.AdditionalMetadata.Contains(MultiLineTextEdit.MetadataEntrySong) select multiLineText).ToList(); songs.Sort(comparison); #region (...finally) Thinked } finally { History.Events.ThinkedAboutTargetEvent.Publish(targetId); } #endregion //CACHE ALL SONGS SO WE WON'T HAVE TO DOWNLOAD THEM AGAIN. THIS IS ASSUMING MY CURRENT NAVIGATION //STRUCTURE WHICH MEANS THAT YOU CAN'T ADD SONGS WITHOUT RECREATING THIS ENTIRE VIEWMODEL. //THIS CACHE WILL BE USED FOR FILTERING. SortedModelListCache = songs; PopulateItems(); }