示例#1
0
    public void QuantityIsNotInRange()
    {
        int expectedLower = 1;
        int expectedUpper = 3;
        int actualValue   = 3;

        // MSTest does not support this case.

        // NUnit
        Assert.That(actualValue, Is.Not.InRange(expectedLower, expectedUpper), () => "Some context");
        // Some context
        //  Expected: not in range (1,3)
        //  But was: 3

        // XUnit
        XUnitAssert.NotInRange(actualValue, expectedLower, expectedUpper); // Supports a custom IComparer<T>
        //Assert.NotInRange() Failure
        //Range: (1 - 3)
        //Actual: 3

        // Fluent
        actualValue.Should().NotBeInRange(expectedLower, expectedUpper, "SOME REASONS");
        // Expected actualValue to not be between 1 and 3 because SOME REASONS, but found 3.

        // Shouldly
        actualValue.ShouldNotBeInRange(expectedLower, expectedUpper, "Some context");
        // actualValue
        //   should not be in range
        // { from = 1, to = 3 }
        //   but was
        // 3
        //
        // Additional Info:
        //  Some context
    }