/// <summary> /// Adds the text to RTB. /// </summary> /// <param name="richTextBox">The rich text box.</param> /// <param name="stackCard">The stack card.</param> /// <remarks>Documented by Dev08, 2009-05-12</remarks> private void AddTextToRTB(RichTextBox richTextBox, StackCard stackCard) { richTextBox.SuspendLayout(); AnswerResult result = stackCard.Promoted ? AnswerResult.Correct : (stackCard.Result == AnswerResult.Almost ? AnswerResult.Almost : AnswerResult.Wrong); System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"<[^>]*>"); //to replace html code if any bool questionRTL = stackCard.QuestionCulture.TextInfo.IsRightToLeft; bool answerRTL = stackCard.AnswerCulture.TextInfo.IsRightToLeft; richTextBox.BackColor = StackCardBackColors.ContainsKey(result) ? StackCardBackColors[result] : SystemColors.Window; richTextBox.ForeColor = this.ForeColor; string text = Environment.NewLine; string questionRLE = (questionRTL ? Convert.ToString(Convert.ToChar(RLE)) : string.Empty); text += questionRLE + regex.Replace(stackCard.Question, String.Empty) + Environment.NewLine; text += questionRLE + regex.Replace(stackCard.QuestionExample, String.Empty) + Environment.NewLine; text += Environment.NewLine; string answerRLE = (answerRTL ? Convert.ToString(Convert.ToChar(RLE)) : string.Empty); if (stackCard.LearnMode == MLifter.BusinessLayer.LearnModes.Sentence && stackCard.AnswerExample.Length > 0) { text += answerRLE + regex.Replace(stackCard.AnswerExample, String.Empty) + Environment.NewLine; text += answerRLE + regex.Replace(stackCard.Answer, String.Empty) + Environment.NewLine; } else { text += answerRLE + regex.Replace(stackCard.Answer, String.Empty) + Environment.NewLine; text += answerRLE + regex.Replace(stackCard.AnswerExample, String.Empty) + Environment.NewLine; } richTextBox.Visible = true; richTextBox.Text = text; richTextBox.Font = this.Font; richTextBox.SelectAll(); richTextBox.SelectionFont = this.Font; richTextBox.Select(0, 0); richTextBox.ResumeLayout(); }
public void CardStackUnitTest() { if (TestInfrastructure.IsActive(TestContext)) { using (Dictionary dictionary = TestInfrastructure.GetConnection(TestContext)) { DictionaryTest.FillDictionary(dictionary); CardStack target = new CardStack(new LearnLogic(MLifterTest.DAL.OpenUserProfileTests.GetUserAdmin, (MLifter.DAL.DataAccessErrorDelegate)delegate { return; })); target.StackChanged += new EventHandler(CardStack_StackChanged); cardstackChanged = false; target.Clear(); Assert.IsTrue(cardstackChanged, "CardStackChanged event did not fire for Clear."); int cardcount = 0; int rightcount = 0; TimeSpan duration = new TimeSpan(0); foreach (ICard card in dictionary.Cards.Cards) { for (int i = 0; i < 100; i++) { cardcount++; bool promoted = GetRandBool(); if (promoted) rightcount++; DateTime asked = DateTime.Now - new TimeSpan(0, 0, random.Next(1000)); DateTime answered = DateTime.Now; duration += (answered - asked); AnswerResult result = promoted ? AnswerResult.Correct : AnswerResult.Wrong; StackCard stackCard = new StackCard(card, result, promoted, EQueryDirection.Question2Answer, LearnModes.Word, asked, answered, Thread.CurrentThread.CurrentCulture, Thread.CurrentThread.CurrentCulture, card.Answer.ToString(), 0, 0, false, dictionary, 0); cardstackChanged = false; target.Push(stackCard); Assert.IsTrue(cardstackChanged, "CardStackChanged event did not fire for Push."); } } Assert.AreEqual(cardcount, target.Count, "Not all cards were added to the stack."); Assert.AreEqual(duration, target.SessionDuration, "Session duration sum does not match."); Assert.AreEqual(rightcount, target.RightCount, "RightCount does not match."); Assert.AreEqual(cardcount - rightcount, target.WrongCount, "WrongCount does not match."); Assert.IsTrue(rightcount > 0 && target.VisibleStack.Count > 0, "No StackCards in VisibleStack property."); } } }