Example #1
0
        public void Switcher_DelegateRegistration_Success()
        {
            var swithcer = new DelegateSwitcher <Func <int> >();

            swithcer.Register(1, () => 1);
            Assert.IsNull(swithcer.Active);
            Assert.AreEqual(1, swithcer[1]());
        }
Example #2
0
        public void Switcher_SwitchingPredicate_Success()
        {
            var swithcer = new DelegateSwitcher <Func <int> >(key => !Equals(key, 3));

            swithcer.RegisterAndSwitch(1, () => 1);
            Assert.AreEqual(1, swithcer.Active());
            swithcer.RegisterAndSwitch(2, () => 2);
            Assert.AreEqual(2, swithcer.Active());
            swithcer.RegisterAndSwitch(3, () => 3);
            Assert.AreEqual(2, swithcer.Active());
        }
Example #3
0
 public ExpressionTypeCache(string root)
 {
     if (root == null)
     {
         throw new ArgumentNullException(nameof(root));
     }
     _root    = root;
     _types   = new List <Type>();
     _factory = new DelegateSwitcher <Func <object> >();
     _factory.RegisterAndSwitch(nameof(StateDefault), StateDefault);
     _factory.Register(nameof(StateErrorMultipleTypes), StateErrorMultipleTypes);
 }
Example #4
0
        public void Switcher_UnregisteredDeleagateUsage_Failure()
        {
            var swithcer = new DelegateSwitcher <Func <int> >();

            Assert.Throws <InvalidOperationException>(() => swithcer[1]());
        }