TUnit icon indicating copy to clipboard operation
TUnit copied to clipboard

Migrating from Fluentassertions, is there a good way to rewrite property chaining?

Open ChristianSauer opened this issue 8 months ago • 3 comments

I.e. something like this:


        result
            .Should()
            .BeOfType<EventHandled>()
            .Subject.ConsecutiveEvents[0]
            .Should()
            .Be(@event.Source);

I can replicate the first part easy enough

  await Assert.That(result).IsTypeOf<EventHandled>

But how to access the ConsecutiveEvents?

ChristianSauer avatar Apr 12 '25 19:04 ChristianSauer

I need to expand the chaining functionality for properties etc.

It doesn't exist right now, and would require another Assertion line where you manually pass the property into a new Assert.That() call.

The syntax that I'll probably build though would most likely look like:

Assert.That(obj)
.IsTypeOf<Something>()
.And
.Item(x => x.ConsecutiveEvents[0])
.IsEqualTo("Foo");

thomhurst avatar Apr 12 '25 20:04 thomhurst

Thanks, that looks sensible

ChristianSauer avatar Apr 13 '25 18:04 ChristianSauer

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar May 14 '25 00:05 github-actions[bot]

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Jun 14 '25 00:06 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Jun 19 '25 00:06 github-actions[bot]