Fluentassertions: Add ability to time an action

Created on 18 Feb 2017  路  4Comments  路  Source: fluentassertions/fluentassertions

I had a need to ensure a method took a certain amount of time which I know is a pretty unusual use case but here's the code if you want to include it in the framework. It also supports fluent chaining which is lacking in the other action assertions and I can see why as it makes it difficult to know when to invoke the action.

feature

Most helpful comment

We have improved this area for the upcoming 5.0.0 in #653 and added

BeCloseTo(TimeSpan expectedDuration, TimeSpan precision, string because = "", params object[] becauseArgs)

Here are two extracts from the tests of what this enables you to assert.

subject.ExecutionTimeOf(s => s.Sleep(510)).Should().BeCloseTo(500.Milliseconds(), 50.Milliseconds());
someAction.ExecutionTime().Should().BeCloseTo(500.Milliseconds(), 50.Milliseconds());

All 4 comments

We have improved this area for the upcoming 5.0.0 in #653 and added

BeCloseTo(TimeSpan expectedDuration, TimeSpan precision, string because = "", params object[] becauseArgs)

Here are two extracts from the tests of what this enables you to assert.

subject.ExecutionTimeOf(s => s.Sleep(510)).Should().BeCloseTo(500.Milliseconds(), 50.Milliseconds());
someAction.ExecutionTime().Should().BeCloseTo(500.Milliseconds(), 50.Milliseconds());

@carlin-q-scott is that what you meant?

@sw-carlin seems you switched to a new GitHub profile?

I use both profiles but I'm on my personal one way less frequently. Yes, the 5.0 release addressed my ask.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dennisdoomen picture dennisdoomen  路  3Comments

felpel picture felpel  路  4Comments

shift-evgeny picture shift-evgeny  路  5Comments

Wolfsblvt picture Wolfsblvt  路  5Comments

FabianNitsche picture FabianNitsche  路  4Comments