Exemplo n.º 1
0
        private void ListVariables(StringBuilder output)
        {
            var names = _variables.Names;

            if (names.Count == 0)
            {
                output.Append(_phraseDictionary.GetPhrase(Texts.PhraseKeys.NoVariablesSet, _executionCultureName));
                return;
            }

            foreach (var name in names)
            {
                var variable = _variables.Get(name) as ValueVariable;
                output.Append($"{name, Constants.FirstColumnWidth}{variable.Value}{Environment.NewLine}");
            }
        }
Exemplo n.º 2
0
        public void Get_VariableNotSet_ReturnsNull()
        {
            // arrange
            var sut = new VariableCollection();

            // act
            var result = sut.Get("name");

            // assert
            Assert.Null(result);
        }
Exemplo n.º 3
0
        private void ProcessVariableParameter(VariableCommandParameter parameter, StringBuilder output, VariableCollection variables)
        {
            var variable = variables.Get(parameter.VariableName);

            if (variable == null)
            {
                throw new UnsetVariableException(parameter.VariableName);
            }

            output.Append((variable as ValueVariable).Value);
        }
Exemplo n.º 4
0
        public void Get_DifferentCasingForName_ReturnsVariable(string name)
        {
            // arrange
            var sut      = new VariableCollection();
            var variable = new ValueVariable("name", "alpha");

            sut.Set(variable);

            // act
            var result = sut.Get(name) as ValueVariable;

            // assert
            Assert.Equal(variable, result);
        }
Exemplo n.º 5
0
        public void Set_WhenCalled_StoresVariable()
        {
            // arrange
            var sut      = new VariableCollection();
            var variable = new ValueVariable("name", "alpha");

            // act
            sut.Set(variable);

            // assert
            var result = sut.Get("name") as ValueVariable;

            Assert.Equal("alpha", variable.Value);
        }
Exemplo n.º 6
0
        public void Remove_VariableWasSet_RemovesVariable(string name)
        {
            // arrange
            var sut      = new VariableCollection();
            var variable = new ValueVariable("name", "alpha");

            sut.Set(variable);

            // act
            sut.Remove(name);

            // assert
            var result = sut.Get("name");

            Assert.Null(result);
        }
Exemplo n.º 7
0
        public void SetGet_VariableAlreadySet_ReplacesVariable()
        {
            // arrange
            var sut       = new VariableCollection();
            var variable1 = new ValueVariable("name", "alpha");
            var variable2 = new ValueVariable("name", "beta");

            sut.Set(variable1);

            // act
            sut.Set(variable2);

            // assert
            var result = sut.Get("name") as ValueVariable;

            Assert.Equal("beta", result.Value);
        }
Exemplo n.º 8
0
        public void Execute_ValueProvided_SetsVariable()
        {
            // arrange
            var variables = new VariableCollection();

            var sut = new Var(variables, new PhraseDictionary());

            sut.Name  = "name";
            sut.Value = "value";

            // act
            var result = sut.Execute() as ValueResult;

            // assert
            Assert.Equal("value", result.Value);

            var variable = variables.Get("name") as ValueVariable;

            Assert.Equal("value", variable.Value);
        }
 private Response ReturnResolvedVariable(VariableCollection variableCollection, dynamic parameters) => FormatterExtensions.AsText(Response, variableCollection.Get(parameters.variable));