Esempio n. 1
0
        public void BindToNonExistent()
        {
            dynamic      d       = new TypeWithEvents();
            Action <int> handler = i =>
            {
            };

            Assert.Throws <RuntimeBinderException>(() => d.NothingHere += handler);
        }
Esempio n. 2
0
        public void BindToNonEvents()
        {
            dynamic      d       = new TypeWithEvents();
            Action <int> handler = i =>
            {
            };

            Assert.Throws <RuntimeBinderException>(() => d.NonEventField    += handler);
            Assert.Throws <RuntimeBinderException>(() => d.NonEventProperty += handler);
            Assert.Throws <RuntimeBinderException>(() => d.Raise            += handler);
        }
Esempio n. 3
0
        public void BindToEvent()
        {
            dynamic d      = new TypeWithEvents();
            int     output = 0;

            d.Event += (Action <int>)(i =>
            {
                output = i;
            });
            d.Raise(49);
            Assert.Equal(49, output);
        }
Esempio n. 4
0
        public void RemoveHandler()
        {
            TypeWithEvents with      = new TypeWithEvents();
            int            output    = 0;
            Action <int>   setOutput = i =>
            {
                output = i;
            };

            with.Event += setOutput;
            with.Raise(1);
            dynamic d = with;

            d.Event -= setOutput;
            with.Raise(2);
            Assert.Equal(1, output);
            d.Raise(3);
            Assert.Equal(1, output);
        }