Badgerati/Edison

Add logic for conditional assertions

Badgerati opened this issue · 1 comments

Say if you want to assert that either AssertFactory.Instance.AreEqual(...) or AssertFactory.Instance.IsLessThan(...) passes, and even if one fails it's considered a pass. Where as if both fail it's a proper assertion failure.

For now just an Or will do, as an And is technically just consecutive Assert calls.

This new AssertFactory.Instance.Or(...) should take a params of assertion actions.

There is a new AssertFactory.Instance.Or(...) method. This method takes an array of Func<IAssert> calls.

Example:

var assert = AssertFactory.Instance;
assert .Or(() => assert .AreEqual(1, 1), () =>  assert.AreEqual(5, 5));

If one of the assertions pass, then the Or assert passes. If all the assertions fail, then the Or assert fails, and will return the error messages from all assertions.

Further to this, the assertion methods now return the current IAssert instance, meaning you can chain assertion calls:

var assert = AssertFactory.Instance;
assert.AreEqual(1, 1).IsNotNull("Hello");