Ejemplo n.º 1
0
        /// <summary>
        /// Starts the test scheduler and uses the specified virtual time to create, subscribe and dispose the subscription to the sequence
        /// obtained through the factory function. Scheduler is passed to the subscription using the provided operator context.
        /// Default virtual times are used for <see cref="ReactiveTest.Created">factory invocation</see> and <see cref="ReactiveTest.Subscribed">sequence subscription</see>.
        /// </summary>
        /// <typeparam name="T">The element type of the observable sequence being tested.</typeparam>
        /// <param name="scheduler">The scheduler.</param>
        /// <param name="context">The context.</param>
        /// <param name="create">Factory method to create an observable sequence.</param>
        /// <param name="created">The created time.</param>
        /// <param name="subscribed">The subscribed time.</param>
        /// <param name="disposed">Virtual time at which to dispose the subscription.</param>
        /// <param name="recovery">Optional state container to reload state from at subscription time.</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>
        public static ITestableObserver <T> Start <T>(
            this TestScheduler scheduler,
            IOperatorContext context,
            Func <ISubscribable <T> > create,
            long created,
            long subscribed,
            long disposed,
            IOperatorStateContainer recovery = null)
        {
            if (scheduler == null)
            {
                throw new ArgumentNullException(nameof(scheduler));
            }

            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (create == null)
            {
                throw new ArgumentNullException(nameof(create));
            }

            if (created > subscribed)
            {
                throw new ArgumentOutOfRangeException(nameof(created));
            }

            if (subscribed > disposed)
            {
                throw new ArgumentOutOfRangeException(nameof(subscribed));
            }

            var source       = default(ISubscribable <T>);
            var subscription = default(ISubscription);
            var observer     = scheduler.CreateObserver <T>();

            scheduler.ScheduleAbsolute(default(object), created, (s, state) => source = create());
            scheduler.ScheduleAbsolute(
                default(object),
                subscribed,
                (s, state) =>
            {
                subscription = source.Subscribe(observer);

                var reader = default(IOperatorStateReaderFactory);

                if (recovery != null)
                {
                    reader = recovery.CreateReader();
                }

                new SubscriptionInitializeVisitor(subscription).Initialize(context, reader);
            });
            scheduler.ScheduleAbsolute(default(object), disposed, (s, state) => subscription.Dispose());
            scheduler.Start();
            return(observer);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Starts the test scheduler and uses the specified virtual time to create, subscribe and dispose the subscription to the sequence
        /// obtained through the factory function. Scheduler is passed to the subscription using the provided operator context.
        /// Default virtual times are used for <see cref="ReactiveTest.Created">factory invocation</see> and <see cref="ReactiveTest.Subscribed">sequence subscription</see>.
        /// </summary>
        /// <typeparam name="T">The element type of the observable sequence being tested.</typeparam>
        /// <param name="scheduler">The scheduler.</param>
        /// <param name="create">Factory method to create an observable sequence.</param>
        /// <param name="created">The created time.</param>
        /// <param name="subscribed">The subscribed time.</param>
        /// <param name="disposed">Virtual time at which to dispose the subscription.</param>
        /// <param name="recovery">Optional state container to reload state from at subscription time.</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>
        public static ITestableObserver <T> Start <T>(
            this TestScheduler scheduler,
            Func <ISubscribable <T> > create,
            long created,
            long subscribed,
            long disposed,
            IOperatorStateContainer recovery = null)
        {
            if (scheduler == null)
            {
                throw new ArgumentNullException(nameof(scheduler));
            }

            return(scheduler.Start(scheduler.CreateContext(), create, created, subscribed, disposed, recovery));
        }
Ejemplo n.º 3
0
 protected static Recorded <SubscriptionAction> OnSave(long time, IOperatorStateContainer state)
 {
     return(new Recorded <SubscriptionAction>(time, new SaveState(state)));
 }
        /// <summary>
        /// Subscribes the specified source.
        /// </summary>
        /// <typeparam name="T">Type of events.</typeparam>
        /// <param name="source">The source.</param>
        /// <param name="res">The result observer.</param>
        /// <param name="context">The context.</param>
        /// <param name="container">The container.</param>
        /// <returns>Subscription.</returns>
        public static ISubscription Subscribe <T>(this ISubscribable <T> source, IObserver <T> res, IOperatorContext context, IOperatorStateContainer container)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

            ISubscription sub = source.Subscribe(res);

            new SubscriptionInitializeVisitor(sub).Initialize(context, container.CreateReader());
            return(sub);
        }
Ejemplo n.º 5
0
 public SaveState(IOperatorStateContainer state)
 {
     Type   = SubscriptionActionKind.SaveState;
     _state = state;
 }