Пример #1
0
        public void RaiseSignal()
        {
            bool called = false;

            Yogi.RaiseSignalFnDelegate fn = () =>
            {
                called = true;
            };

            MOCK_RaiseSignal((int signal, IntPtr sigarg, RaiseSignalFnDelegate fn_, IntPtr userarg) =>
            {
                Assert.Equal((int)Yogi.Signals.Term, signal);
                Assert.NotNull(fn_);
                fn_(sigarg, userarg);
                return((int)Yogi.ErrorCode.Ok);
            });

            Yogi.RaiseSignal(Yogi.Signals.Term, fn);
            Assert.True(called);

            called = false;

            Yogi.RaiseSignalFnDelegate <string> fn2 = (string sigarg) =>
            {
                Assert.Null(sigarg);
                called = true;
            };

            Yogi.RaiseSignal(Yogi.Signals.Term, fn);
            Assert.True(called);
        }
Пример #2
0
        public void RaiseSignalError()
        {
            MOCK_RaiseSignal((int signal, IntPtr sigarg, RaiseSignalFnDelegate fn_, IntPtr userarg) =>
            {
                return((int)Yogi.ErrorCode.Unknown);
            });

            Assert.ThrowsAny <Yogi.FailureException>(() =>
            {
                Yogi.RaiseSignal(Yogi.Signals.Term);
            });

            Assert.ThrowsAny <Yogi.FailureException>(() =>
            {
                Yogi.RaiseSignal(Yogi.Signals.Term, "foo");
            });
        }
Пример #3
0
        public void RaiseSignalNoHandler()
        {
            bool called = false;

            MOCK_RaiseSignal((int signal, IntPtr sigarg, RaiseSignalFnDelegate fn_, IntPtr userarg) =>
            {
                called = true;
                return((int)Yogi.ErrorCode.Ok);
            });

            Yogi.RaiseSignal(Yogi.Signals.Term);
            Assert.True(called);

            called = false;
            Yogi.RaiseSignal(Yogi.Signals.Term, "foo");
            Assert.True(called);
        }
        public void AwaitSignal()
        {
            var sigset = new Yogi.SignalSet(context, Yogi.Signals.Term | Yogi.Signals.Usr5);

            bool called = false;

            sigset.AwaitSignalAsync((res, signal) => {
                Assert.IsType <Yogi.Success>(res);
                Assert.Equal(Yogi.ErrorCode.Ok, res.ErrorCode);
                Assert.Equal(Yogi.Signals.Term, signal);
                called = true;
            });
            GC.Collect();
            Yogi.RaiseSignal(Yogi.Signals.Term, "123");
            GC.Collect();
            context.Poll();
            GC.Collect();
            Assert.True(called);

            called = false;
            sigset.AwaitSignalAsync <string>((res, signal, sigarg) => {
                Assert.IsType <Yogi.Success>(res);
                Assert.Equal(Yogi.ErrorCode.Ok, res.ErrorCode);
                Assert.Equal(Yogi.Signals.Term, signal);
                Assert.Null(sigarg);
                called = true;
            });
            Yogi.RaiseSignal(Yogi.Signals.Term);
            context.Poll();
            Assert.True(called);

            called = false;
            sigset.AwaitSignalAsync <string>((res, signal, sigarg) => {
                Assert.IsType <Yogi.Success>(res);
                Assert.Equal(Yogi.ErrorCode.Ok, res.ErrorCode);
                Assert.Equal(Yogi.Signals.Term, signal);
                Assert.Equal("Hello", sigarg);
                called = true;
            });
            Yogi.RaiseSignal(Yogi.Signals.Term, "Hello");
            context.Poll();
            Assert.True(called);
        }
        public void RaiseSignalCleanupHandler()
        {
            bool called = false;

            Yogi.RaiseSignal(Yogi.Signals.Usr1, () => {
                called = true;
            });
            Assert.True(called);

            called = false;
            Yogi.RaiseSignal <string>(Yogi.Signals.Usr2, null, (sigarg) => {
                Assert.Null(sigarg);
                called = true;
            });
            Assert.True(called);

            called = false;
            Yogi.RaiseSignal(Yogi.Signals.Usr2, "Hello", (sigarg) => {
                Assert.Equal("Hello", sigarg);
                called = true;
            });
            Assert.True(called);
        }