Exemplo n.º 1
0
        /// <summary>
        /// Tests if awaiting a specified amount of time for a single animation lasting the
        /// specified amount of time waits for the appropriate amount of time.
        /// </summary>
        ///
        /// <param name="animationDuration">
        /// the duration of the animation in milliseconds.
        /// </param>
        ///
        /// <param name="awaitduration">
        /// the amount of time to await after the animation finishes.
        /// </param>
        public void AnimationAwaitTestCase(long animationDuration, int awaitduration)
        {
            // Setup the animation.
            var animation = new ValueAnimation(0, 0, animationDuration);

            // Time the waiting time.
            var stopwatch = new Stopwatch();

            // Start the animation.
            animation.Start();
            stopwatch.Start();

            // Await
            animation.Await(awaitduration);

            // Stop the stopwatch.
            stopwatch.Stop();

            // The error must be within the acceptable amount.
            var elapsed         = stopwatch.ElapsedMilliseconds;
            var error           = Math.Abs(elapsed - animationDuration) - awaitduration;
            var acceptableError = Animator.Instance.FrameDuration;

            Assert.IsTrue(
                error <= acceptableError,
                String.Format(
                    "Waited for {0} milliseconds instead of {1} milliseconds for an animation lasting {2} "
                    + "milliseconds and await time of {3} milliseconds with an allotted error of {4} milliseconds.",
                    elapsed,
                    animationDuration + awaitduration,
                    animationDuration,
                    awaitduration,
                    acceptableError
                    )
                );
        }