Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4034330
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:57:31+00:00 2026-05-20T11:57:31+00:00

There are a number of operators that are timer based, and I although I

  • 0

There are a number of operators that are timer based, and I although I don’t have a concrete example, would think it common to create new operators that utilise timers. So how would you go about writing a test that runs synchronously for these operators?

As an example, how could I go about unit testing an operator such as BufferWithTime?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T11:57:31+00:00Added an answer on May 20, 2026 at 11:57 am

    The most accessible way to do the test would be to use TestScheduler:

    var source = new Subject<int>();
    var scheduler = new TestScheduler();
    
    var outputValues = new List<IList<int>>();
    
    source
        .BufferWithTime(TimeSpan.FromTicks(500), scheduler)
        .Subscribe(x => outputValues.Add(x));
    
    scheduler.RunTo(1);
    source.OnNext(1);
    
    scheduler.RunTo(100);
    source.OnNext(2);
    
    scheduler.RunTo(200);
    source.OnNext(3);
    
    scheduler.RunTo(501);
    source.OnNext(4);
    
    scheduler.RunTo(1001);
    
    Assert.AreEqual(2, outputValues.Count);
    Assert.AreEqual(3, outputValues[0].Count);
    Assert.AreEqual(1, outputValues[1].Count);
    

    In addition you can also use a bunch of types from System.Reactive.Testing.dll, which makes things even easier but takes a dependency on Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll which in turn has a dependency on System.Web.dll (not available in the client profile).

    // using System.Reactive.Testing;
    // using System.Reactive.Testing.Mocks;
    
    var scheduler = new TestScheduler();
    
    var source = scheduler.CreateColdObservable(
        new Recorded<Notification<int>>(0, new Notification<int>.OnNext(1)),
        new Recorded<Notification<int>>(100, new Notification<int>.OnNext(2)),
        new Recorded<Notification<int>>(400, new Notification<int>.OnNext(3)),
        new Recorded<Notification<int>>(500, new Notification<int>.OnNext(4))
        )
        .BufferWithTime(TimeSpan.FromTicks(500), scheduler);
    
    var observer = new MockObserver<IList<int>>(scheduler);
    
    source.Subscribe(observer);
    
    scheduler.RunTo(1001);
    
    Assert.AreEqual(2, observer.Count);
    Assert.AreEqual(3, observer[0].Value.Value.Count);
    Assert.AreEqual(1, observer[1].Value.Value.Count);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a maximum number of characters that can be written to a file
Is there a maximum number of email addresses that can be included in a
I have to create a function bitParity(int x) that takes an integer and returns
I have a JSF validator that checks whether a Container Number string conforms to
Is there a high precision timer that I can use to benchmark the amount
Are there any efficient bitwise operations I can do to get the number of
Is there a managed system-level sequential number generator? DateTime.Now.Ticks won't do because the operations
There are a number of email regexp questions popping up here, and I'm honestly
There are a number of great Javascript libraries\frameworks out there (jQuery, Prototype, MooTools, etc.),
There are a number of run-time differences in compatible code between these two versions

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.