public string getRandomTranslation(TextBlock tb, bool[] answerTypes) { List<string> subL; Random rnd = new Random(); int[] options = Enumerable.Range(0, 3).OrderBy(x => rnd.Next()).ToArray(); tb.ClearValue(TextBlock.FontStyleProperty); tb.ClearValue(TextBlock.FontWeightProperty); tb.Tag = this; for (int i = 0; i < options.Length; i++) { switch (options[i]) { case 0: if (!answerTypes[0] || llLexicon.Count == 0) continue; tb.FontStyle = FontStyles.Italic; tb.Text = llLexicon[rnd.Next(llLexicon.Count)]; return tb.Text; case 1: if (!answerTypes[1] || llSynonyms.Count == 0) continue; subL = llSynonyms[rnd.Next(llSynonyms.Count)]; tb.FontWeight = FontWeights.Bold; tb.Text = subL[rnd.Next(subL.Count)]; return tb.Text; case 2: if (!answerTypes[2] || llMacedonian.Count == 0) continue; subL = llMacedonian[rnd.Next(llMacedonian.Count)]; tb.Text = subL[rnd.Next(subL.Count)]; return tb.Text; } } return ""; }
public void SettingTextNeverCreatesMoreThanOneRun () { TextBlock tb = new TextBlock (); string text; Run run; tb.Text = "this is line 1\rthis is line 2"; run = (Run) tb.Inlines[0]; Assert.AreEqual (1, tb.Inlines.Count, "1. Setting Text property should never create more than 1 Run"); Assert.AreEqual ("this is line 1\rthis is line 2", run.Text, "1. The Run's Text should remain unchanged"); tb.Text = "this is line 1\nthis is line 2"; run = (Run) tb.Inlines[0]; Assert.AreEqual (1, tb.Inlines.Count, "2. Setting Text property should never create more than 1 Run"); Assert.AreEqual ("this is line 1\nthis is line 2", run.Text, "2. The Run's Text should remain unchanged"); tb.Text = "this is line 1\r\nthis is line 2"; run = (Run) tb.Inlines[0]; Assert.AreEqual (1, tb.Inlines.Count, "3. Setting Text property should never create more than 1 Run"); Assert.AreEqual ("this is line 1\r\nthis is line 2", run.Text, "3. The Run's Text should remain unchanged"); // now try using the exact same line separator that LineBreak maps to tb.Inlines.Clear (); run.Text = "this is line 1"; tb.Inlines.Add (run); tb.Inlines.Add (new LineBreak ()); run = new Run (); run.Text = "this is line 2"; tb.Inlines.Add (run); text = tb.Text; tb.ClearValue (TextBlock.TextProperty); tb.Text = text; run = (Run) tb.Inlines[0]; Assert.AreEqual (1, tb.Inlines.Count, "4. Setting Text property should never create more than 1 Run"); Assert.AreEqual (text, run.Text, "4. The Run's Text should remain unchanged"); }