Как выполнить модульный тест метода Textrenderer.DrawText в C #
public static void DrawText(IDeviceContext dc, string text, Font font, Point pt, Color foreColor, TextFormatFlags flags);
У меня есть приложение для тестирования, которое для моего ExtendedComboBox. Все элементы String, приведенные ниже в коде, находятся в моих элементах ComboBox в моем приложении для тестирования. Как выполнить юнит-тест над методом, потому что он возвращает void? Какой другой способ проверить TextRenderer.Drawtext? Есть ли замена для проверки метода OnDrawItem для рисования текста ComboBox.
[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;
}