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 GetComponentsTest()
        {
            ComponentContainer_Accessor target = new ComponentContainer_Accessor(); // TODO: Initialize to an appropriate value
            IEnumerable<IComponent> actual;

            //容器中注册两个容器
            IComponent component1 = new HostInfo();
            IComponent component2 = new BuildInfo();
            target.Register(component1);
            target.Register(component2);
            actual = target.GetComponents();
            //actual不为空
            Assert.IsNotNull(actual);
            //actual个数为2
            int result=0;
            using (IEnumerator<IComponent> enumerator = actual.GetEnumerator())
            {
                while (enumerator.MoveNext())
                    result++;
            }
            Assert.AreEqual(result, 2);
            //actual中含有HostInfo和BuildInfo
            bool ret=false;
            using (IEnumerator<IComponent> enumerator = actual.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    if (enumerator.Current.GetType().Name.Equals(component1.GetType().Name))
                    {
                        ret = true; break;
                    }
                }
            }
            Assert.IsTrue(ret);
            ret = false;
            using (IEnumerator<IComponent> enumerator = actual.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    if (enumerator.Current.GetType().Name.Equals(component2.GetType().Name))
                    {
                        ret = true; break;
                    }
                }
            }
            Assert.IsTrue(ret);
        }
Ejemplo n.º 3
0
 public void ComponentContainerConstructorTest()
 {
     ComponentContainer_Accessor target = new ComponentContainer_Accessor();
     Assert.IsNotNull(target);
 }       
Ejemplo n.º 4
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);
        }