示例#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);
        }
示例#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);
        }
示例#3
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);
        }
示例#4
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);
        }