If I have code like the following:
public const string UNSPECIFIED_DATATYPE = "11";
private string SelectedValue = "11";
public bool Validate(object sender, EventArgs eventArgs)
{
return IsValid();
}
private bool IsValid()
{
return (SelectedValue != UNSPECIFIED_DATATYPE);
}
The method signature is actually for an ASP.Net CustomValidatorControl. I have no scope to change this implementation.
SelectedValue will come from a list control and I want to at least test a positive and negative condition.
Ideally, something like:
public void Test_When_SelectedValue_IS_UnSPecified_validate_Returns_False
{
Assert.IsFalse(Validate(UNSPECIFIED_DATATYPE));
}
Obviously, this is not possible due to the method signature of Validate().
How do I write clean and meaningful unit tests to check that the public Validate method with different simulated selected Values?
Thanks
IsValid this method is private and not so good to test
you can extract validation logic in separate class, and then delegate in CustomValidatorControl validation logic into this class. This is help you to test all logic in this class
look at the following example
and ther is tests for this class
and the in method Validate you should write
SelectedValue also you sould map into Validator class