public void ShouldReturnNullWhenElementIsNull()
            {
                var document        = new XmlDocument();
                var scriptVariables = new ScriptVariables(document);

                var result = scriptVariables.GetSingleArray(null);

                Assert.IsNull(result);
            }
            public void ShouldReturnNullWhenElementHasNoVariableAttribute()
            {
                var document        = new XmlDocument();
                var scriptVariables = new ScriptVariables(document);

                var element = document.CreateElement("test");

                var result = scriptVariables.GetSingleArray(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.GetSingleArray(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.GetSingleArray(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.GetSingleArray(element);
                }, "The value of variable 'foo' is not a float[].");
            }
            public void ShouldReturnValue()
            {
                var document = new XmlDocument();

                document.LoadXml("<test foo=\"{$foo}\"/>");

                var scriptVariables = new ScriptVariables(document);

                scriptVariables.Set("foo", new float[] { 42 });

                var element = document.CreateElement("test");

                element.SetAttribute("variable", "{$foo}");

                var result = scriptVariables.GetSingleArray(element);

                Assert.IsNotNull(result);
                Assert.AreEqual(42.0f, result[0]);
            }