Ejemplo n.º 1
0
        public void RegisterTest()
        {
            ComponentContainer_Accessor target = new ComponentContainer_Accessor(); // TODO: Initialize to an appropriate value
            IComponent component = null; // TODO: Initialize to an appropriate value
            bool ret = false;
            //component不存在,抛出异常
            try
            {
                target.Register(component);
            }
            catch (Exception)
            {
                ret = true;
            }
            Assert.IsTrue(ret);

            //注册一个HostInfo
            component = new HostInfo();
            target.Register(component);
            //componentContainer中有一个Component
            Assert.AreEqual(target.components.Count, 1);
            //该Component为HostInfo
            Assert.IsInstanceOfType(target.GetComponent(component.GetType().Name.ToLowerInvariant()), component.GetType());

        }
Ejemplo n.º 2
0
        public void GetComponentTest()
        {
            ComponentContainer_Accessor target = new ComponentContainer_Accessor(); // TODO: Initialize to an appropriate value
            string typeName = string.Empty; // TODO: Initialize to an appropriate value
            IComponent expected = null; // TODO: Initialize to an appropriate value
            IComponent actual;

            //注册HostInfo
            expected = new HostInfo();
            target.Register(expected);

            //typename为空,抛出异常
            bool ret = false;
            try
            {
                actual = target.GetComponent(typeName);
            }
            catch (Exception)
            {
                ret = true;
            }
            Assert.IsTrue(ret);

            //typename不存在,返回NULL
            typeName="gaga";
            actual = target.GetComponent(typeName);
            Assert.IsNull(actual);

            //typename存在
            typeName = expected.GetType().Name.ToLowerInvariant();
            actual = target.GetComponent(typeName);
            Assert.AreEqual(actual, expected);
        }