Example #1
0
        public void OK()
        {
            var mc = new MyClass(10);

            RunTest(AnyValue.IsValid,
                    () => mc.Method(),
                    SmartAssert.Within(100));
        }
Example #2
0
        // ReSharper disable once InconsistentNaming
        public void Context_OK()
        {
            var mc = new MyClass(300);

            RunTest(AnyValue.IsValid,
                    ctx => mc.Method(ctx.SetHandle),
                    SmartAssert.Within(100),
                    SmartAssert.WaitContextHandle(1000));

            Assert.IsTrue(mc.Done);
            Assert.IsNull(mc.Exception);
        }
Example #3
0
        // ReSharper disable once InconsistentNaming
        public void OK()
        {
            var handle = new AutoResetEvent(false);
            var mc     = new MyClass(300);

            RunTest(AnyValue.IsValid,
                    () => mc.Method(() => handle.Set()),
                    SmartAssert.Within(100),
                    SmartAssert.Wait(handle, 1000));

            Assert.IsTrue(mc.Done);
            Assert.IsNull(mc.Exception);
        }
Example #4
0
        public void NegativeTimeout()
        {
            var exception = Assert.Catch <BadTestException>(() =>
            {
                var mc = new MyClass(100);

                RunTest(AnyValue.IsValid,
                        () => mc.Method(),
                        SmartAssert.Within(-90));
            });

            Assert.AreEqual(@"BAD TEST: Time should be strictly positive, but was -90ms", exception.Message);
        }
Example #5
0
        public void Fail()
        {
            var exception = Assert.Catch <SmartTestException>(() =>
            {
                var mc = new MyClass(100);

                RunTest(AnyValue.IsValid,
                        () => mc.Method(),
                        SmartAssert.Within(90));
            });

            StringAssert.IsMatch(@"Should be less than 90ms, but was \d+ms", exception.Message);
        }
Example #6
0
        public void Context_Timeout()
        {
            var mc = new MyClass(300);

            var exception = Assert.Catch <SmartTestException>(() =>
                                                              RunTest(AnyValue.IsValid,
                                                                      ctx => mc.Method(ctx.SetHandle),
                                                                      SmartAssert.Within(100),
                                                                      SmartAssert.WaitContextHandle(200))
                                                              );

            Assert.IsFalse(mc.Done);
            Assert.IsNull(mc.Exception);
            Assert.AreEqual("Timeout reached (200ms)", exception.Message);
        }
Example #7
0
        public void Exception()
        {
            var mc     = new MyClass(300, true);
            var handle = new AutoResetEvent(false);

            var exception = Assert.Catch <SmartTestException>(() =>
                                                              RunTest(AnyValue.IsValid,
                                                                      () => mc.Method(() => handle.Set()),
                                                                      SmartAssert.Within(100),
                                                                      SmartAssert.Wait(handle, 200))
                                                              );

            Assert.IsFalse(mc.Done);
            Assert.AreEqual("OOPS!", mc.Exception.Message);
            Assert.AreEqual("Timeout reached (200ms)", exception.Message);
        }
Example #8
0
        public void NoContextHandle()
        {
            var handle = new AutoResetEvent(false);
            var mc     = new MyClass(300);

            var exception = Assert.Catch <InconclusiveException>(() =>
                                                                 RunTest(AnyValue.IsValid,
                                                                         ctx => mc.Method(ctx.SetHandle),
                                                                         SmartAssert.Within(100),
                                                                         SmartAssert.Wait(handle, 500))
                                                                 );

            Assert.IsTrue(mc.Done);
            Assert.AreEqual("BAD TEST: ActContext.SetHandle called, but specified handle expected", mc.Exception.Message);
            Assert.AreEqual("BAD TEST: ActContext.SetHandle called, but specified handle expected", exception.Message);
        }
Example #9
0
        public void NoWaitHandle()
        {
            var handle = new AutoResetEvent(false);
            var mc     = new MyClass(300);

            var exception = Assert.Catch <SmartTestException>(() =>
                                                              RunTest(AnyValue.IsValid,
                                                                      () => mc.Method(() => handle.Set()),
                                                                      SmartAssert.Within(100),
                                                                      SmartAssert.WaitContextHandle(500))
                                                              );

            Assert.IsTrue(mc.Done);
            Assert.IsNull(mc.Exception);
            Assert.AreEqual("Timeout reached (500ms)", exception.Message);
        }