Example #1
0
        public void GetConnectionsSizeTest()
        {
            Receptacle target = new Receptacle(name, interfaceName, isMultiple);
            int        actual;
            int        expected;

            for (int i = 0; i < connections.Count; i++)
            {
                target.AddConnections(connections[i]);
                actual   = target.GetConnectionsSize();
                expected = i + 1;
                Assert.AreEqual(expected, actual);
            }

            int id = target.AddConnections(connections[0]);

            expected = connections.Count + 1;
            actual   = target.GetConnectionsSize();
            Assert.AreEqual(expected, actual);

            target.RemoveConnetions(id);
            expected = connections.Count;
            actual   = target.GetConnectionsSize();
            Assert.AreEqual(expected, actual);
        }
Example #2
0
        /// <summary>
        /// Conecta uma faceta a um receptáculo.
        /// </summary>
        /// <param name="receptacle">
        /// O nome do receptáculo que se deseja conectar.
        /// </param>
        /// <param name="obj">
        /// A referência para a faceta que se deseja conectar.
        /// </param>
        /// <exception cref="InvalidName">
        /// Caso o nome do receptáculo seja inválido.
        /// </exception>
        /// <exception cref="InvalidConnection">
        /// Caso a conexão não possa ser estabelecida, este erro pode acontecer
        /// caso o <c>obj</c> não implemente a interface do receptáculo.
        /// </exception>
        /// <exception cref="AlreadyConnected">
        /// Caso a faceta já esteja conectada.
        /// </exception>
        /// <exception cref="ExceededConnectionLimit">
        /// Caso o número de conexões tenha excedido o limite configurado.
        /// </exception>
        public int connect(string receptacle, MarshalByRefObject obj)
        {
            IDictionary <string, Receptacle> receptacles =
                context.GetReceptacles();

            if (!receptacles.ContainsKey(receptacle))
            {
                throw new InvalidName {
                          name = receptacle
                }
            }
            ;

            Receptacle rec = receptacles[receptacle];

            if ((!rec.IsMultiple) &&
                (rec.GetConnectionsSize() > 0))
            {
                throw new AlreadyConnected();
            }

            if (!IiopNetUtil.CheckInterface(obj, rec.InterfaceName))
            {
                throw new InvalidConnection();
            }

            int id = rec.AddConnections(obj);

            logger.InfoFormat("Conexão {0} adicionada ao receptáculo '{1}'", id,
                              receptacle);
            return(id);
        }
Example #3
0
        public void RemoveConnetionsTest()
        {
            Receptacle         target     = new Receptacle(name, interfaceName, isMultiple);
            MarshalByRefObject connection = connections[0];
            int  id     = target.AddConnections(connection);
            bool actual = target.RemoveConnetions(id);

            Assert.AreEqual(true, actual);
        }
Example #4
0
        public void GetConnectionsTest()
        {
            Receptacle target = new Receptacle(name, interfaceName, isMultiple);
            List <ConnectionDescription> expected = new List <ConnectionDescription>();
            List <ConnectionDescription> actual   = target.GetConnections();

            Assert.AreEqual(expected.Count, actual.Count);
            for (int i = 0; i < connections.Count; i++)
            {
                target.AddConnections(connections[i]);
            }

            actual = target.GetConnections();
            Assert.AreEqual(connections.Count, actual.Count);
        }
Example #5
0
        public void ClearConnectionsTest()
        {
            Receptacle target = new Receptacle(name, interfaceName, isMultiple);
            List <int> idList = new List <int>(connections.Count);

            foreach (var connection in connections)
            {
                int id = target.AddConnections(connection);
                idList.Add(id);
            }
            List <ConnectionDescription> actual = target.GetConnections();

            Assert.AreEqual(connections.Count, actual.Count);

            target.ClearConnections();
            actual = target.GetConnections();
            Assert.AreEqual(0, actual.Count);
        }
Example #6
0
        public void GetDescriptionTest2()
        {
            Receptacle target = new Receptacle(name, interfaceName, isMultiple);

            foreach (var connection in connections)
            {
                target.AddConnections(connection);
            }
            List <ConnectionDescription> receptacleConnectionsList = target.GetConnections();

            ConnectionDescription[] connectionDescription = receptacleConnectionsList.ToArray();
            ReceptacleDescription   expected = new ReceptacleDescription(name, interfaceName, isMultiple, connectionDescription);
            ReceptacleDescription   actual   = target.GetDescription();

            Assert.AreEqual(actual.name, expected.name);
            Assert.AreEqual(actual.interface_name, expected.interface_name);
            Assert.AreEqual(actual.is_multiplex, expected.is_multiplex);
            Assert.AreEqual(actual.connections.Length, expected.connections.Length);
        }