Exemplo n.º 1
0
        internal CompletedCommandExecution(CompletedCommandExecutionState state, float progress, Exception exception)
        {
            Debug.Assert(
                state == CompletedCommandExecutionState.Done && Math.Abs(progress - 1f) < float.Epsilon && exception == null ||
                state == CompletedCommandExecutionState.Canceled && progress >= 0f && progress <= 1f && exception == null ||
                state == CompletedCommandExecutionState.Faulted &&
                progress >= 0f &&
                progress <= 1f &&
                exception != null &&
                !(exception is OperationCanceledException));

            State     = state;
            Progress  = progress;
            Exception = exception;
        }
Exemplo n.º 2
0
        internal static void AssertExecutionsAfterCompletion <C>(
            [NotNull] TestArgs <C> args,
            CompletedCommandExecutionState state,
            bool isProgressOne,
            bool hasException) where C : CommandBase
        {
            Assert.IsNull(args.Command.RunningExecution);

            if (args.CanExecute)
            {
                Assert.IsNotNull(args.Command.CompletedExecution);

                Assert.AreEqual(state, args.Command.CompletedExecution.State);

                if (isProgressOne)
                {
                    Assert.AreEqual(1, args.Command.CompletedExecution.Progress);
                }
                else
                {
                    Assert.IsTrue(args.Command.CompletedExecution.Progress < 1f);
                }

                if (hasException)
                {
                    Assert.IsNotNull(args.Command.CompletedExecution.Exception);
                }
                else
                {
                    Assert.IsNull(args.Command.CompletedExecution.Exception);
                }

                if (args.CapturedController != null)
                {
                    ExceptionAssert.Throws <InvalidOperationException>(() => args.CapturedController.ReportProgress(0.7f));
                    ((IProgress <float>)args.CapturedController).Report(0.75f);
                }
            }
            else
            {
                Assert.IsNull(args.Command.CompletedExecution);
            }
        }