Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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....

like image 531
Moon Avatar asked Jun 28 '13 07:06

Moon


People also ask

What is C in simple words?

C Introduction C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

Is C or C++ same?

While C and C++ may sound similar, their features and usage differ. C is a procedural programming language that support objects and classes. On the other hand C++ is an enhanced version of C programming with object-oriented programming support.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.


2 Answers

Assert.IsTrue((myString.Substring(3,3) == "DEF" || myString.Substring(3,3) == "RED")?true:false,"Failed");
like image 103
Cris Avatar answered Sep 19 '22 18:09

Cris


Using NUnit, the AnyOf constraint works:

Assert.That(myString.Substring(3,3), Is.AnyOf("DEF", "RED"));
like image 38
Christopher Scott Avatar answered Sep 17 '22 18:09

Christopher Scott