Esempio n. 1
0
        public void Cleanup()
        {
            IPortReceive pa = new Port <int> ();
            IPortReceive pb = new Port <string> ();
            ITask task = new Task<int, string> ((i, s) => { });
            var mr = new MultipleItemReceiver (task, pa, pb);
            var dq = new SerialDispatchQueue ();
            mr.TaskQueue = dq;

            mr.Execute ();
            Assert.AreEqual (1, pa.GetReceivers ().Length, "#1");
            Assert.AreEqual (1, pb.GetReceivers ().Length, "#2");

            mr.Cleanup ();
            Assert.AreEqual (0, pa.GetReceivers ().Length, "#3");
            Assert.AreEqual (0, pb.GetReceivers ().Length, "#4");

            Assert.AreEqual (0, pa.ItemCount, "#5");
            Assert.AreEqual (0, pb.ItemCount, "#6");
        }
Esempio n. 2
0
        public void UnRegisterReceiverChangesGetReceivers()
        {
            IPortReceive ipr = new Port<int> ();
            ReceiverTask rt = new EvalTask (true);

            Assert.AreEqual (0, ipr.GetReceivers ().Length, "#1");
            ipr.RegisterReceiver (rt);
            ipr.RegisterReceiver (rt);
            Assert.AreEqual (2, ipr.GetReceivers ().Length, "#3");
            ipr.UnregisterReceiver (rt);
            Assert.AreEqual (1, ipr.GetReceivers ().Length, "#4");
            ipr.UnregisterReceiver (rt);
            Assert.AreEqual (0, ipr.GetReceivers ().Length, "#5");
        }
Esempio n. 3
0
 public void ReceiverCanUnregisterOnEvaluate()
 {
     IPortReceive p = new Port<int> ();
     var rec = new WeirdReceiver (p);
     Assert.AreEqual (1, p.GetReceivers ().Length, "#1");
     ((IPort)p).PostUnknownType (10);
     Assert.AreEqual (0, p.GetReceivers ().Length, "#2");
 }
Esempio n. 4
0
        public void ConstructorSideEffects()
        {
            int cnt = 0;
            IPortReceive pa = new Port <int> ();
            IPortReceive pb = new Port <string> ();
            var mr = new MultipleItemReceiver (Arbiter.FromHandler (() => { ++cnt; }), pa, pb);

            Assert.AreEqual (0, pa.GetReceivers ().Length, "#1");
            Assert.AreEqual (0, pb.GetReceivers ().Length, "#2");
            Assert.AreEqual (0, cnt, "#3");
        }
Esempio n. 5
0
        public void ExecutePersistent()
        {
            int cnt = 0;
            IPortReceive pa = new Port <int> ();
            IPortReceive pb = new Port <string> ();
            var mr = new MultipleItemReceiver (Arbiter.FromHandler (() => { ++cnt; }), pa, pb);
            var dq = new SerialDispatchQueue ();
            mr.TaskQueue = dq;
            mr.State = ReceiverTaskState.Persistent;

            Assert.AreEqual (0, pa.GetReceivers ().Length, "#1");
            Assert.AreEqual (0, pb.GetReceivers ().Length, "#2");

            mr.Execute ();

            Assert.AreEqual (1, pa.GetReceivers ().Length, "#3");
            Assert.AreEqual (1, pb.GetReceivers ().Length, "#4");

            Assert.AreEqual (ReceiverTaskState.Onetime, pa.GetReceivers ()[0].State, "#5");
        }
Esempio n. 6
0
        public void Execute2()
        {
            int cnt = 0;
            IPortReceive pa = new Port <int> ();
            IPortReceive pb = new Port <string> ();
            ITask task = new Task<int, string> ( (i, s) => { cnt += i + s.Length; });
            var mr = new MultipleItemReceiver (task, pa, pb);
            var dq = new SerialDispatchQueue ();
            mr.TaskQueue = dq;

            mr.Execute ();

            var a = (Port<int>)pa;
            var b = (Port<string>)pb;

            a.Post (10);
            Assert.AreEqual (0, pa.ItemCount, "#1");
            Assert.AreEqual (0, cnt, "#2");

            b.Post ("hello");
            Assert.AreEqual (15, cnt, "#3");

            //it's a one time thing
            Assert.AreEqual (0, pa.GetReceivers ().Length, "#4");
            Assert.AreEqual (0, pb.GetReceivers ().Length, "#5");

            a.Post (1);
            Assert.AreEqual (15, cnt, "#6");
            b.Post ("x");
            Assert.AreEqual (15, cnt, "#7");
        }