I have this property:
public SubjectStatus Status
{
get { return status; }
set
{
if (Enum.IsDefined(typeof(SubjectStatus), value))
{
status = value;
}
else
{
Debug.Fail("Error setting Subject.Status", "There is no SubjectStatus enum constant defined for that value.");
return;
}
}
}
and this unit test
[Test]
public void StatusProperty_StatusAssignedValueWithoutEnumDefinition_StatusUnchanged()
{
Subject subject = new TestSubjectImp("1");
// assigned by casting from an int to a defined value
subject.Status = (SubjectStatus)2;
Assert.AreEqual(SubjectStatus.Completed, subject.Status);
// assigned by casting from an int to an undefined value
subject.Status = (SubjectStatus)100;
// no change to previous value
Assert.AreEqual(SubjectStatus.Completed, subject.Status);
}
Is there a way I can prevent Debug.Fail displaying a message box when I run my tests, but allow it to show me one when I debug my application?