Example #1
0
        public void TestProgressWithUntrack()
        {
            using (ProgressTracker tracker = new ProgressTracker()) {
                TestTransaction test1 = new TestTransaction();
                TestTransaction test2 = new TestTransaction();
                tracker.Track(test1);
                tracker.Track(test2);

                Assert.AreEqual(0.0f, tracker.Progress);

                test1.ChangeProgress(0.5f);

                Assert.AreEqual(0.25f, tracker.Progress);

                tracker.Untrack(test2);

                Assert.AreEqual(0.5f, tracker.Progress);
            }
        }
Example #2
0
        public void TestSummedProgress()
        {
            using (ProgressTracker tracker = new ProgressTracker()) {
                IProgressTrackerSubscriber mockedSubscriber = mockSubscriber(tracker);

                TestTransaction test1 = new TestTransaction();
                TestTransaction test2 = new TestTransaction();

                // Step 1
                {
                    Expect.Once.On(mockedSubscriber).Method("IdleStateChanged").WithAnyArguments();

                    // Since the progress is already at 0, these redundant reports are optional
                    Expect.Between(0, 2).On(mockedSubscriber).Method("ProgressChanged").With(
                        new Matcher[] {
                        new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)),
                        new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.0f))
                    }
                        );

                    tracker.Track(test1);
                    tracker.Track(test2);
                }

                // Step 2
                {
                    Expect.Once.On(mockedSubscriber).Method("ProgressChanged").With(
                        new Matcher[] {
                        new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)),
                        new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.25f))
                    }
                        );

                    test1.ChangeProgress(0.5f);
                }
            }

            this.mockery.VerifyAllExpectationsHaveBeenMet();
        }
        public void TestSummedProgress()
        {
            using (ProgressTracker tracker = new ProgressTracker()) {
                Mock <IProgressTrackerSubscriber> mockedSubscriber = mockSubscriber(tracker);

                TestTransaction test1 = new TestTransaction();
                TestTransaction test2 = new TestTransaction();

                // Step 1
                {
                    mockedSubscriber.Expects.One.Method(
                        m => m.IdleStateChanged(null, null)
                        ).WithAnyArguments();

                    // Since the progress is already at 0, these redundant reports are optional
                    mockedSubscriber.Expects.Between(0, 2).Method(m => m.ProgressChanged(null, null)).With(
                        new NMock.Matchers.TypeMatcher(typeof(ProgressTracker)),
                        new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.0f))
                        );

                    tracker.Track(test1);
                    tracker.Track(test2);
                }

                // Step 2
                {
                    mockedSubscriber.Expects.One.Method(m => m.ProgressChanged(null, null)).With(
                        new NMock.Matchers.TypeMatcher(typeof(ProgressTracker)),
                        new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.25f))
                        );

                    test1.ChangeProgress(0.5f);
                }
            }

            this.mockery.VerifyAllExpectationsHaveBeenMet();
        }
Example #4
0
        public void TestDelayedRemoval()
        {
            using (ProgressTracker tracker = new ProgressTracker()) {
                IProgressTrackerSubscriber mockedSubscriber = mockSubscriber(tracker);

                TestTransaction test1 = new TestTransaction();
                TestTransaction test2 = new TestTransaction();

                // Step 1
                {
                    Expect.Once.On(mockedSubscriber).
                    Method("IdleStateChanged").
                    WithAnyArguments();

                    // This is optional. The tracker's progress is currently 0, so there's no need
                    // to send out superfluous progress reports.
                    Expect.Between(0, 2).On(mockedSubscriber).
                    Method("ProgressChanged").
                    With(
                        new Matcher[] {
                        new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)),
                        new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.0f))
                    }
                        );

                    tracker.Track(test1);
                    tracker.Track(test2);
                }

                // Step 2
                {
                    Expect.Once.On(mockedSubscriber).
                    Method("ProgressChanged").
                    With(
                        new Matcher[] {
                        new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)),
                        new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.25f))
                    }
                        );

                    // Total progress should be 0.25 after this call (two transactions, one with
                    // 0% progress and one with 50% progress)
                    test1.ChangeProgress(0.5f);
                }

                // Step 3
                {
                    Expect.Once.On(mockedSubscriber).
                    Method("ProgressChanged").
                    With(
                        new Matcher[] {
                        new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)),
                        new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.75f))
                    }
                        );

                    // Total progress should be 0.75 after this call (one transaction at 100%,
                    // the other one at 50%). If the second transaction would be removed by the tracker,
                    // (which would be inappropriate!) the progress would falsely jump to 0.5 instead.
                    test2.End();
                }

                // Step 4
                {
                    Expect.Once.On(mockedSubscriber).
                    Method("ProgressChanged").
                    With(
                        new Matcher[] {
                        new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)),
                        new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(1.0f))
                    }
                        );

                    Expect.Once.On(mockedSubscriber).
                    Method("IdleStateChanged").
                    WithAnyArguments();

                    test1.End();
                }
            }

            this.mockery.VerifyAllExpectationsHaveBeenMet();
        }
    public void TestProgressWithUntrack() {
      using(ProgressTracker tracker = new ProgressTracker()) {
        TestTransaction test1 = new TestTransaction();
        TestTransaction test2 = new TestTransaction();
        tracker.Track(test1);
        tracker.Track(test2);

        Assert.AreEqual(0.0f, tracker.Progress);

        test1.ChangeProgress(0.5f);

        Assert.AreEqual(0.25f, tracker.Progress);

        tracker.Untrack(test2);

        Assert.AreEqual(0.5f, tracker.Progress);
      }
    }
    public void TestDelayedRemoval() {
      using(ProgressTracker tracker = new ProgressTracker()) {
        IProgressTrackerSubscriber mockedSubscriber = mockSubscriber(tracker);

        TestTransaction test1 = new TestTransaction();
        TestTransaction test2 = new TestTransaction();

        // Step 1
        {
          Expect.Once.On(mockedSubscriber).
            Method("IdleStateChanged").
            WithAnyArguments();

          // This is optional. The tracker's progress is currently 0, so there's no need
          // to send out superfluous progress reports.
          Expect.Between(0, 2).On(mockedSubscriber).
            Method("ProgressChanged").
            With(
              new Matcher[] {
              new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)),
              new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.0f))
            }
            );

          tracker.Track(test1);
          tracker.Track(test2);
        }

        // Step 2
        {
          Expect.Once.On(mockedSubscriber).
            Method("ProgressChanged").
            With(
              new Matcher[] {
              new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)),
              new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.25f))
            }
            );

          // Total progress should be 0.25 after this call (two transactions, one with
          // 0% progress and one with 50% progress)
          test1.ChangeProgress(0.5f);
        }

        // Step 3
        {
          Expect.Once.On(mockedSubscriber).
            Method("ProgressChanged").
            With(
              new Matcher[] {
              new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)),
              new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.75f))
            }
            );

          // Total progress should be 0.75 after this call (one transaction at 100%,
          // the other one at 50%). If the second transaction would be removed by the tracker,
          // (which would be inappropriate!) the progress would falsely jump to 0.5 instead.
          test2.End();
        }

        // Step 4
        {
          Expect.Once.On(mockedSubscriber).
            Method("ProgressChanged").
            With(
              new Matcher[] {
              new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)),
              new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(1.0f))
            }
            );

          Expect.Once.On(mockedSubscriber).
            Method("IdleStateChanged").
            WithAnyArguments();

          test1.End();
        }
      }

      this.mockery.VerifyAllExpectationsHaveBeenMet();
    }
    public void TestSummedProgress() {
      using(ProgressTracker tracker = new ProgressTracker()) {
        IProgressTrackerSubscriber mockedSubscriber = mockSubscriber(tracker);

        TestTransaction test1 = new TestTransaction();
        TestTransaction test2 = new TestTransaction();

        // Step 1
        {
          Expect.Once.On(mockedSubscriber).Method("IdleStateChanged").WithAnyArguments();

          // Since the progress is already at 0, these redundant reports are optional
          Expect.Between(0, 2).On(mockedSubscriber).Method("ProgressChanged").With(
            new Matcher[] {
              new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)),
              new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.0f))
            }
          );

          tracker.Track(test1);
          tracker.Track(test2);
        }

        // Step 2
        {
          Expect.Once.On(mockedSubscriber).Method("ProgressChanged").With(
            new Matcher[] {
              new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)),
              new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.25f))
            }
          );

          test1.ChangeProgress(0.5f);
        }
      }

      this.mockery.VerifyAllExpectationsHaveBeenMet();
    }