Example #1
0
        /// <summary>
        /// the IObservable generated with ReplaySubject can be generated once and used for multiple times
        /// </summary>
        private static void TestGenerate_ReplaySubject_ReuseFeature()
        {
            GeneratorBase     generator      = new Generator_ReplaySubject();
            IObservable <int> reusableSource = generator.Generate();

            Sumer sumer = new Sumer();
            int   total = sumer.SyncSum(reusableSource);

            Debug.Assert(total == 6);

            // ---------------------- change the seed won't affect generated observables
            // ---------------------- because this observable is a concrete sequence, not just a factory
            generator.Seed = 100;
            total          = sumer.SyncSum(reusableSource);
            Debug.Assert(total == 6);// it WON'T generate again with the latest value

            Debug.Assert(1 == generator.NumInvoke);

            Console.WriteLine("consume [{0}] times,data generated [{1}] times", sumer.NumSubscription, generator.NumInvoke);
        }
Example #2
0
        /// <summary>
        /// the IObservable generated with ReplaySubject can be generated once and used for multiple times
        /// </summary>
        private static void TestGenerate_ReplaySubject_ReuseFeature()
        {
            GeneratorBase generator = new Generator_ReplaySubject();
            IObservable<int> reusableSource = generator.Generate();

            Sumer sumer = new Sumer();
            int total = sumer.SyncSum(reusableSource);
            Debug.Assert(total == 6);

            // ---------------------- change the seed won't affect generated observables
            // ---------------------- because this observable is a concrete sequence, not just a factory
            generator.Seed = 100;
            total = sumer.SyncSum(reusableSource);
            Debug.Assert(total == 6);// it WON'T generate again with the latest value

            Debug.Assert(1 == generator.NumInvoke);

            Console.WriteLine("consume [{0}] times,data generated [{1}] times", sumer.NumSubscription, generator.NumInvoke);
        }