Skip to content

Document behavioral differences with fluentassertions #573

@vbreuss

Description

@vbreuss
  1. A null object is considered not equal to any type:
    object someObject = null;
    // Does throw with fluentassertions, but not with aweXpect
    await Expect.That(someObject).IsNot(typeof(DateTime));
    
    // or
    
    string aString = null;
    // Does throw with fluentassertions, but not with aweXpect
     await Expect.That(aString).IsNotExactly(typeof(string));

The same holds for e.g. IsNotBetween:

Expect.That((int?)null).IsNotBetween(0).And(1); // succeeds
  1. When checking "contains at most" against null, it throws:

    string actual = null;
    // Does not throw with fluentassertions, but does with aweXpect
    Expect.That(actual).Contains(expectedSubstring).AtMost(1.Times());
    Expect.That(actual).Contains(expectedSubstring).LessThan(1.Times());
  2. All().Be does not mix type and instances (see AllBeAssignableTo behaving not like foreach BeAssignableTo fluentassertions/fluentassertions#1006)

    var collection = new object[] { typeof(int), 2, typeof(int) };
    collection.Should().AllBeAssignableTo<int>(); // Succeeds with fluentassertions
    await Expect.That(collection).All().Are<int>(); // Fails with aweXpect
  3. DateTime with different Kind is considered different in aweXpect

    var actual = new DateTime(2025, 1, 1, 0, 0, 0, DateTimeKind.Local);
    var expected = new DateTime(2025, 1, 1, 0, 0, 0, DateTimeKind.Utc);
    actual.Should().Be(expected); // Succeeds with fluentassertions
    await Expect.That(actual).IsEqualTo(expected); // Fails with aweXpect
  4. automatic flattening of AggregateException:

    Func<Task> act = () => throw new AggregateException(new ArgumentException("It is nested within an `AggregateException`"));
    act.Should().Throw<ArgumentException>(); // Succeeds with fluentassertions
    await Expect.That(act).Throws<ArgumentException>(); // Fails with aweXpect
  5. BeInRange for numbers throws an XUnitException instead of ArgumentException when minimum or maximum is NaN.
    Same for IsEqualTo("").AsWildcard() (which throws an ArgumentException on fluentassertions)

Metadata

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