public void Given_An_ICommand_When_Calling_OnProgressUpdatesDo_Should_Report_Progress_continuosly()
        {
            var updates = new List <double>();
            Mock <IEventAggregator> aggregator = new Mock <IEventAggregator>();
            CommandManager          manager    = new CommandManager(aggregator.Object, SynchronizationContext.Current);
            var    command = new ProgressNotifyingCommand();
            double counter = 0;

            manager.Do(
                Execute.The(command)
                .RunCommandInBackground()
                .OnProgressUpdatesDo(progress =>
            {
                updates.Add(progress.ProgressPercentage);
                Assert.IsTrue(updates[updates.Count - 1] == (counter += 10), "Percentage not updated correctly");
            }));
        }
        public void Given_An_ICommand_When_Calling_OnProgressUpdatesDo_Should_Report_Progress_To_Caller()
        {
            ManualResetEvent resetEvent = new ManualResetEvent(false);
            var updates = new List <double>();
            Mock <IEventAggregator> aggregator = new Mock <IEventAggregator>();
            CommandManager          manager    = new CommandManager(aggregator.Object, SynchronizationContext.Current);
            var command = new ProgressNotifyingCommand();

            manager.Do(
                Execute.The(command)
                .RunCommandInBackground()
                .OnProgressUpdatesDo(progress => updates.Add(progress.ProgressPercentage))
                .AndWhenCompletedCall(state => resetEvent.Set()));

            resetEvent.WaitOne(1000, false);
            Assert.IsTrue(updates.Count == 9, "There should be 9 updates");
            Assert.IsTrue(updates[5] == 60, "This value should be 60 but is: " + updates[5]);
        }
        public void Given_An_ICommand_When_Calling_OnProgressUpdatesDo_Should_Report_EstimatedTime()
        {
            ManualResetEvent resetEvent = new ManualResetEvent(false);
            var updates = new List <TimeSpan>();
            Mock <IEventAggregator> aggregator = new Mock <IEventAggregator>();
            CommandManager          manager    = new CommandManager(aggregator.Object, SynchronizationContext.Current);
            var command = new ProgressNotifyingCommand();

            manager.Do(
                Execute.The(command)
                .RunCommandInBackground()
                .OnProgressUpdatesDo(progress =>
            {
                updates.Add(progress.TimeEstimated);
                System.Diagnostics.Debug.WriteLine(string.Format("({0:00}%) -> Elapsed: {1:00} ms / Estimated: {2:00} ms", progress.ProgressPercentage, progress.TimeElapsed.TotalMilliseconds, progress.TimeEstimated.TotalMilliseconds));
            })
                .AndWhenCompletedCall(state => resetEvent.Set()));

            resetEvent.WaitOne(1000, false);
            Assert.IsTrue(updates[0] > updates[5], "TimeElapsed is not calculated correctly.");
            Assert.IsTrue(updates[5] > updates[8], "TimeElapsed is not calculated correctly.");
        }