public LocalVariableEvaluator(
     VariablesTypeVariableLocal_variable variable, 
     oval_system_characteristics systemCharacteristics, 
     IEnumerable<VariableType> variablesOfDefinitions,
     Modulo.Collect.OVAL.Variables.oval_variables externalVariables = null)
 {
     this.variable = variable;
     this.systemCharacteristics = systemCharacteristics;
     this.localVariableComponentFactory = new LocalVariableComponentsFactory(systemCharacteristics, variablesOfDefinitions, externalVariables);
     this.variablesOfDefinitions = variablesOfDefinitions;
 }
 private VariablesTypeVariableLocal_variable GetLocalVariableForAddOperationWithLiteralComponentTypeInt()
 {
     LiteralComponentType literalComponent1 = new LiteralComponentType() { Value = 10.ToString(),  datatype = [email protected] };
     LiteralComponentType literalComponent2 = new LiteralComponentType() { Value = 10.ToString(), datatype = [email protected] };
     ArithmeticFunctionType arithmeticFunctionType = new ArithmeticFunctionType() { arithmetic_operation = ArithmeticEnumeration.add, Items = new [] { literalComponent1, literalComponent2 } };
     VariablesTypeVariableLocal_variable localVariable = new VariablesTypeVariableLocal_variable() { Item = arithmeticFunctionType };
     return localVariable;
 }
 public OvalLocalVariableBuilder CreateTheLocalVariable()
 {
     this.localVariable = new VariablesTypeVariableLocal_variable();
     return this;
 }
 /// <summary>
 /// Gets the correct instance of localVariableComponent.
 /// </summary>
 /// <param name="localVariable">The local variable.</param>
 /// <returns></returns>
 public LocalVariableComponent GetLocalVariableComponent(VariablesTypeVariableLocal_variable localVariable)
 {
     return this.InstantiateTheCorrectTypeOfComponent(localVariable.Item, localVariable);
 }
        private static VariablesTypeVariableLocal_variable CreateALocalVariable()
        {
            VariablesTypeVariableLocal_variable variable = new VariablesTypeVariableLocal_variable();
            variable.id = "oval:org.mitre.oval:var:4000";
            variable.datatype = [email protected];

            ObjectComponentType objecttype = new ObjectComponentType();
            objecttype.object_ref = "oval:org.mitre.oval:obj:3000";
            objecttype.item_field = "key";
            variable.Item = objecttype;
            return variable;
        }
        public void Should_be_possible_to_instantiate_a_ConstantVariableComponent()
        {
            VariablesTypeVariableLocal_variable localVariable = new VariablesTypeVariableLocal_variable() { Item = new ObjectComponentType() };

            LocalVariableComponentsFactory factory = new LocalVariableComponentsFactory(null, null);
            LocalVariableComponent variableComponent = factory.GetLocalVariableComponent(localVariable);

            Assert.IsInstanceOfType(variableComponent, typeof(LocalVariableObjectComponent),"the variable component is not expected");
        }
        public void Should_be_possible_to_instantiate_a_CountFunctionComponent()
        {
            var function = new CountFunctionType() { Items = new object[] { new ObjectComponentType(), new ObjectComponentType() } };
            var localVariable = new VariablesTypeVariableLocal_variable() { Item = function };

            var factory = new LocalVariableComponentsFactory(null, null);
            var variableComponent = factory.GetLocalVariableComponent(localVariable);

            Assert.IsInstanceOfType(variableComponent, typeof(CountFunctionComponent));
            Assert.IsTrue(((CountFunctionComponent)variableComponent).QuantityOfComponents() == 2, "the quantity of component is not expected");
        }
        public void Should_be_possible_to_instantiate_an_SubstringFunctionComponent()
        {
            var function = new SubstringFunctionType() { Item = new LiteralComponentType() } ;
            var localVariable = new VariablesTypeVariableLocal_variable() { Item = function };

            var factory = new LocalVariableComponentsFactory(null, null);
            var variableComponent = factory.GetLocalVariableComponent(localVariable);

            Assert.IsInstanceOfType(variableComponent, typeof(SubStringFunctionComponent));
            Assert.IsTrue(((SubStringFunctionComponent)variableComponent).QuantityOfComponents() == 1, "the quantity of component is not expected");
        }
        public void Should_be_possible_to_get_value_to_variableComponent_by_the_constantVariable()
        {
            oval_definitions definitions = new OvalDocumentLoader().GetFakeOvalDefinitions("definitionsWithLocalVariable.xml");
            Assert.IsNotNull(definitions);
            VariableComponentType variableComponent = new VariableComponentType() { var_ref = "oval:org.mitre.oval:var:3000" };
            VariablesTypeVariableLocal_variable localVariable = new VariablesTypeVariableLocal_variable() { id = "oval:org.mitre.oval:var:5000" };

            LocalVariableVariablesComponent variableComponentEvaluator = new LocalVariableVariablesComponent(localVariable,variableComponent,definitions.variables,null);
            IEnumerable<string> values = variableComponentEvaluator.GetValue();
            Assert.IsTrue(values.Count() > 0, "the quantity of values is not expected.");
            Assert.IsTrue(values.ElementAt(0) == "Multiprocessor Free", "the value is not expected");
        }
        public void Should_not_be_possible_to_get_value_to_variableComponent_if_this_variable_refer_his_localVariable()
        {
            OvalDocumentLoader ovalDocuments = new OvalDocumentLoader();

            oval_definitions definitions = ovalDocuments.GetFakeOvalDefinitions("definitionsWithLocalVariable.xml");
            Assert.IsNotNull(definitions);
            oval_system_characteristics systemSystemCharacteristics = ovalDocuments.GetFakeOvalSystemCharacteristics("system_characteristics_with_local_variable.xml");
            Assert.IsNotNull(systemSystemCharacteristics);

            VariablesTypeVariableLocal_variable localVariable = new VariablesTypeVariableLocal_variable() { id = "oval:org.mitre.oval:var:4000" };

            VariableComponentType variableComponent = new VariableComponentType() { var_ref = "oval:org.mitre.oval:var:4000" };
            LocalVariableVariablesComponent variableComponentEvaluator = new LocalVariableVariablesComponent(localVariable,variableComponent, definitions.variables, systemSystemCharacteristics);
            IEnumerable<string> values = variableComponentEvaluator.GetValue();
            Assert.IsTrue(values.Count() == 0);
        }
        public void Should_be_possible_to_get_value_to_variableComponent_by_the_LocalVariable()
        {
            OvalDocumentLoader ovalDocuments = new OvalDocumentLoader();

            oval_definitions definitions = ovalDocuments.GetFakeOvalDefinitions("definitionsWithLocalVariable.xml");
            Assert.IsNotNull(definitions);
            oval_system_characteristics systemSystemCharacteristics = ovalDocuments.GetFakeOvalSystemCharacteristics("system_characteristics_with_local_variable.xml");
            Assert.IsNotNull(systemSystemCharacteristics);
            VariablesTypeVariableLocal_variable localVariable = new VariablesTypeVariableLocal_variable() { id = "oval:org.mitre.oval:var:5000" };

            VariableComponentType variableComponent = new VariableComponentType() { var_ref = "oval:org.mitre.oval:var:4000" };
            LocalVariableVariablesComponent variableComponentEvaluator = new LocalVariableVariablesComponent(localVariable,variableComponent, definitions.variables, systemSystemCharacteristics);
            IEnumerable<string> values = variableComponentEvaluator.GetValue();
            Assert.IsTrue(values.Count() > 0, "the quantity of value is not expected");
            Assert.IsTrue(values.ElementAt(0) == @"Software\Microsoft\Windows NT\CurrentVersion", "the value is not expected");
        }
 private IEnumerable<string> EvaluateVariable(VariablesTypeVariableLocal_variable localVariable)
 {
     LocalVariableComponentsFactory factory = new LocalVariableComponentsFactory(OvalSystemCharacteristics, OvalDefinitions.variables);
     LocalVariableComponent localVariableComponent = factory.GetLocalVariableComponent(localVariable);
     IEnumerable<string> values = localVariableComponent.GetValue();
     return values;
 }