public void GetConfigBeansTest() { ConfigBeanContainer_Accessor target = new ConfigBeanContainer_Accessor(); // TODO: Initialize to an appropriate value IEnumerable<ConfigBeanBase> actual; ConfigBeanBase appsettingsBean = new AppSettingsBean(); ConfigBeanBase fcconfigBean = new FCConfigBean(); target.Register(appsettingsBean); target.Register(fcconfigBean); actual = target.GetConfigBeans(); //actual不为空 Assert.IsNotNull(actual); //actual个数为2 int result = 0; using (IEnumerator<ConfigBeanBase> enumerator = actual.GetEnumerator()) { while (enumerator.MoveNext()) result++; } Assert.AreEqual(result, 2); //actual中含有AppSettingsBean和FCConfigBean bool ret = false; using (IEnumerator<ConfigBeanBase> enumerator = actual.GetEnumerator()) { while (enumerator.MoveNext()) { if (enumerator.Current.GetType().Name.Equals(appsettingsBean.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(fcconfigBean.GetType().Name)) { ret = true; break; } } } Assert.IsTrue(ret); ConfigBeanBase testBean1 = new Arch.CFramework.AppInternals.Test.TestBean1.TestBean(); ConfigBeanBase testBean2 = new Arch.CFramework.AppInternals.Test.TestBean2.TestBean(); target.Register(testBean1); target.Register(testBean2); //actual个数为2 result = 0; using (IEnumerator<ConfigBeanBase> enumerator = actual.GetEnumerator()) { while (enumerator.MoveNext()) result++; } Assert.AreEqual(result, 2); }
public void GetConfigBeanTest() { string typename = string.Empty; ConfigBeanBase expected = null; ConfigBeanBase actual; //typename为空,抛出异常 bool ret = false; try { actual = ConfigBeanManager.Current.GetConfigBean(typename); } catch(Exception) { ret = true; } Assert.IsTrue(ret); //typename不存在,返回Null typename = "lala"; actual = ConfigBeanManager.Current.GetConfigBean(typename); Assert.IsNull(actual); //typename存在得到ConfigBean expected = new AppSettingsBean(); actual = ConfigBeanManager.Current.GetConfigBean(expected.GetType().Name.ToLowerInvariant()); Assert.IsNotNull(actual); Assert.IsInstanceOfType(actual, expected.GetType()); expected = new Arch.CFramework.AppInternals.Test.TestBean.AppSettingsBean(); actual = ConfigBeanManager.Current.GetConfigBean(expected.GetType().FullName.ToLowerInvariant()); Assert.IsNull(actual); }
public void GetConfigBeanTest() { ConfigBeanContainer_Accessor target = new ConfigBeanContainer_Accessor(); // TODO: Initialize to an appropriate value string typeName = string.Empty; // TODO: Initialize to an appropriate value ConfigBeanBase expected = null; // TODO: Initialize to an appropriate value ConfigBeanBase actual; expected = new AppSettingsBean(); target.Register(expected); //属性值为空,抛出异常 bool ret = false; try { actual = target.GetConfigBean(typeName); } catch (Exception) { ret = true; } Assert.IsTrue(ret); //typename不存在,返回NULL typeName = "gaga"; actual = target.GetConfigBean(typeName); Assert.IsNull(actual); //typename存在 typeName = expected.GetType().Name.ToLowerInvariant(); actual = target.GetConfigBean(typeName); Assert.AreEqual(actual, expected); }