Skip to content

Commit

Permalink
Merge pull request #1115 from akarnokd/TestSchedulerParamValidationFix
Browse files Browse the repository at this point in the history
Add more argument validation to TestScheduler.Start
  • Loading branch information
danielcweber authored Dec 21, 2019
2 parents 34ea00d + 5d769c3 commit c7c3b59
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Rx.NET/Source/src/Microsoft.Reactive.Testing/TestScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,24 @@ protected override long ToRelative(TimeSpan timeSpan)
/// <param name="disposed">Virtual time at which to dispose the subscription.</param>
/// <returns>Observer with timestamped recordings of notification messages that were received during the virtual time window when the subscription to the source sequence was active.</returns>
/// <exception cref="ArgumentNullException"><paramref name="create"/> is null.</exception>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="subscribed"/> is less than <paramref name="created"/>.</exception>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="disposed"/> is less than <paramref name="created"/> or <paramref name="subscribed"/>.</exception>
public ITestableObserver<T> Start<T>(Func<IObservable<T>> create, long created, long subscribed, long disposed)
{
if (create == null)
{
throw new ArgumentNullException(nameof(create));
}

if (subscribed < created)
{
throw new ArgumentOutOfRangeException(nameof(subscribed));
}
if (disposed < created || disposed < subscribed)
{
throw new ArgumentOutOfRangeException(nameof(disposed));
}

var source = default(IObservable<T>);
var subscription = default(IDisposable);
var observer = CreateObserver<T>();
Expand All @@ -108,6 +119,7 @@ public ITestableObserver<T> Start<T>(Func<IObservable<T>> create, long created,
/// <param name="disposed">Virtual time at which to dispose the subscription.</param>
/// <returns>Observer with timestamped recordings of notification messages that were received during the virtual time window when the subscription to the source sequence was active.</returns>
/// <exception cref="ArgumentNullException"><paramref name="create"/> is null.</exception>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="disposed"/> is less than <see cref="ReactiveTest.Subscribed"/>.</exception>
public ITestableObserver<T> Start<T>(Func<IObservable<T>> create, long disposed)
{
if (create == null)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reactive.Concurrency;
using System.Reactive.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Reactive.Testing;
using Xunit;

namespace ReactiveTests.Tests
{

public class TestSchedulerTest
{
[Fact]
public void Test_ArgumentChecking()
{
ReactiveAssert.Throws<ArgumentNullException>(() => new TestScheduler().Start<int>(null));
ReactiveAssert.Throws<ArgumentNullException>(() => new TestScheduler().Start<int>(null, 10));
ReactiveAssert.Throws<ArgumentOutOfRangeException>(() => new TestScheduler().Start(() => Observable.Empty<int>(), 10));
ReactiveAssert.Throws<ArgumentOutOfRangeException>(() => new TestScheduler().Start(() => Observable.Empty<int>(), 10, 15, 5));
}
}
}

0 comments on commit c7c3b59

Please sign in to comment.