public static void DrawText(IDeviceContext dc, string text, Font font, Point pt, Color foreColor, TextFormatFlags flags);
I have a tester application which for my ExtendedComboBox. All the String items given below in code are there in my ComboBox items in my tester Application. How to unit test above method because it returns void? What is the other way to test TextRenderer.Drawtext? Is there any replacement to test OnDrawItem method for drawing the 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;
}