Ejemplo n.º 1
0
 public static Polyface IsHasExpirable(this Polyface root, IExpirable expirable)
 {
     Condition.Requires(root).IsNotNull();
     var composited = new HasExpirable(expirable);
     root.Is(composited);
     return root;
 }
Ejemplo n.º 2
0
        public static Polyface IsHasExpirable(this Polyface root, IExpirable expirable)
        {
            Condition.Requires(root).IsNotNull();
            var composited = new HasExpirable(expirable);

            root.Is(composited);
            return(root);
        }
Ejemplo n.º 3
0
        public ExpirableTest()
            : base(LogicOf <Nothing> .New((x) =>
        {
            #region Expirable
            //create expirable
            var expirable = NaturalTrueExpirable.New();

            //test date expirable
            var dateExp = expirable.DecorateWithDateExpirable(DateTime.Now.AddSeconds(5));
            Condition.Requires(dateExp.IsExpired()).IsFalse();
            Thread.Sleep(6000);
            Condition.Requires(dateExp.IsExpired()).IsTrue();

            //test floating date
            var floatDateExp = expirable.DecorateWithDateExpirable(DateTime.Now.AddSeconds(5)).DecorateWithFloatingDateExpirable(1);
            Condition.Requires(floatDateExp.IsExpired()).IsFalse();
            floatDateExp.Touch().Touch();
            Thread.Sleep(6000);
            Condition.Requires(floatDateExp.IsExpired()).IsFalse();
            Thread.Sleep(2000);
            Condition.Requires(floatDateExp.IsExpired()).IsTrue();

            //test window date
            var windowExp = expirable.DecorateWithWindowExpirable(DateTime.Now.AddSeconds(1), DateTime.Now.AddSeconds(5));
            Condition.Requires(windowExp.IsExpired()).IsTrue();
            Thread.Sleep(2000);
            Condition.Requires(windowExp.IsExpired()).IsFalse();
            Thread.Sleep(6000);
            Condition.Requires(windowExp.IsExpired()).IsTrue();

            //test float window date
            var floatWindowExp = expirable.DecorateWithWindowExpirable(DateTime.Now.AddSeconds(1), DateTime.Now.AddSeconds(5)).DecorateWithFloatingWindowExpirable(1);
            Condition.Requires(floatWindowExp.IsExpired()).IsTrue();
            Thread.Sleep(2000);
            Condition.Requires(floatWindowExp.IsExpired()).IsFalse();
            Thread.Sleep(6000);
            Condition.Requires(floatWindowExp.IsExpired()).IsTrue();
            floatWindowExp.Touch().Touch().Touch().Touch();     //touch it back to not expired
            Condition.Requires(floatWindowExp.IsExpired()).IsFalse();

            //test conditional expiry
            var cond    = StrategizedConditionOf <bool> .New((o) => { return(o); }).AddContext(false);
            var condExp = expirable.DecorateWithConditionalExpirable(cond);
            Condition.Requires(condExp.IsExpired()).IsFalse();
            cond.Context = true;
            Condition.Requires(condExp.IsExpired()).IsTrue();
            #endregion

            #region HasA
            //test HasA
            var hasExp = HasExpirable.New(expirable);
            hasExp.ExpiresOn(DateTime.Now.AddSeconds(5));
            Condition.Requires(hasExp.IsExpired()).IsFalse();
            Thread.Sleep(6000);
            Condition.Requires(hasExp.IsExpired()).IsTrue();
            //test floating date
            hasExp.ExpiryFloats(1);
            hasExp.Touch().Touch();
            Condition.Requires(hasExp.IsExpired()).IsFalse();
            Thread.Sleep(2000);
            Condition.Requires(hasExp.IsExpired()).IsTrue();

            //test window date
            hasExp.InWindow(DateTime.Now.AddSeconds(1), DateTime.Now.AddSeconds(5));
            Condition.Requires(hasExp.IsExpired()).IsTrue();
            Thread.Sleep(2000);
            Condition.Requires(hasExp.IsExpired()).IsFalse();
            Thread.Sleep(6000);
            Condition.Requires(hasExp.IsExpired()).IsTrue();

            //test float window date
            hasExp.InWindow(DateTime.Now.AddSeconds(1), DateTime.Now.AddSeconds(5)).WindowFloats(1);
            Condition.Requires(hasExp.IsExpired()).IsTrue();
            Thread.Sleep(2000);
            Condition.Requires(hasExp.IsExpired()).IsFalse();
            Thread.Sleep(6000);
            Condition.Requires(hasExp.IsExpired()).IsTrue();
            hasExp.Touch().Touch().Touch().Touch();     //touch it back to not expired
            Condition.Requires(hasExp.IsExpired()).IsFalse();

            //test conditional expiry
            hasExp.ExpiresWhen(cond);
            cond.Context = false;
            Condition.Requires(condExp.IsExpired()).IsFalse();
            cond.Context = true;
            Condition.Requires(condExp.IsExpired()).IsTrue();
            #endregion
        }))
        {
        }