Skip to content

Assert.IsTrue/IsFalse for nullable booleans #652

Closed

Description

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions