The most affordable way to do this is 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);
Alternatively, you can also use the type group from System.Reactive.Testing.dll , which makes things even easier, but requires a dependency on Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll , which in turn depends on System.Web.dll (not available in client profile).
source share