Search code examples
c#unit-testingassertions

c# - Asserting with OR condition


i am checking a string for three characters

Assert.AreEqual(myString.Substring(3,3), "DEF", "Failed as DEF  was not observed");

the thing is here it can be DEF or RES, now to handle this what i can think of is the following

bool check = false;
if( myString.Substring(3,3) == "DEF" || myString.Substring(3,3) == "RED" ) 
check = true;

Assert.IsTrue(check,"Failed");
Console.WriteLine(""Passed);

IS THERE a way i can use some OR thing within Assert

p.s i'm writing unit test & yes i will use ternary operator instead....


Solution

  • Assert.IsTrue((myString.Substring(3,3) == "DEF" || myString.Substring(3,3) == "RED")?true:false,"Failed");