Esempio n. 1
0
        /// <summary>
        /// chekanote: this test demonstrate that the observable returned by "Create" is a cold one
        /// 1. "Create" won't run until there is observer subscribed on
        /// 2. everytime an observer subscribed, "Create" will be invoked once again
        /// 3. everytime an observer subscribed, "Create" will generate and publish newest value with latest seed
        /// </summary>
        private static void TestGenerate_Create_ColdFeature()
        {
            GeneratorBase     generator  = new Generator_Create();
            IObservable <int> coldSource = generator.Generate();

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

            Debug.Assert(total == 6);

            total = sumer.SyncSum(coldSource);
            Debug.Assert(total == 6);
            Debug.Assert(2 == generator.NumInvoke);

            // ---------------------- change the seed will affect generated observables
            // ---------------------- because this observable ISN'T a concrete sequence, just a factory
            // ---------------------- everytime subscribed, it will use the latest seed to generate and publish data
            generator.Seed = 100;
            total          = sumer.SyncSum(coldSource);
            Debug.Assert(306 == total);
            Debug.Assert(3 == generator.NumInvoke);

            Console.WriteLine("consume [{0}] times,data generated [{1}] times", sumer.NumSubscription, generator.NumInvoke);
        }
Esempio n. 2
0
        /// <summary>
        /// chekanote: this test demonstrate that the observable returned by "Create" is a cold one
        /// 1. "Create" won't run until there is observer subscribed on
        /// 2. everytime an observer subscribed, "Create" will be invoked once again
        /// 3. everytime an observer subscribed, "Create" will generate and publish newest value with latest seed 
        /// </summary>
        private static void TestGenerate_Create_ColdFeature()
        {
            GeneratorBase generator = new Generator_Create();
            IObservable<int> coldSource = generator.Generate();

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

            total = sumer.SyncSum(coldSource);
            Debug.Assert(total == 6);
            Debug.Assert(2 == generator.NumInvoke);

            // ---------------------- change the seed will affect generated observables
            // ---------------------- because this observable ISN'T a concrete sequence, just a factory
            // ---------------------- everytime subscribed, it will use the latest seed to generate and publish data
            generator.Seed = 100;
            total = sumer.SyncSum(coldSource);
            Debug.Assert(306 == total);
            Debug.Assert(3 == generator.NumInvoke);

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