示例#1
0
        public void AddAndTakeTwoMessages()
        {
            Mailbox box = new Mailbox();

            box.Add(1);
            box.Add(2);

            Assert.AreEqual(1, box.Take());
            Assert.AreEqual(2, box.Take());
        }
示例#2
0
        public void AddAndTakeMessagesWithReject()
        {
            Mailbox box = new Mailbox();

            box.Add(1);
            box.Add(2);
            box.Add(3);

            Assert.AreEqual(1, box.Take());
            Assert.AreEqual(2, box.Take());
            box.Reject(2);
            Assert.AreEqual(3, box.Take());
            Assert.AreEqual(2, box.Take());
        }
示例#3
0
        public void AddAndTakeMessagesWithReject()
        {
            Mailbox box = new Mailbox();

            box.Add(1);
            box.Add(2);
            box.Add(3);

            Assert.AreEqual(1, box.Take());
            Assert.AreEqual(2, box.Take());
            box.Reject(2);
            Assert.AreEqual(3, box.Take());
            Assert.AreEqual(2, box.Take());
        }
示例#4
0
        public void AddAndTakeMessage()
        {
            Mailbox box = new Mailbox();

            box.Add(1);

            Assert.AreEqual(1, box.Take());
        }
示例#5
0
        public void TakeADelayedAddedMessage()
        {
            Mailbox box = new Mailbox();

            ThreadStart ts = new ThreadStart(() => { Thread.Sleep(100); box.Add(1); });
            Thread      th = new Thread(ts);

            th.Start();

            Assert.AreEqual(1, box.Take());
        }
示例#6
0
        public void AddAndTakeMessagesWithThreeNonConsecutiveRejects()
        {
            Mailbox box = new Mailbox();

            box.Add(1);
            box.Add(2);
            box.Add(3);
            box.Add(4);
            box.Add(5);

            Assert.AreEqual(1, box.Take());
            Assert.AreEqual(2, box.Take());
            box.Reject(2);
            Assert.AreEqual(3, box.Take());
            box.Reject(3);
            Assert.AreEqual(4, box.Take());
            Assert.AreEqual(2, box.Take());
            box.Reject(2);
            Assert.AreEqual(3, box.Take());
            Assert.AreEqual(2, box.Take());
            Assert.AreEqual(5, box.Take());
        }
示例#7
0
        public void AddAndTakeMessagesWithThreeNonConsecutiveRejects()
        {
            Mailbox box = new Mailbox();

            box.Add(1);
            box.Add(2);
            box.Add(3);
            box.Add(4);
            box.Add(5);

            Assert.AreEqual(1, box.Take());
            Assert.AreEqual(2, box.Take());
            box.Reject(2);
            Assert.AreEqual(3, box.Take());
            box.Reject(3);
            Assert.AreEqual(4, box.Take());
            Assert.AreEqual(2, box.Take());
            box.Reject(2);
            Assert.AreEqual(3, box.Take());
            Assert.AreEqual(2, box.Take());
            Assert.AreEqual(5, box.Take());
        }
示例#8
0
        public void TakeADelayedAddedMessage()
        {
            Mailbox box = new Mailbox();

            ThreadStart ts = new ThreadStart(() => { Thread.Sleep(100); box.Add(1); });
            Thread th = new Thread(ts);
            th.Start();

            Assert.AreEqual(1, box.Take());
        }