Exemple #1
0
        public void HostInfoConstructorTest()
        {
            HostInfo target = new HostInfo();

            Assert.IsNotNull( target );
            Assert.AreEqual( Environment.MachineName, target.HostName );
        }
        public void GetComponentTest()
        {
            string componentName = string.Empty; 
            IComponent expected = null; 
            IComponent actual = null;
            //componentName为空,抛出异常
            bool ret = false;
            try
            {
                actual = ComponentManager.Current.GetComponent(componentName);
            }
            catch (Exception)
            {
                ret = true;
            }
            Assert.IsTrue(ret);

            //默认注册两个Component BuidInfo和HostInfo
            var components = ComponentManager.Current.GetCollection();
            Assert.AreEqual(components.Components.Count, 2);

            //expected存在
            expected = new HostInfo();
            var component = ComponentManager.Current.GetComponent(expected.GetType().Name.ToLowerInvariant());
            Assert.IsInstanceOfType(component, component.GetType());

            //expected不存在
            expected = new Arch.CFramework.AppInternals.Test.TestBean.BuildInfo();
            component = ComponentManager.Current.GetComponent(expected.GetType().FullName.ToLowerInvariant());
            Assert.IsNull(component);
        }
        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());

        }
        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);
        }
        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);
        }