public void GetConfigurationUsesjsConf_PrefixAsDefault() { var data = Utils.FilterAppSettings("jsConf_"); var jsm = new JsConfigurationScriptManager(); var script = jsm.GetScript(data); Assert.IsTrue(script.Contains(@"{""test1"":1};")); }
public void GetConfigurationFailsIfnotPrefixPresent() { var data = Utils.FilterAppSettings("conf_"); var jsm = new JsConfigurationScriptManager(); var script = jsm.GetScript(data); Assert.IsFalse(script.Contains(@"""test3""")); }
public void GetConfigurationReturnsStringsProperly() { var data = Utils.FilterAppSettings("conf_"); var jsm = new JsConfigurationScriptManager {Prefix = "conf_"}; var script = jsm.GetScript(data); Assert.IsTrue(script.StartsWith("var ServerConfigurations = ")); Assert.IsTrue(script.Contains(@"{""test3"":""hello""};")); }
public void GetConfigurationReturnsOk() { var data = Utils.FilterAppSettings("jsConf_"); var jsm = new JsConfigurationScriptManager(); var script = jsm.GetScript(data); Assert.IsTrue(script.StartsWith("var ServerConfigurations = ")); Assert.IsTrue(script.Contains(@"{""test1"":1};")); }
public void GetConfigurationCustomReturnsCustonNames() { const string JS_PREFIX = "jsConf_"; var data = Utils.FilterAppSettings(JS_PREFIX); var jsm = new JsConfigurationScriptManager { Prefix = JS_PREFIX, VariableName = "MyVar"}; var script = jsm.GetScript(data); Assert.IsTrue(script.StartsWith("var MyVar = ")); Assert.IsTrue(script.Contains(@"{""test1"":1};")); }
private static void AddDataCodeFromConfig(StringBuilder builder, string prefix, string varName) { var jsm = new JsConfigurationScriptManager { Prefix = prefix, VariableName = varName, VarIsMainVar = false }; var codes = Utils.FilterAppSettings(jsm.Prefix); builder.Append(jsm.GetScript(codes)); }
public JavaScriptResult GetConfiguration() { //1. we set the prefix of the AppSettings that we're going to export. var jsPrefix = Utils.GetString("JsConfPrefix"); //2. we use our utility method in order to retrieve the key/value pairs. var data = Utils.FilterAppSettings(jsPrefix); //3. we instantiate our JsConfigurationScriptManager (typically we'll use DI and maybe use it through the controller) var jsm = new JsConfigurationScriptManager(); //4. we create the script var script = jsm.GetScript(data); //5. we expose the script return JavaScript(script); /* RETURN VALUE **************************************************************************************************** var ServerConfigurations = { 'maxContactItems': 50, 'maxAddressItems': 50 }; - The default variable name is ServerConfigurations. *********************************************************************************************************************/ }
public JavaScriptResult GetConfigurationCustom() { //1. we set the prefix of the AppSettings that we're going to export. const string JS_PREFIX = "jsConf_"; //2. we use our utility method in order to retrieve the key/value pairs. var data = Utils.FilterAppSettings(JS_PREFIX); //3. we instantiate our JsConfigurationScriptManager (typically we'll use DI and maybe use it through the controller) var jsm = new JsConfigurationScriptManager { Prefix = JS_PREFIX, VariableName = "MyVar", ExposeRelativePath = true}; //4. we create the script var script = jsm.GetScript(data); //5. we expose the script return JavaScript(script); /* RETURN VALUE **************************************************************************************************** var Myvar = { 'maxContactItems': 50, 'maxAddressItems': 50, 'relPath':'/' }; - The variable name has been defined by us. - If you forget to inform the prefix when instantiating the JsConfigurationScriptManager, the prefix will appear in the property names. - relPath exposes the relative path of the app. *********************************************************************************************************************/ }