Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Assert.IsTrue/IsFalse for nullable booleans #652

Closed
Grauenwolf opened this issue Nov 1, 2019 · 0 comments · Fixed by #690
Closed

Assert.IsTrue/IsFalse for nullable booleans #652

Grauenwolf opened this issue Nov 1, 2019 · 0 comments · Fixed by #690

Comments

@Grauenwolf
Copy link

Grauenwolf commented Nov 1, 2019

I propose adding the following overloads for handling nullable Booleans:

    public static void IsTrue(bool? condition);
    public static void IsTrue(bool? condition, string message);
    public static void IsTrue(bool? condition, string message, params object[] parameters);
    public static void IsFalse(bool? condition);
    public static void IsFalse(bool? condition, string message);
    public static void IsFalse(bool? condition, string message, params object[] parameters);

They would work exactly like their non-nullable versions.

Reasoning

When checking a Nullable value, we can't use the IsTrue and IsFalse shortcuts. Instead we have to use the longform of Assert.AreEqual( [true|false], which is more error prone because it isn't type safe.

There is also a very minor performance hit with AreEqual because it boxes by default. (You can use AreEqual( (bool?) true, but no one is going to.)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants