コード例 #1
0
        public void TestDispose()
        {
            ProgressV2 progress = new ProgressV2("testDispose", 200);

            progress.percent = 50;
            Assert.Equal(100, progress.GetCount());
            progress.totalCount = 400;
            Assert.Equal(100, progress.GetCount());
            Assert.Equal(25, progress.percent);

            progress.Dispose();
            Assert.Throws <ObjectDisposedException>(() => progress.totalCount = 100);
            Assert.Throws <ObjectDisposedException>(() => progress.percent    = 1);
            Assert.Throws <ObjectDisposedException>(() => progress.SetCount(2));
            Assert.Throws <ObjectDisposedException>(() => ((IProgress <double>)progress).Report(3));
        }
コード例 #2
0
        public void ExampleUsage1()
        {
            using (IProgress progress = new ProgressV2(id: "Download Progress 1", totalCount: 10)) {
                Assert.Equal(10, progress.totalCount);

                progress.SetCount(7); // 7/10 will be complete
                Assert.Equal(70, progress.percent);

                progress.IncrementCount(); // 8/10 will be complete
                Assert.Equal(80, progress.percent);

                progress.percent = 90; // 9/10 will be complete
                Assert.Equal(9, progress.GetCount());

                progress.SetComplete(); // 10/10 will be complete
                Assert.True(progress.IsComplete());
                Assert.Equal(100, progress.percent);
            }
        }