Exemplo n.º 1
0
        public void TestSessionState()
        {
            // Create a Consumer
            ConsumerId cid = new ConsumerId();

            cid.ConnectionId = "CONNECTION";
            cid.SessionId    = 4096;
            cid.Value        = 42;
            ConsumerInfo cinfo = new ConsumerInfo();

            cinfo.ConsumerId = cid;

            // Create a Producer
            ProducerId pid = new ProducerId();

            pid.ConnectionId = "CONNECTION";
            pid.SessionId    = 42;
            pid.Value        = 4096;
            ProducerInfo pinfo = new ProducerInfo();

            pinfo.ProducerId = pid;

            // Create a Session
            SessionId id = new SessionId();

            id.ConnectionId = "CONNECTION";
            id.Value        = 42;
            SessionInfo info = new SessionInfo();

            info.SessionId = id;

            SessionState state = new SessionState(info);

            Assert.AreEqual(info, state.Info);

            state.AddProducer(pinfo);
            state.AddConsumer(cinfo);

            Assert.AreEqual(1, state.ConsumerStates.Count);
            Assert.AreEqual(1, state.ProducerStates.Count);

            state.RemoveProducer(pinfo.ProducerId);
            state.RemoveConsumer(cinfo.ConsumerId);

            Assert.AreEqual(0, state.ConsumerStates.Count);
            Assert.AreEqual(0, state.ProducerStates.Count);

            state.AddConsumer(cinfo);
            state.AddProducer(pinfo);
            state.AddProducer(pinfo);
            Assert.AreEqual(1, state.ProducerStates.Count);

            state.Shutdown();
            Assert.AreEqual(0, state.ConsumerStates.Count);
            Assert.AreEqual(0, state.ProducerStates.Count);

            try
            {
                state.AddConsumer(cinfo);
                Assert.Fail("Should have thrown an exception");
            }
            catch
            {
            }

            try
            {
                state.AddProducer(pinfo);
                Assert.Fail("Should have thrown an exception");
            }
            catch
            {
            }
        }