public static void DrawText(IDeviceContext dc, string text, Font font, Point pt, Color foreColor, TextFormatFlags flags);
I have a tester application that is for my ExtendedComboBox. All String elements below in the code are contained in my ComboBox components in the tester application. Like the unit test method above, because it returns void? What is another way to test TextRenderer.Drawtext? Is there a replacement for testing the OnDrawItem method for drawing ComboBox text.
[TestMethod()] public void ExtendedComboBoxOnDrawPrefixTest() { ExtendedComboBox cboTest = new ExtendedComboBox (); // List of strings having special characters. string[] items = { "&One", "T&wo", "E!xclamation", " Am@persat ", "H#ash", "Dollar$Sign", "Perc%ent", "Ci^rcumflex", "Ast*erisk", "Hy-phen", "Und_erscore", "pl+us", "Equ=als", "Col:on", "Semi;colon", "Co'mma", "Inverted\"Comma", "Apos'trophe", "Pip|e", "Open{Brace", "Close}Brace", "OpenBr[acket", "CloseBr]acket", "BackS\\lash", "ForwardSl/ash", "LessT<han", "Greate>rThan", "Questio?nMark", "Do.t", "Three", "Four", "Five", "Six", "This is a really extremely long string value for a combobox to display." }; cboTest.Items.AddRange(items); // To test that all the items have the same kind of prefixes for (int index = 0; index < cboTest.Items.Count; index++) { String expectedText = GetExtendedComboBoxText(cboTest, items[index]); Assert.AreEqual(items[index], , String.Format("Item '{0}' returned an string", cboTest.Items[index])); } } /// <summary> /// Compare the ComboBoxText of the passed string with respect to the DC, Font, ForeColor and TextFormatFlags. /// Draw the item /// </summary> private string GetExtendedComboBoxText(Control cboTest, string itemToTest) { TextFormatFlags textFormatflags = TextFormatFlags.NoPrefix; Color foreColor = SystemColors.HighlightText; return (TextRenderer.DrawText(cboTest.CreateGraphics(), itemToTest, cboTest.Font, new Point(cboTest.Bounds.X, cboTest.Bounds.Y), foreColor, textFormatflags)).Text; }