public void TestSetSection() { var configFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Cfg", "SetSection.config"); SuperConfig <UserInfo> .Setting(configFilePath, (sectionName, filePath, convertCaseStrategy) => { XElement xElement = XElement.Load(filePath); var caseSectionName = convertCaseStrategy.ConvertCase(sectionName); var sectionElement = xElement.Elements().Where(i => i.Name == caseSectionName).FirstOrDefault(); if (sectionElement == null) { throw new Exception("dot find section:" + sectionName); } return(new Section() { XElement = sectionElement }); }); var user = SuperConfig <UserInfo> .Value; Assert.AreEqual(user.UserName, "CEmrys"); Assert.AreEqual(user.Email, "*****@*****.**"); Assert.AreEqual(user.Age, 17); Assert.AreEqual(user.BlogUrl, "http://www.cnblogs.com/emrys5/"); Assert.AreEqual(user.FavoriteColor, Color.Blue); Assert.AreEqual(user.DislikeColor, Color.Black); }
public void TestSetConvertCase() { SuperConfig <UserInfo> .Setting(n => n); var user = SuperConfig <UserInfo> .Value; Assert.AreEqual(user.UserName, "Emrys"); Assert.AreEqual(user.Email, "*****@*****.**"); Assert.AreEqual(user.Age, 27); Assert.AreEqual(user.BlogUrl, "http://www.cnblogs.com/emrys5/"); Assert.AreEqual(user.FavoriteColor, Color.Blue); Assert.AreEqual(user.DislikeColor, Color.Black); }
public void TestSetSectionUserInfo() { var configFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Cfg", "SectionUserInfo.config"); SuperConfig <UserInfo> .Setting(configFilePath, (sectionName, filePath, convertCaseStrategy) => { return(new Section() { XElement = XElement.Load(filePath) }); }); var user = SuperConfig <UserInfo> .Value; Assert.AreEqual(user.UserName, "SUEmrys"); }