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_only_unique_values_for_a_list_with_duplicates() { VariablesTypeVariableLocal_variable localVariable = LocalVariableBuilder. CreateTheLocalVariable(). WithUnique(). AddLiteralComponent(@"banana"). AddLiteralComponent(@"banana"). AddLiteralComponent(@"apple"). AddLiteralComponent(@"banana"). SetInLocalVariable(). Build(); oval_definitions definitions = this.ovalDocument.GetFakeOvalDefinitions("definitionsWithLocalVariable.xml"); Assert.IsNotNull(definitions, "the definitions was loaded"); oval_system_characteristics systemCharacteristics = this.ovalDocument.GetFakeOvalSystemCharacteristics("system_characteristics_with_local_variable.xml"); Assert.IsNotNull(systemCharacteristics, "the systemCharacteristics was not loaded"); LocalVariableComponentsFactory factory = new LocalVariableComponentsFactory(systemCharacteristics, definitions.variables); var uniqueFunctionComponent = factory.GetLocalVariableComponent(localVariable); Assert.IsInstanceOfType(uniqueFunctionComponent, typeof(UniqueFunctionComponent)); IEnumerable <string> values = uniqueFunctionComponent.GetValue(); Assert.AreEqual(2, values.Count()); Assert.AreEqual("banana", values.ElementAt(0)); Assert.AreEqual("apple", values.ElementAt(1)); }
private VariablesTypeVariableLocal_variable GetLocalVariableForRegexCaptureFunctionWithObjectComponent(string refValue, string itemFieldValue) { ObjectComponentType objectComponent = new ObjectComponentType() { object_ref = refValue, item_field = itemFieldValue }; RegexCaptureFunctionType regexCaptureFunctionType = new RegexCaptureFunctionType() { pattern = ".", Item = objectComponent }; VariablesTypeVariableLocal_variable localVariable = new VariablesTypeVariableLocal_variable() { Item = regexCaptureFunctionType }; return localVariable; }
public void Should_be_possible_to_calculate_the_difference_between_dates_with_objectComponent_with_multiples_values() { VariablesTypeVariableLocal_variable localVariable = LocalVariableBuilder .CreateTheLocalVariable() .WithTimeDifference() .WithFirstFormat(DateTimeFormatEnumeration.day_month_year) .WithSecondFormat(DateTimeFormatEnumeration.day_month_year) .AddObjectComponent("value", "oval:org.mitre.oval:obj:10001") .AddObjectComponent("value", "oval:org.mitre.oval:obj:10002") .SetInLocalVariable() .Build(); LocalVariableComponentsFactory factory = new LocalVariableComponentsFactory(systemCharacteristics, definitions.variables); LocalVariableComponent component = factory.GetLocalVariableComponent(localVariable); IEnumerable <string> values = component.GetValue(); DateTime firstDate = new DateTime(2009, 10, 25, 0, 0, 0); DateTime secondDate = new DateTime(2009, 11, 25, 0, 0, 0); TimeSpan firstElement = secondDate - firstDate; secondDate = new DateTime(2009, 12, 25, 0, 0, 0); TimeSpan secondElement = secondDate - firstDate; Assert.IsTrue(values.Count() > 0, "the quantity is not expected"); Assert.AreEqual(values.ElementAt(0), firstElement.TotalSeconds.ToString(), "the difference is not expected"); // in seconds Assert.AreEqual(values.ElementAt(1), secondElement.TotalSeconds.ToString(), "the difference is not expected"); // in seconds }
public void Should_be_possible_to_get_count_result_for_a_simple_list() { VariablesTypeVariableLocal_variable localVariable = LocalVariableBuilder. CreateTheLocalVariable(). WithCount(). AddLiteralComponent(@"banana"). AddLiteralComponent(@"apple"). SetInLocalVariable(). Build(); oval_definitions definitions = this.ovalDocument.GetFakeOvalDefinitions("definitionsWithLocalVariable.xml"); Assert.IsNotNull(definitions, "the definitions was loaded"); oval_system_characteristics systemCharacteristics = this.ovalDocument.GetFakeOvalSystemCharacteristics("system_characteristics_with_local_variable.xml"); Assert.IsNotNull(systemCharacteristics, "the systemCharacteristics was not loaded"); LocalVariableComponentsFactory factory = new LocalVariableComponentsFactory(systemCharacteristics, definitions.variables); var countFunctionComponent = factory.GetLocalVariableComponent(localVariable); Assert.IsInstanceOfType(countFunctionComponent, typeof(CountFunctionComponent)); IEnumerable <string> values = countFunctionComponent.GetValue(); Assert.AreEqual(1, values.Count()); Assert.AreEqual("2", values.First()); }
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"); }
public void Should_be_possible_to_calculate_the_difference_between_dates_with_literal_Component_with_seconds_since_epoch() { VariablesTypeVariableLocal_variable localVariable = LocalVariableBuilder .CreateTheLocalVariable() .WithTimeDifference() .WithFirstFormat(DateTimeFormatEnumeration.year_month_day) .WithSecondFormat(DateTimeFormatEnumeration.seconds_since_epoch) .AddLiteralComponent("2009-09-03 17:43:12") .AddLiteralComponent("1251996192") .SetInLocalVariable() .Build(); LocalVariableComponentsFactory factory = new LocalVariableComponentsFactory(systemCharacteristics, definitions.variables); LocalVariableComponent component = factory.GetLocalVariableComponent(localVariable); IEnumerable <string> values = component.GetValue(); TimeDifferenceFormatter formatter = new TimeDifferenceFormatter(); DateTime dateFromSeconds = formatter.GetDateInFormat("1251996192", DateTimeFormatEnumeration.seconds_since_epoch); DateTime firstDate = new DateTime(2009, 09, 03, 17, 43, 12); TimeSpan difference = dateFromSeconds - firstDate; Assert.IsTrue(values.Count() > 0, "the quantity is not expected"); Assert.IsTrue(values.ElementAt(0) == difference.TotalSeconds.ToString()); // in seconds }
public void Should_be_possible_to_get_value_of_concatFunction_with_ObjectComponent_and_LiteralComponent() { VariablesTypeVariableLocal_variable localVariable = LocalVariableBuilder. CreateTheLocalVariable(). WithConcat(). AddLiteralComponent(@"c:\"). AddObjectComponent("oval:org.mitre.oval:obj:1000", "family"). SetInLocalVariable(). Build(); oval_definitions definitions = this.ovalDocument.GetFakeOvalDefinitions("definitionsWithLocalVariable.xml"); Assert.IsNotNull(definitions, "the definitions was loaded"); oval_system_characteristics systemCharacteristics = this.ovalDocument.GetFakeOvalSystemCharacteristics("system_characteristics_with_local_variable.xml"); Assert.IsNotNull(systemCharacteristics, "the systemCharacteristics was not loaded"); LocalVariableComponentsFactory factory = new LocalVariableComponentsFactory(systemCharacteristics, definitions.variables); LocalVariableComponent concatFunctionComponent = factory.GetLocalVariableComponent(localVariable); Assert.IsInstanceOfType(concatFunctionComponent, typeof(ConcatFunctionComponent)); IEnumerable <string> values = concatFunctionComponent.GetValue(); Assert.IsTrue(values.Count() > 0, "the quantity is not expected"); Assert.IsTrue(values.ElementAt(0) == @"c:\windows", "the value is not expected"); }
public void Should_be_possible_to_get_value_of_concatFunction_with_multiples_values_of_return() { VariablesTypeVariableLocal_variable localVariable = LocalVariableBuilder. CreateTheLocalVariable(). WithConcat(). AddObjectComponent("oval:org.mitre.oval:obj:5000", "name"). AddLiteralComponent(@"\"). AddObjectComponent("oval:org.mitre.oval:obj:6000", "name"). AddLiteralComponent(@"\"). AddObjectComponent("oval:org.mitre.oval:obj:7000", "name"). SetInLocalVariable(). Build(); oval_definitions definitions = this.ovalDocument.GetFakeOvalDefinitions("definitionsWithLocalVariable.xml"); Assert.IsNotNull(definitions, "the definitions was loaded"); oval_system_characteristics systemCharacteristics = this.ovalDocument.GetFakeOvalSystemCharacteristics("system_characteristics_with_local_variable.xml"); Assert.IsNotNull(systemCharacteristics, "the systemCharacteristics was not loaded"); LocalVariableComponentsFactory factory = new LocalVariableComponentsFactory(systemCharacteristics, definitions.variables); LocalVariableComponent concatFunctionComponent = factory.GetLocalVariableComponent(localVariable); Assert.IsInstanceOfType(concatFunctionComponent, typeof(ConcatFunctionComponent)); IEnumerable <string> values = concatFunctionComponent.GetValue(); Assert.IsTrue(values.Count() == 4, "the quantity is not expected"); Assert.IsTrue(values.ElementAt(0) == @"BuildLabEx\SoftwareType\InstallDate", "the value is not expected"); Assert.IsTrue(values.ElementAt(1) == @"BuildLabEx\SystemRoot\InstallDate", "the value is not expected"); Assert.IsTrue(values.ElementAt(2) == @"CSDBuildNumber\SoftwareType\InstallDate", "the value is not expected"); Assert.IsTrue(values.ElementAt(3) == @"CSDBuildNumber\SystemRoot\InstallDate", "the value is not expected"); }
public void Should_throws_exception_when_the_value_type_is_not_correct_in_multiply_operation() { Assert.IsNotNull(definitions, "the definitions was loaded"); Assert.IsNotNull(systemCharacteristics, "the systemCharacteristics was not loaded"); VariablesTypeVariableLocal_variable localVariable = LocalVariableBuilder .CreateTheLocalVariable() .WithArithmetic() .WithArithmeticOperation(ArithmeticEnumeration.multiply) .AddLiteralComponent("A", SimpleDatatypeEnumeration.@string) .AddLiteralComponent("B", SimpleDatatypeEnumeration.@string) .SetInLocalVariable() .Build(); LocalVariableComponentsFactory factory = new LocalVariableComponentsFactory(systemCharacteristics, definitions.variables); LocalVariableComponent component = factory.GetLocalVariableComponent(localVariable); Assert.IsInstanceOfType(component, typeof(ArithmeticFunctionComponent)); try { IEnumerable <string> values = component.GetValue(); } catch (Exception exc) { Assert.IsInstanceOfType(exc, typeof(FormatException), "the exception is not corret in multiply operator"); } }
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); }
public void Should_be_possible_to_get_value_of_local_variable_without_system_characteristics() { VariablesTypeVariableLocal_variable variable = CreateALocalVariable(); LocalVariableEvaluator localVariableEvaluator = new LocalVariableEvaluator(variable, null, null); IEnumerable <string> values = localVariableEvaluator.GetValue(); Assert.IsTrue(values.Count() == 0, "the quantity of values is not expected."); }
public void Should_be_possible_to_get_value_of_local_variable() { VariablesTypeVariableLocal_variable variable = CreateALocalVariable(); oval_system_characteristics systemCharacteristics = new OvalDocumentLoader().GetFakeOvalSystemCharacteristics("system_characteristics_with_local_variable.xml"); LocalVariableEvaluator localVariableEvaluator = new LocalVariableEvaluator(variable, systemCharacteristics, null); IEnumerable <string> values = localVariableEvaluator.GetValue(); Assert.IsTrue(values.Count() > 0, "the quantity of values is not expected."); Assert.IsTrue(values.ElementAt(0) == @"Software\Microsoft\Windows NT\CurrentVersion", "the value is not expected"); }
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; }
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"); }
private static VariablesTypeVariableLocal_variable CreateALocalVariable() { VariablesTypeVariableLocal_variable variable = new VariablesTypeVariableLocal_variable(); variable.id = "oval:org.mitre.oval:var:4000"; variable.datatype = Modulo.Collect.OVAL.Common.SimpleDatatypeEnumeration.@string; 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_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"); }
private VariablesTypeVariableLocal_variable GetLocalVariableForRegexCaptureFunctionWithObjectComponent(string refValue, string itemFieldValue) { ObjectComponentType objectComponent = new ObjectComponentType() { object_ref = refValue, item_field = itemFieldValue }; RegexCaptureFunctionType regexCaptureFunctionType = new RegexCaptureFunctionType() { pattern = ".", Item = objectComponent }; VariablesTypeVariableLocal_variable localVariable = new VariablesTypeVariableLocal_variable() { Item = regexCaptureFunctionType }; return(localVariable); }
public void Should_be_possible_add_the_character_in_the_end_of_expression_if_the_expression_not_start_with_him() { VariablesTypeVariableLocal_variable localVariable = LocalVariableBuilder .CreateTheLocalVariable() .WithEnd() .WithCharacter(";") .AddLiteralComponent("CurrentVersion") .SetInLocalVariable() .Build(); LocalVariableComponentsFactory factory = new LocalVariableComponentsFactory(systemCharacteristics, definitions.variables); LocalVariableComponent component = factory.GetLocalVariableComponent(localVariable); IEnumerable <string> values = component.GetValue(); Assert.IsTrue(values.Count() == 1, "the quantity of values is not expected"); Assert.IsTrue(values.ElementAt(0) == "CurrentVersion;", "the quantity of values is not expected"); }
public void Should_be_possible_to_apply_a_beginFunction_with_ObjectComponent_defined() { VariablesTypeVariableLocal_variable localVariable = LocalVariableBuilder .CreateTheLocalVariable() .WithBegin() .WithCharacter(@"Software\") .AddObjectComponent("oval:org.mitre.oval:obj:3000", "name") .SetInLocalVariable() .Build(); LocalVariableComponentsFactory factory = new LocalVariableComponentsFactory(systemCharacteristics, definitions.variables); LocalVariableComponent component = factory.GetLocalVariableComponent(localVariable); IEnumerable <string> values = component.GetValue(); Assert.IsTrue(values.Count() == 1, "the quantity of values is not expected"); Assert.IsTrue(values.ElementAt(0) == @"Software\CurrentVersion", "the value is not expected"); }
public void Should_not_be_possible_to_apply_a_EndFunction_with_multiples_components_defined_in_evaluators() { VariablesTypeVariableLocal_variable localVariable = LocalVariableBuilder .CreateTheLocalVariable() .WithEnd() .WithCharacter(@"\Software") .AddLiteralComponent(@"\Software\Microsoft\Windows NT\CurrentVersion") .SetInLocalVariable() .Build(); LocalVariableComponentsFactory factory = new LocalVariableComponentsFactory(systemCharacteristics, definitions.variables); LocalVariableComponent component = factory.GetLocalVariableComponent(localVariable); //add new component evaluator in endFunction ((LocalVariableFunctionComponent)component).AddComponent(new ArithmeticFunctionComponent(null)); IEnumerable <string> values = component.GetValue(); }
public void Should_not_add_the_character_in_the_start_of_expression_if_the_expression_start_with_him() { VariablesTypeVariableLocal_variable localVariable = LocalVariableBuilder .CreateTheLocalVariable() .WithBegin() .WithCharacter(@"\Software") .AddLiteralComponent(@"\Software\Microsoft\Windows NT\CurrentVersion") .SetInLocalVariable() .Build(); LocalVariableComponentsFactory factory = new LocalVariableComponentsFactory(systemCharacteristics, definitions.variables); LocalVariableComponent component = factory.GetLocalVariableComponent(localVariable); IEnumerable <string> values = component.GetValue(); Assert.IsTrue(values.Count() == 1, "the quantity of values is not expected"); Assert.IsTrue(values.ElementAt(0) == @"\Software\Microsoft\Windows NT\CurrentVersion", "the value is not expected"); }
public void Should_be_possible_to_get_value_of_escaperegex_function_with_ObjectComponent() { Assert.IsNotNull(definitions, "the definitions was loaded"); Assert.IsNotNull(systemCharacteristics, "the systemCharacteristics was not loaded"); VariablesTypeVariableLocal_variable localVariable = LocalVariableBuilder .CreateTheLocalVariable() .WithEscapeRegex() .AddObjectComponent("oval:org.mitre.oval:obj:3000", "key") .SetInLocalVariable() .Build(); LocalVariableComponentsFactory factory = new LocalVariableComponentsFactory(systemCharacteristics, definitions.variables); LocalVariableComponent localVariableComponent = factory.GetLocalVariableComponent(localVariable); IEnumerable <string> values = localVariableComponent.GetValue(); Assert.IsTrue((values.Count() == 1), "the quantity is not expected"); Assert.IsTrue(values.ElementAt(0).Equals(@"Software\\Microsoft\\Windows\ NT\\CurrentVersion"), "the value is not expected"); }
public void Should_be_possible_to_get_value_of_escaperegex_function_with_LiteralComponent() { Assert.IsNotNull(definitions, "the definitions was loaded"); Assert.IsNotNull(systemCharacteristics, "the systemCharacteristics was not loaded"); VariablesTypeVariableLocal_variable localVariable = LocalVariableBuilder .CreateTheLocalVariable() .WithEscapeRegex() .AddLiteralComponent(@"C:\Windows") .SetInLocalVariable() .Build(); LocalVariableComponentsFactory factory = new LocalVariableComponentsFactory(systemCharacteristics, definitions.variables); LocalVariableComponent localVariableComponent = factory.GetLocalVariableComponent(localVariable); IEnumerable <string> values = localVariableComponent.GetValue(); Assert.IsTrue((values.Count() == 1), "the quantity is not expected"); Assert.IsTrue(values.ElementAt(0).Equals(@"C:\\Windows"), "the value is not expected"); }
public void Should_be_possible_to_get_value_of_splitFunction_with_ObjectComponent() { VariablesTypeVariableLocal_variable localVariable = LocalVariableBuilder. CreateTheLocalVariable(). WithSplit(). WithDelimeter("."). AddObjectComponent("oval:org.mitre.oval:obj:8000", "value"). SetInLocalVariable(). Build(); Assert.IsNotNull(definitions, "the definitions was loaded"); Assert.IsNotNull(systemCharacteristics, "the systemCharacteristics was not loaded"); LocalVariableComponentsFactory factory = new LocalVariableComponentsFactory(systemCharacteristics, definitions.variables); LocalVariableComponent localVariableComponent = factory.GetLocalVariableComponent(localVariable); IEnumerable <string> values = localVariableComponent.GetValue(); Assert.IsTrue((values.Count() == 2), "the quantity is not expected"); Assert.IsTrue(values.ElementAt(0).ToString() == "4", "the value of first element is not expected"); Assert.IsTrue(values.ElementAt(1).ToString() == "0", "the value of second element 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_be_possible_to_get_value_of_regexcapture_function_with_ObjectComponent() { Assert.IsNotNull(definitions, "the definitions was loaded"); Assert.IsNotNull(systemCharacteristics, "the systemCharacteristics was not loaded"); VariablesTypeVariableLocal_variable localVariable = LocalVariableBuilder. CreateTheLocalVariable(). WithRegexCapture(). WithPattern("(B.{4})"). AddObjectComponent("oval:org.mitre.oval:obj:5000", "name"). SetInLocalVariable(). Build(); LocalVariableComponentsFactory factory = new LocalVariableComponentsFactory(systemCharacteristics, definitions.variables); LocalVariableComponent localVariableComponent = factory.GetLocalVariableComponent(localVariable); IEnumerable <string> values = localVariableComponent.GetValue(); Assert.IsTrue((values.Count() == 2), "the quantity is not expected"); Assert.IsTrue(values.ElementAt(0).Equals("Build"), "the value of first element is not expected"); Assert.IsTrue(values.ElementAt(1).Equals("Build"), "the value of second element is not expected"); }
public void Should_be_possible_to_calculate_the_difference_between_dates_with_literal_component_with_differents_formats() { VariablesTypeVariableLocal_variable localVariable = LocalVariableBuilder .CreateTheLocalVariable() .WithTimeDifference() .WithFirstFormat(DateTimeFormatEnumeration.day_month_year) .WithSecondFormat(DateTimeFormatEnumeration.month_day_year) .AddLiteralComponent("25/09/2009 00:00:00") .AddLiteralComponent("09/25/2009 00:00:10") .SetInLocalVariable() .Build(); LocalVariableComponentsFactory factory = new LocalVariableComponentsFactory(systemCharacteristics, definitions.variables); LocalVariableComponent component = factory.GetLocalVariableComponent(localVariable); IEnumerable <string> values = component.GetValue(); Assert.IsTrue(values.Count() > 0, "the quantity is not expected"); Assert.IsTrue(values.ElementAt(0) == "10"); // in seconds }
private VariablesTypeVariableLocal_variable GetLocalVariableForAddOperationWithLiteralComponentTypeInt() { LiteralComponentType literalComponent1 = new LiteralComponentType() { Value = 10.ToString(), datatype = SimpleDatatypeEnumeration.@int }; LiteralComponentType literalComponent2 = new LiteralComponentType() { Value = 10.ToString(), datatype = SimpleDatatypeEnumeration.@int }; ArithmeticFunctionType arithmeticFunctionType = new ArithmeticFunctionType() { arithmetic_operation = ArithmeticEnumeration.add, Items = new [] { literalComponent1, literalComponent2 } }; VariablesTypeVariableLocal_variable localVariable = new VariablesTypeVariableLocal_variable() { Item = arithmeticFunctionType }; return(localVariable); }
public void Should_be_possible_to_get_value_of_arithmeticFunction_with_add_operation() { VariablesTypeVariableLocal_variable localVariableInt = LocalVariableBuilder .CreateTheLocalVariable() .WithArithmetic() .WithArithmeticOperation(ArithmeticEnumeration.add) .AddLiteralComponent(10.ToString(), SimpleDatatypeEnumeration.@int) .AddLiteralComponent(10.ToString(), SimpleDatatypeEnumeration.@int) .SetInLocalVariable() .Build(); Assert.IsNotNull(definitions, "the definitions was loaded"); Assert.IsNotNull(systemCharacteristics, "the systemCharacteristics was not loaded"); LocalVariableComponentsFactory factory = new LocalVariableComponentsFactory(systemCharacteristics, definitions.variables); LocalVariableComponent component = factory.GetLocalVariableComponent(localVariableInt); Assert.IsInstanceOfType(component, typeof(ArithmeticFunctionComponent)); IEnumerable <string> values = component.GetValue(); Assert.IsTrue(values.Count() == 1, "the quantity of values is not expected"); Assert.IsTrue(values.ElementAt(0) == 20.ToString(), "the value is not expected"); VariablesTypeVariableLocal_variable localVariableFloat = LocalVariableBuilder .CreateTheLocalVariable() .WithArithmetic() .WithArithmeticOperation(ArithmeticEnumeration.add) .AddLiteralComponent(10.1.ToString(), SimpleDatatypeEnumeration.@float) .AddLiteralComponent(10.1.ToString(), SimpleDatatypeEnumeration.@float) .SetInLocalVariable() .Build(); component = factory.GetLocalVariableComponent(localVariableFloat); Assert.IsInstanceOfType(component, typeof(ArithmeticFunctionComponent)); values = component.GetValue(); Assert.IsTrue(values.Count() == 1, "the quantity of values is not expected"); Assert.IsTrue(values.ElementAt(0) == 20.2f.ToString(), "the value is not expected"); }