public static void GetAppSetting1_Load(Page p) { object o = AppSettingsExpressionBuilder.GetAppSetting("strvalue"); Assert.AreEqual(typeof(string), o.GetType(), "#A1"); Assert.AreEqual("str", o, "#A2"); o = AppSettingsExpressionBuilder.GetAppSetting("intvalue"); Assert.AreEqual(typeof(string), o.GetType(), "#B1"); Assert.AreEqual("123", o, "#B2"); }
[Test] // GetAppSetting (String) public void GetAppSetting1_Key_DoesNotExist() { try { AppSettingsExpressionBuilder.GetAppSetting("DoesNotExist"); Assert.Fail("#1"); } catch (InvalidOperationException ex) { // The application setting 'DoesNotExist' was // not found in the applications configuration Assert.AreEqual(typeof(InvalidOperationException), ex.GetType(), "#2"); Assert.IsNull(ex.InnerException, "#3"); Assert.IsNotNull(ex.Message, "#4"); Assert.IsTrue(ex.Message.IndexOf("'DoesNotExist'") != -1, "#5"); } }
[Test] // GetAppSetting (String, Type, String) public void GetAppSetting2_Key_Null() { try { AppSettingsExpressionBuilder.GetAppSetting( (string)null, typeof(SettingTestingType), "StrProp"); Assert.Fail("#1"); } catch (InvalidOperationException ex) { // The application setting '' was not found in // the applications configuration Assert.AreEqual(typeof(InvalidOperationException), ex.GetType(), "#2"); Assert.IsNull(ex.InnerException, "#3"); Assert.IsNotNull(ex.Message, "#4"); Assert.IsTrue(ex.Message.IndexOf("''") != -1, "#5"); } }
private static bool ValidateAndSetArguments(string[] args) { try { if (args.Length > 0) { _vPath = args[0]; } else { _vPath = (string)AppSettingsExpressionBuilder.GetAppSetting ("virtualDirectory"); } if (args.Length > 1) { _pPath = args[1]; } else { _pPath = (string)AppSettingsExpressionBuilder.GetAppSetting ("physicalDirectory"); } if (args.Length > 2) { _tPath = args[2]; } else { _tPath = (string)AppSettingsExpressionBuilder.GetAppSetting ("targetDirectory"); } if (args.Length > 3) { string[] precompFlags = args[3].Split('|'); foreach (string flag in precompFlags) { _flags |= (PrecompilationFlags)Enum.Parse (typeof(PrecompilationFlags), flag.Trim()); } } else { _flags = PrecompilationFlags.Clean | PrecompilationFlags.ForceDebug; } if (args.Length > 4) { _keyContainer = args[4]; } return(true); } catch (Exception e) { OutputErrorList(e); } return(false); }
public static void GetAppSetting2_Load(Page p) { object o = AppSettingsExpressionBuilder.GetAppSetting("strvalue", typeof(SettingTestingType), "StrProp"); Assert.AreEqual(typeof(string), o.GetType(), "#A1"); Assert.AreEqual("str", o, "#A2"); // property does not exist o = AppSettingsExpressionBuilder.GetAppSetting("strvalue", typeof(SettingTestingType), "NotExistsProp"); Assert.AreEqual(typeof(string), o.GetType(), "#B1"); Assert.AreEqual("str", o, "#B2"); o = AppSettingsExpressionBuilder.GetAppSetting("intvalue", typeof(SettingTestingType), "IntProp"); Assert.AreEqual(typeof(int), o.GetType(), "#C1"); Assert.AreEqual(123, o, "#C2"); // conversion o = AppSettingsExpressionBuilder.GetAppSetting("intvalue", typeof(SettingTestingType), "StrProp"); Assert.AreEqual(typeof(string), o.GetType(), "#D1"); Assert.AreEqual("123", o, "#D2"); // property does not exist o = AppSettingsExpressionBuilder.GetAppSetting("intvalue", typeof(SettingTestingType), "NotExistsProp"); Assert.AreEqual(typeof(string), o.GetType(), "#E1"); Assert.AreEqual("123", o, "#E2"); // targetType null o = AppSettingsExpressionBuilder.GetAppSetting("intvalue", (Type)null, "NotExistsProp"); Assert.AreEqual(typeof(string), o.GetType(), "#F1"); Assert.AreEqual("123", o, "#F2"); // conversion failed try { AppSettingsExpressionBuilder.GetAppSetting("intvalue", typeof(SettingTestingType), "DateTimeProp"); Assert.Fail("#G1"); } catch (FormatException ex) { // String was not recognized as a valid DateTime Assert.AreEqual(typeof(FormatException), ex.GetType(), "#G2"); Assert.IsNotNull(ex.Message, "#G3"); } // conversion not supported try { AppSettingsExpressionBuilder.GetAppSetting("intvalue", typeof(SettingTestingType), "TypeProp"); Assert.Fail("#H1"); } catch (InvalidOperationException ex) { // Could not convert the AppSetting '123' to the // type 'Type' on property 'TypeProp' Assert.AreEqual(typeof(InvalidOperationException), ex.GetType(), "#H2"); Assert.IsNull(ex.InnerException, "#H3"); Assert.IsNotNull(ex.Message, "#H4"); Assert.IsTrue(ex.Message.IndexOf("'123'") != -1, "#H5"); Assert.IsTrue(ex.Message.IndexOf("'Type'") != -1, "#H6"); Assert.IsTrue(ex.Message.IndexOf("'TypeProp'") != -1, "#H7"); } // propertyName null try { AppSettingsExpressionBuilder.GetAppSetting("intvalue", typeof(SettingTestingType), (string)null); Assert.Fail("#I1"); } catch (ArgumentNullException ex) { Assert.AreEqual(typeof(ArgumentNullException), ex.GetType(), "#I2"); Assert.IsNull(ex.InnerException, "#I3"); Assert.IsNotNull(ex.Message, "#I4"); //Assert.AreEqual ("key", ex.ParamName, "#I5"); } }
public void SupportsEvaluate() { AppSettingsExpressionBuilder aseb = new AppSettingsExpressionBuilder(); Assert.IsTrue(aseb.SupportsEvaluate); }