dennisdoomen / dennisdoomen/fluentassertions.mockly

[API Proposal]: Add ordering, count and timing assertions on RequestCollection

Closed
#80 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
0
Forks
0
Avg merge
11d 7h
Merged PRs (30d)
4

Description

## Motivation

Ordering can only be asserted through `HttpMockAssertions.HaveCalledInOrder(params RequestMockResponseBuilder[])`. That works, but it requires you to keep a reference to every builder:

```csharp
var auth = mock.ForPost("/token").RespondsWithStatus(HttpStatusCode.OK);
var data = mock.ForGet("/api/data").RespondsWithJsonContent(payload);
// ...
mock.Should().HaveCalledInOrder(auth, data);
```

If you are asserting on a captured `RequestCollection` rather than the mock itself, there is no ordering assertion at all — even though `CapturedRequest` already exposes both `Sequence` and `Timestamp`.

## Proposed API

Ordering by URL pattern, no builder references needed:

```csharp
requests.Should().ContainRequestsInOrder("/token", "/api/data");
requests.Should().ContainRequestsInOrder(
(HttpMethod.Post, "/token"),
(HttpMethod.Get, "/api/data"));
```

Count assertions, which are also missing today:

```csharp
requests.Should().ContainRequestsFor("/api/users", Exactly.Times(3));
```

Timing, useful together with the core `After(TimeSpan)` latency feature:

```csharp
requests.Should().AllHaveBeenSentWithin(TimeSpan.FromSeconds(5));
```

## Notes

- `Sequence` already drives `HaveCalledInOrder`, so the ordering logic can largely be reused.
- Failure messages should print the actual observed order, which `HaveCalledInOrder` already does well.
- The timing assertion is the least certain of the three — worth confirming it does not just encourage flaky tests.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reading HttpMockAssertions.HaveCalledInOrder and the RequestCollection and CapturedRequest APIs, especially Sequence and Timestamp. Compare the proposed ordering, count, and timing assertions with the existing behavior, and confirm whether timing avoids encouraging flaky tests. Done means the agreed RequestCollection assertions and their observed-order or timing failure behavior are covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.