public void ShouldReturnNullWhenElementIsNull() { var document = new XmlDocument(); var scriptVariables = new ScriptVariables(document); var result = scriptVariables.GetDoubleArray(null); Assert.IsNull(result); }
public void ShouldReturnNullWhenElementHasNoVariableAttribute() { var document = new XmlDocument(); var scriptVariables = new ScriptVariables(document); var element = document.CreateElement("test"); var result = scriptVariables.GetDoubleArray(element); Assert.IsNull(result); }
public void ShouldReturnNullWhenVariableValueIsInvalid() { var document = new XmlDocument(); document.LoadXml("<test foo=\"{$foo}\"/>"); var scriptVariables = new ScriptVariables(document); var element = document.CreateElement("test"); element.SetAttribute("variable", "bar"); var result = scriptVariables.GetDoubleArray(element); Assert.IsNull(result); }
public void ShouldThrowExceptionWhenVariableNameIsInvalid() { var document = new XmlDocument(); document.LoadXml("<test foo=\"{$foo}\"/>"); var scriptVariables = new ScriptVariables(document); var element = document.CreateElement("test"); element.SetAttribute("variable", "{$bar}"); ExceptionAssert.Throws <InvalidOperationException>(() => { scriptVariables.GetDoubleArray(element); }, "Invalid variable name: bar"); }
public void ShouldThrowExceptionWhenVariableTypeIsIncorrect() { var document = new XmlDocument(); document.LoadXml("<test foo=\"{$foo}\"/>"); var scriptVariables = new ScriptVariables(document); scriptVariables.Set("foo", new string[] { }); var element = document.CreateElement("test"); element.SetAttribute("variable", "{$foo}"); ExceptionAssert.Throws <InvalidOperationException>(() => { scriptVariables.GetDoubleArray(element); }, "The value of variable 'foo' is not a double[]."); }
public void ShouldReturnValue() { var document = new XmlDocument(); document.LoadXml("<test foo=\"{$foo}\"/>"); var scriptVariables = new ScriptVariables(document); scriptVariables.Set("foo", new double[] { 42 }); var element = document.CreateElement("test"); element.SetAttribute("variable", "{$foo}"); var result = scriptVariables.GetDoubleArray(element); Assert.IsNotNull(result); Assert.AreEqual(42.0, result[0]); }