Пример #1
0
        public void TestNowOrLater()
        {
            ActionSequence s = new ActionSequence();

            int iStacked = 0;

            s.NowOrLater(x => { iStacked = x; }, 1);
            Assert.That(iStacked, Is.EqualTo(0), "ActionSequence s is not null nor read only: it is stacked.");

            s.ReadOnly = true;
            s.NowOrLater(x => { iStacked = x; }, 2);
            Assert.That(iStacked, Is.EqualTo(2), "ActionSequence s is read only: it is executed immediately.");

            s.Run();
            Assert.That(iStacked, Is.EqualTo(1), "First action has been deferred.");

            s = null;
            s.NowOrLater(x => { iStacked = x; }, 3);
            Assert.That(iStacked, Is.EqualTo(3), "This ActionSequence is null: it is executed immediately.");
        }
Пример #2
0
        public void TestWithEvents()
        {
            int stdCalled  = 0;
            int specCalled = 0;

            ActionSequence s = new ActionSequence();

            StdEvent  += (o, e) => { stdCalled = 1; };
            SpecEvent += (o, e) => { specCalled = 1; };

            SpecEventArgs args = new SpecEventArgs();

            s.NowOrLater(SpecEvent, this, args);
            s.NowOrLater(StdEvent, this, EventArgs.Empty);

            Assert.That(stdCalled, Is.EqualTo(0));
            Assert.That(specCalled, Is.EqualTo(0));

            s.Run();
            Assert.That(stdCalled, Is.EqualTo(1));
            Assert.That(specCalled, Is.EqualTo(1));
        }
Пример #3
0
        public void TestNowOrLater()
        {
            ActionSequence s = new ActionSequence();

            int iStacked = 0;

            s.NowOrLater(x => { iStacked = x; }, 1);
            Assert.That(iStacked, Is.EqualTo(0), "ActionSequence s is not null nor read only: it is stacked.");

            s.ReadOnly = true;
            s.NowOrLater(x => { iStacked = x; }, 2);
            Assert.That(iStacked, Is.EqualTo(2), "ActionSequence s is read only: it is executed immediately.");

            s.Run();
            Assert.That(iStacked, Is.EqualTo(1), "First action has been deferred.");

            s = null;
            s.NowOrLater(x => { iStacked = x; }, 3);
            Assert.That(iStacked, Is.EqualTo(3), "This ActionSequence is null: it is executed immediately.");

        }
Пример #4
0
        public void TestWithEvents()
        {
            int stdCalled = 0;
            int specCalled = 0;

            ActionSequence s = new ActionSequence();

            StdEvent += (o, e) => { stdCalled = 1; };
            SpecEvent += (o, e) => { specCalled = 1; };

            SpecEventArgs args = new SpecEventArgs();
            s.NowOrLater(SpecEvent, this, args);
            s.NowOrLater(StdEvent, this, EventArgs.Empty);

            Assert.That(stdCalled, Is.EqualTo(0));
            Assert.That(specCalled, Is.EqualTo(0));

            s.Run();
            Assert.That(stdCalled, Is.EqualTo(1));
            Assert.That(specCalled, Is.EqualTo(1));

        }