Exemple #1
0
        public void TestTimeProperties()
        {
            // Testing beginTime, endTime, eyeTime
            Userflow example = ExampleUserflow();

            Assert.IsTrue(example.State() == UserflowState.CREATED,
                          "Expecting UserflowState.CREATED .");
            example.SetTimeout(Int32.MaxValue);
            {
                example.Begin();
                Assert.IsTrue(example.State() == UserflowState.BEGUN,
                              "Expecting UserflowState.BEGUN .");
            }
            // Call "yield" here so CLR can operate example's timer .
            const int positiveTime = 100;
            long      yieldTime;
            {
                long yieldBeginTime = DateTime.UtcNow.Ticks;
                Thread.Sleep(positiveTime);
                long yieldEndTime = DateTime.UtcNow.Ticks;
                yieldTime = yieldEndTime - yieldBeginTime;
            }
            {
                example.End();
                Assert.IsTrue(example.State() == UserflowState.ENDED,
                              "Expecting UserflowState.ENDED .");
            }
            // All the above is mainly just to get some interesting
            // beginTime, endTime, eyeTime play around with.  Now,
            // it is play time.
            {
                long beginTime = example.BeginTime();
                long endTime   = example.EndTime();
                long eyeTime   = example.EyeTime();
                // Test beginTime, endTime, eyeTime wrt the actual "yieldTime"
                Assert.IsTrue(beginTime < endTime,
                              "Expecting beginTime < endTime .");
                // The test is run entirely in foreground, so
                // endTime - beginTime should be close to eyeTime
                // allowing a little bit of deviation due to use
                // of "yield".
                Assert.IsTrue((0.8 * yieldTime) < eyeTime,
                              String.Format("Expecting eyeTime == {0} to be close to {1} .",
                                            eyeTime,
                                            yieldTime));
                Assert.IsTrue(eyeTime < (1.2 * yieldTime),
                              String.Format("Expecting eyeTime == {0} to be close to {1} .",
                                            eyeTime,
                                            yieldTime));
                Assert.IsTrue((0.8 * yieldTime) < (endTime - beginTime),
                              String.Format("Expecting (endTime - beginTime) == {0} to be close to {1} .",
                                            endTime - beginTime,
                                            yieldTime));
                Assert.IsTrue((endTime - beginTime) < (1.2 * yieldTime),
                              String.Format("Expecting (endTime - beginTime) == {0} to be close to {1} .",
                                            endTime - beginTime,
                                            yieldTime));
            }
        }