3
GUI에서 입력 한 데이터의 유효성을 검사하고 올바르게 기록 할 수 있는지 테스트하기위한 단위 테스트를 작성하고 있습니다. 현재 다음과 같은 코드를 사용하고 있습니다.프로그래밍 방식으로 TextBox에서 유효성 검사 호출
using (MyControl target = new MyControl())
{
PrivateObject accessor = new PrivateObject(target);
TextBox inputTextBox = (TextBox)accessor.GetField("InputTextBox");
string expected, actual;
expected = "Valid input text.";
inputTextBox.Text = expected;
// InputTextBox.TextChanged sets FieldData.Input
actual = target.FieldData.Input;
Assert.AreEqual(expected, actual);
}
그러나 TextChanged 이벤트보다 Validated 이벤트를 사용하고 싶습니다.
using (MyControl target = new MyControl())
{
PrivateObject accessor = new PrivateObject(target);
TextBox inputTextBox = (TextBox)accessor.GetField("InputTextBox");
string expected, actual;
bool valid;
expected = "Valid input text.";
inputTextBox.Text = expected;
valid = inputTextBox.Validate();
// InputTextBox.Validating returns e.Cancel = true/false
// InputTextBox.Validated sets FieldData.Input
Assert.IsTrue(valid);
actual = target.FieldData.Input;
Assert.AreEqual(expected, actual);
}
Validated 이벤트를 지원하는 텍스트 상자 나 다른 컨트롤에서 유효성 검사를 호출하려면 어떻게해야합니까? inputTextBox.Validate()
대신 무엇을 써야합니까? 나는 C#과 VB.Net에 익숙하다.