Skip to content

Commit 83eaadc

Browse files
committed
create overloads with default timeout
1 parent 9328bed commit 83eaadc

File tree

2 files changed

+65
-9
lines changed

2 files changed

+65
-9
lines changed

Src/FluentAssertions.Reactive/ReactiveAssertions.cs

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,18 +108,18 @@ public async Task<AndWhichConstraint<ReactiveAssertions<TPayload>, IEnumerable<T
108108
}
109109

110110
/// <summary>
111-
/// Asserts that at least <paramref name="numberOfNotifications"/> notifications are pushed to the <see cref="FluentTestObserver{TPayload}"/> within the next 1 second.<br />
111+
/// Asserts that at least <paramref name="numberOfNotifications"/> notifications are pushed to the <see cref="FluentTestObserver{TPayload}"/> within the next 1 seconds.<br />
112112
/// This includes any previously recorded notifications since it has been created or cleared.
113113
/// </summary>
114114
/// <param name="numberOfNotifications">the number of notifications the observer should have recorded by now</param>
115115
/// <param name="because"></param>
116116
/// <param name="becauseArgs"></param>
117117
public AndWhichConstraint<ReactiveAssertions<TPayload>, IEnumerable<TPayload>> Push(int numberOfNotifications, string because = "", params object[] becauseArgs)
118-
=> Push(numberOfNotifications, TimeSpan.FromSeconds(10), because, becauseArgs);
118+
=> Push(numberOfNotifications, TimeSpan.FromSeconds(1), because, becauseArgs);
119119

120120
/// <inheritdoc cref="Push(int,string,object[])"/>
121121
public Task<AndWhichConstraint<ReactiveAssertions<TPayload>, IEnumerable<TPayload>>> PushAsync(int numberOfNotifications, string because = "", params object[] becauseArgs)
122-
=> PushAsync(numberOfNotifications, TimeSpan.FromSeconds(10), because, becauseArgs);
122+
=> PushAsync(numberOfNotifications, TimeSpan.FromSeconds(1), because, becauseArgs);
123123

124124
/// <summary>
125125
/// Asserts that at least 1 notification is pushed to the <see cref="FluentTestObserver{TPayload}"/> within the next 1 second.<br />
@@ -266,7 +266,11 @@ public AndConstraint<ReactiveAssertions<TPayload>> NotComplete(string because =
266266
/// Zero or more objects to format using the placeholders in <paramref name="because"/>.
267267
/// </param>
268268
/// <exception cref="ArgumentNullException"><paramref name="predicate"/> is <c>null</c>.</exception>
269-
public AndConstraint<ReactiveAssertions<TPayload>> PushMatch([NotNull] Expression<Func<TPayload, bool>> predicate, TimeSpan timeout, string because = "", params object[] becauseArgs)
269+
public AndConstraint<ReactiveAssertions<TPayload>> PushMatch(
270+
[NotNull] Expression<Func<TPayload, bool>> predicate,
271+
TimeSpan timeout,
272+
string because = "",
273+
params object[] becauseArgs)
270274
{
271275
if (predicate == null) throw new ArgumentNullException(nameof(predicate));
272276

@@ -303,9 +307,33 @@ public AndConstraint<ReactiveAssertions<TPayload>> PushMatch([NotNull] Expressio
303307
return new AndConstraint<ReactiveAssertions<TPayload>>(this);
304308
}
305309

306-
/// <inheritdoc cref="PushMatch"/>
307-
public async Task<AndConstraint<ReactiveAssertions<TPayload>>> PushMatchAsync([NotNull] Expression<Func<TPayload, bool>> predicate, TimeSpan timeout,
308-
string because = "", params object[] becauseArgs)
310+
/// <summary>
311+
/// Asserts that at least one notification matching <paramref name="predicate"/> was pushed to the <see cref="FluentTestObserver{TPayload}"/>
312+
/// within the next 1 second.<br />
313+
/// This includes any previously recorded notifications since it has been created or cleared.
314+
/// </summary>
315+
/// <param name="predicate">A predicate to match the items in the collection against.</param>
316+
/// <param name="timeout">the maximum time to wait for the notification to arrive</param>
317+
/// <param name="because">
318+
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
319+
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
320+
/// </param>
321+
/// <param name="becauseArgs">
322+
/// Zero or more objects to format using the placeholders in <paramref name="because"/>.
323+
/// </param>
324+
/// <exception cref="ArgumentNullException"><paramref name="predicate"/> is <c>null</c>.</exception>
325+
public AndConstraint<ReactiveAssertions<TPayload>> PushMatch(
326+
[NotNull] Expression<Func<TPayload, bool>> predicate,
327+
string because = "",
328+
params object[] becauseArgs)
329+
=> PushMatch(predicate, TimeSpan.FromSeconds(1), because, becauseArgs);
330+
331+
/// <inheritdoc cref="PushMatch(Expression{Func{TPayload, bool}},TimeSpan,string,object[])"/>
332+
public async Task<AndConstraint<ReactiveAssertions<TPayload>>> PushMatchAsync(
333+
[NotNull] Expression<Func<TPayload, bool>> predicate,
334+
TimeSpan timeout,
335+
string because = "",
336+
params object[] becauseArgs)
309337
{
310338
if (predicate == null)
311339
throw new ArgumentNullException(nameof(predicate));
@@ -342,6 +370,13 @@ public async Task<AndConstraint<ReactiveAssertions<TPayload>>> PushMatchAsync([N
342370
return new AndWhichConstraint<ReactiveAssertions<TPayload>, IEnumerable<TPayload>>(this, notifications);
343371
}
344372

373+
/// <inheritdoc cref="PushMatch(Expression{Func{TPayload, bool}},string,object[])"/>
374+
public Task<AndConstraint<ReactiveAssertions<TPayload>>> PushMatchAsync(
375+
[NotNull] Expression<Func<TPayload, bool>> predicate,
376+
string because = "",
377+
params object[] becauseArgs)
378+
=> PushMatchAsync(predicate, TimeSpan.FromSeconds(1), because, becauseArgs);
379+
345380
protected Task<IList<Recorded<Notification<TPayload>>>> GetRecordedNotifications(TimeSpan timeout) =>
346381
Observer.RecordedNotificationStream
347382
.TakeUntil(recorded => recorded.Value.Kind == NotificationKind.OnError)

Tests/FluentAssertions.Reactive.Specs/ReactiveAssertionSpecs.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ public void When_the_observable_is_expected_to_fail_but_does_not_it_should_throw
126126

127127
observer.Error.Should().BeNull();
128128
}
129-
130-
129+
131130
[Fact]
132131
public void When_the_observable_completes_as_expected_it_should_not_throw()
133132
{
@@ -159,5 +158,27 @@ public void When_the_observable_is_expected_to_complete_but_does_not_it_should_t
159158
observer.Error.Should().BeNull();
160159
}
161160

161+
[Fact]
162+
public void When_the_observable_pushes_an_expected_match_it_should_not_throw()
163+
{
164+
var scheduler = new TestScheduler();
165+
var observable = scheduler.CreateColdObservable(
166+
OnNext(100, 1),
167+
OnNext(200, 2),
168+
OnNext(300, 3));
169+
170+
// observe the sequence
171+
using var observer = observable.Observe(scheduler);
172+
// push subscriptions
173+
scheduler.AdvanceTo(400);
174+
175+
// Act
176+
Action act = () => observer.Should().PushMatch(i => i > 1);
177+
178+
// Assert
179+
act.Should().NotThrow();
180+
181+
observer.RecordedNotifications.Should().BeEquivalentTo(observable.Messages);
182+
}
162183
}
163184
}

0 commit comments

Comments
 (0)