예제 #1
0
        public static void TotalTimeOfTooLongConditionWait()
        {
            var success   = false;
            var stopwatch = new Stopwatch();
            var config    = new WaitConfiguration(5000, 250);

            stopwatch.Start();
            try
            {
                Wait.Until(() =>
                {
                    Thread.Sleep(TimeSpan.FromSeconds(10));
                    return(true);
                }, config);
            }
            catch (WaitTimeoutException)
            {
                success = true;
            }

            stopwatch.Stop();
            Assert.IsTrue(success);
            var passedSeconds = stopwatch.Elapsed.TotalMilliseconds;

            Assert.IsTrue(passedSeconds > 5000 && passedSeconds - 5000 < 1000);
        }
        public static void TotalTimeOfFailingWaitMethod()
        {
            var mock = new Mock <ICounter>();

            mock.Setup(foo => foo.GetCount()).Returns(10);

            var success   = false;
            var stopwatch = new Stopwatch();
            var config    = new WaitConfiguration(5000, 250, 10000);

            stopwatch.Start();
            try
            {
                Wait.Until(() => mock.Object.GetCount() == 5, config);
            }
            catch (WaitTimeoutException)
            {
                success = true;
            }

            stopwatch.Stop();
            Assert.IsTrue(success);
            var passedSeconds = stopwatch.Elapsed.TotalMilliseconds;

            Assert.IsTrue(passedSeconds > 10000 && passedSeconds - 10000 < 1000);
        }
        public static void WaitUntilOneCycleSuccess()
        {
            var mock = new Mock <ICounter>();

            mock.Setup(foo => foo.GetCount()).Returns(10);

            var config = new WaitConfiguration(1000, 250, 3000);
            var wait   = Wait.Until(() => mock.Object.GetCount() == 10, config);

            Assert.IsTrue(wait);
            mock.Verify(x => x.GetCount(), Times.Exactly(1));
        }
예제 #4
0
        public static void TotalTimeOfSuccessfulWait()
        {
            var mock = new Mock <ICounter>();

            mock.Setup(foo => foo.GetCount()).Returns(10);

            var stopwatch = new Stopwatch();
            var config    = new WaitConfiguration(10000, 250);

            stopwatch.Start();
            var wait = Wait.Until(() => mock.Object.GetCount() == 10, config);

            stopwatch.Stop();
            Assert.IsTrue(wait);
            var passedSeconds = stopwatch.Elapsed.TotalMilliseconds;

            Assert.IsTrue(passedSeconds < 1000);
        }
예제 #5
0
        public static void OneTimePolled()
        {
            var mock = new Mock <ICounter>();

            mock.Setup(foo => foo.GetCount()).Returns(10);

            var success = false;
            var config  = new WaitConfiguration(500, 1000);

            try
            {
                Wait.Until(() => mock.Object.GetCount() == 5, config);
            }
            catch (WaitTimeoutException)
            {
                success = true;
            }

            Assert.IsTrue(success);
            mock.Verify(x => x.GetCount(), Times.Exactly(1));
        }
예제 #6
0
        public static void AboutTenTimesPolled()
        {
            var mock = new Mock <ICounter>();

            mock.Setup(foo => foo.GetCount()).Returns(10);

            var success = false;
            var config  = new WaitConfiguration(1000, 100);

            try
            {
                Wait.Until(() => mock.Object.GetCount() == 5, config);
            }
            catch (WaitTimeoutException)
            {
                success = true;
            }

            Assert.IsTrue(success);
            mock.Verify(x => x.GetCount(), Times.Between(8, 10, Range.Inclusive));
        }
        public void ExceptionOnExtendedWait()
        {
            var mock = new Mock <ICounter>();

            mock.Setup(foo => foo.GetCount()).Returns(10);

            string exceptionMessage = null;

            try
            {
                var config = new WaitConfiguration(1000, 250, 3000);
                Wait.Until(() => mock.Object.GetCount() == 10, config);
            }
            catch (InvalidOperationException ex)
            {
                exceptionMessage = ex.Message;
            }

            Assert.IsNotNull(exceptionMessage);
            Assert.AreEqual("NUnit Framework must be referenced to use Extend On Timeout feature.", exceptionMessage);
            mock.Verify(x => x.GetCount(), Times.Exactly(0));
        }