Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more argument validation to TestScheduler.Start #1115

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}
}
}