コード例 #1
0
ファイル: ReactiveTests.cs プロジェクト: tintoy/AWTY
        public void ReportProgressToSink(int total, int increment, int chunkSize, int[] expectedPercentages)
        {
            List <int> actualPercentages = new List <int>();

            Int32ChunkedPercentageStrategy strategy = new Int32ChunkedPercentageStrategy(chunkSize);

            strategy.Subscribe(progressData =>
            {
                actualPercentages.Add(progressData.PercentComplete);
            });

            Int32ProgressSink sink = new Int32ProgressSink(initialTotal: total);

            sink.Subscribe(strategy);

            int iterationCount = total / increment;

            for (int iteration = 0; iteration <= iterationCount; iteration++)
            {
                sink.Add(increment);
            }

            Assert.Equal(expectedPercentages.Length, actualPercentages.Count);
            Assert.Equal(expectedPercentages, actualPercentages);
        }
コード例 #2
0
        /// <summary>
        ///     Convert raw progress data to a percentage.
        /// </summary>
        /// <param name="rawProgress">
        ///     The sequence of raw progress data.
        /// </param>
        /// <param name="minimumChange">
        ///     The minimum change in percentage to report.
        /// </param>
        /// <returns>
        ///     An observable <see cref="ProgressStrategy{TValue}"/>.
        /// </returns>
        public static ProgressStrategy <int> Percentage(this IObservable <RawProgressData <int> > rawProgress, int minimumChange)
        {
            if (rawProgress == null)
            {
                throw new ArgumentNullException(nameof(rawProgress));
            }

            Int32ChunkedPercentageStrategy strategy = new Int32ChunkedPercentageStrategy(minimumChange);

            rawProgress.Subscribe(strategy);

            return(strategy);
        }
コード例 #3
0
ファイル: ReactiveTests.cs プロジェクト: tintoy/AWTY
        public void ReportProgressToStrategy(int total, int increment, int chunkSize, int[] expectedPercentages)
        {
            List <int> actualPercentages = new List <int>();

            Int32ChunkedPercentageStrategy strategy = new Int32ChunkedPercentageStrategy(chunkSize);

            strategy.Subscribe(progressData =>
            {
                actualPercentages.Add(progressData.PercentComplete);
            });

            int adjustedTotal = AdjustTotalForIncrement(total, increment);

            for (int currentProgress = 0; currentProgress <= adjustedTotal; currentProgress += increment)
            {
                strategy.AsObserver().OnNext(
                    RawProgressData.Create(currentProgress, total)
                    );
            }

            Assert.Equal(expectedPercentages.Length, actualPercentages.Count);
            Assert.Equal(expectedPercentages, actualPercentages);
        }
コード例 #4
0
        public void Ctor_ChunkSize_5()
        {
            Int32ChunkedPercentageStrategy strategy = new Int32ChunkedPercentageStrategy(chunkSize: 5);

            Assert.Equal(5, strategy.ChunkSize);
        }