简体   繁体   中英

MSTest: How to assert positive if one of 3 asserts are valid?

I have an IntegrationTest where I want to test the result of a linq query. The linq query goes something like this

where myObject.fieldA.StartsWith(aString) 
   || myObject.fieldB.StartsWith(aString) 
   || myObject.fieldC.StartsWith(aString)

Now I want write the test like so:

foreach(var result in results)
{
   StringAssert.StartsWith(result.fieldA, aString);
   StringAssert.StartsWith(result.fieldB, aString);
   StringAssert.StartsWith(result.fieldC, aString);   
}

but of course that is not correct, because it should assert valid when one of the 3 above is valid.

Any idea how to do that using MSTest ?

You can work around it by using

Assert.IsTrue(
    result.fieldA.StartsWith(astring) || 
    result.fieldB.StartsWith(astring) ||
    result.fieldC.StartsWith(astring)
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM