public void TwoVariablesSameNameRoundTripSerialize() { TestSequence sequence = new TestSequence("Sequence"); Variable <int> intVar = VariableHelper.Create <int>("some name"); sequence.Variables.Add(intVar); TestSequence sequence2 = new TestSequence("Sequence"); Variable <double> doubleVar = VariableHelper.Create <double>("some name"); sequence2.Variables.Add(doubleVar); sequence2.Activities.Add(new TestWriteLine("w1", "I'm a funny writeLine") { HintMessage = "I'm a funny writeLine" }); sequence.Activities.Add(sequence2); TestRuntime.RunAndValidateWorkflow(sequence); }
public void AddSameElementToParentAndChild() { TestFlowchart flowchart1 = new TestFlowchart("flowChart1"); TestFlowchart flowchart2 = new TestFlowchart("flowChart2"); TestWriteLine w1 = new TestWriteLine("W1", "Executing W1"); TestFlowElement fStep = new TestFlowStep(w1); flowchart2.Elements.Add(fStep); Variable <int> margin = VariableHelper.CreateInitialized <int>("Margin", 10); flowchart1.Variables.Add(margin); TestFlowConditional flowDecision = new TestFlowConditional(HintTrueFalse.True) { ConditionExpression = (context => margin.Get(context) > 0) }; TestFlowElement tCond = flowchart1.AddConditionalLink(null, flowDecision, fStep, flowchart2); TestRuntime.ValidateInstantiationException(flowchart1, string.Format(ErrorStrings.FlowNodeCannotBeShared, flowchart1.DisplayName, flowchart2.DisplayName)); }
public void DecisionFalseEvaluation() { TestFlowchart flowchart = new TestFlowchart("Flow1"); Variable <int> counter = VariableHelper.CreateInitialized <int>("counter", 3); flowchart.Variables.Add(counter); TestWriteLine writeLine1 = new TestWriteLine("hello1", "Hello1"); TestWriteLine writeLine2 = new TestWriteLine("hello2", "Hello2"); TestWriteLine writeLine3 = new TestWriteLine("hello3", "Hello3"); TestFlowConditional flowDecision = new TestFlowConditional(HintTrueFalse.False); flowDecision.ConditionExpression = (context => counter.Get(context) > 3); flowchart.AddStartLink(writeLine1); flowchart.AddConditionalLink(writeLine1, flowDecision, writeLine2, writeLine3); TestRuntime.RunAndValidateWorkflow(flowchart); }
public void Should_be_possible_to_execute_a_registry_collect_with_variables() { // Arrange string[] fakeVarValues = new string[] { @"Software\Microsoft\Windows NT\CurrentVersion" }; oval_definitions fakeDefinitions = ProbeHelper.GetFakeOvalDefinitions("definitionsWithConstantVariable.xml"); var fakeObjects = fakeDefinitions.objects.OfType <registry_object>().ToArray(); VariablesEvaluated variables = VariableHelper.CreateVariableWithMultiplesValue(OBJ_3000_ID, VAR_3000_ID, fakeVarValues); CollectInfo fakeCollectInfo = ProbeHelper.CreateFakeCollectInfo(fakeObjects, variables, null); registry_item fakeRegistryItem = this.GetFakeRegistryItem(@"Software\Microsoft\Windows NT\CurrentVersion", "CurrentVersion", eValueTypes.STRING, "6.0"); RegistryProber registryProber = this.GetMockedRegistryProber(fakeRegistryItem); // Act IEnumerable <CollectedObject> result = registryProber.Execute(fakeContext, fakeTarget, fakeCollectInfo).CollectedObjects; // Assert Assert.AreEqual(1, result.Count(), "the quantity is not expected"); this.AssertProbeResultItem(result.ElementAt(0), fakeDefinitions.objects[1].id, fakeVarValues, new List <registry_item>() { fakeRegistryItem }); }
public CodeNamespace Build(JdbcQueryActivity jdbcQueryActivity) { var dataAccessNameSpace = new CodeNamespace(TargetAppNameSpaceService.dataAccessNamespace()); dataAccessNameSpace.Imports.AddRange(this.GenerateImport(jdbcQueryActivity)); var dataAccessToGenerate = new CodeTypeDeclaration(); dataAccessToGenerate.IsClass = true; dataAccessToGenerate.TypeAttributes = TypeAttributes.Public; dataAccessToGenerate.Name = VariableHelper.ToClassName(jdbcQueryActivity.ClassName) + "DataAccess"; dataAccessToGenerate.Members.AddRange(this.GenererateFields(jdbcQueryActivity)); dataAccessToGenerate.Members.AddRange(this.GenererateContructors(jdbcQueryActivity, dataAccessToGenerate)); dataAccessToGenerate.Members.AddRange(this.GenererateMethods(jdbcQueryActivity)); dataAccessNameSpace.Types.Add(dataAccessToGenerate); return(dataAccessNameSpace); }
public void DecisionTrueEvaluation() { TestFlowchart flowchart = new TestFlowchart("Flow1"); Variable <int> counter = VariableHelper.CreateInitialized <int>("counter", 3); flowchart.Variables.Add(counter); TestWriteLine writeLine1 = new TestWriteLine("hello1", "Hello1"); TestWriteLine writeLine2 = new TestWriteLine("hello2", "Hello2"); TestWriteLine writeLine3 = new TestWriteLine("hello3", "Hello3"); TestFlowConditional flowDecision = new TestFlowConditional { ConditionExpression = ((env) => (counter.Get(env) == 3)) }; flowchart.AddConditionalLink(writeLine1, flowDecision, writeLine2, writeLine3); TestRuntime.RunAndValidateWorkflow(flowchart); }
public void Should_be_possible_to_evaluate_variable_for_all_entities_at_same_time() { var sourceObject = ProbeHelper.GetOvalComponentByOvalID(this.Definitions, ConstantHelper.OBJECT_ID_1050); var variablesAndValues = this.CreateVariableAndValuesDictionary(sourceObject.id); var evaluatedVariables = VariableHelper.CreateEvaluatedVariables(sourceObject.id, variablesAndValues); var variableEvaluator = new FileEffectiveRights53EntityVariableEvaluator(evaluatedVariables); var evaluationResult = variableEvaluator.ProcessVariables(sourceObject); DoBasicAssertForVariableProcessing(evaluationResult, 1, typeof(fileeffectiverights53_object)); var pathVariableValue = this.GetVariableValue(variablesAndValues.ElementAt(0).Key); AssertObjectEntity(evaluationResult.First(), ConstantHelper.PathEntityName, pathVariableValue); var filenameVariableValue = this.GetVariableValue(variablesAndValues.ElementAt(1).Key); AssertObjectEntity(evaluationResult.First(), ConstantHelper.FilenameEntityName, filenameVariableValue); var trusteeSIDVariableValue = this.GetVariableValue(variablesAndValues.ElementAt(2).Key); AssertObjectEntity(evaluationResult.First(), ConstantHelper.TrusteeSIDEntityName, trusteeSIDVariableValue); AssertCorrectnessOfFileEntities((fileeffectiverights53_object)evaluationResult.First()); }
public void SimpleWhileConditionFalse() { // Test case description: // Set condition to a valid rule and run with an activity in it. Condition is false. Variable <int> counter = VariableHelper.CreateInitialized <int>("countervar", 10); TestSequence outerSequence = new TestSequence("sequence") { Variables = { counter }, Activities = { new TestWhile("while") { ConditionExpression = ((env) => ((int)counter.Get(env)) < 3), HintIterationCount = 0, Body = new TestSequence("sequence") { Activities = { new TestSequence("sequence") { Activities = { new TestWriteLine("not execute", "i shudnt execute"), } }, new TestAssign <int>("Add One") { ToVariable = counter, ValueExpression = ((env) => (((int)counter.Get(env))) + 1), }, } } }, } }; TestRuntime.RunAndValidateWorkflow(outerSequence); }
public static Dictionary <string, Variable> MakeInputData(TestCasesTestCase testCase, VariableContext context) { var inputDicts = new Dictionary <string, Variable> (); foreach (var inputnode in testCase.InputNode) { context.InputDataMetaByName.TryGetValue(inputnode.Name, out InputDataMeta inputMeta); //an overwrite input data for a decision invocation if (inputMeta == null) { inputDicts.Add(inputnode.Name, MakeVariableFromType(inputnode.Value)); continue; } var itemMeta = FindDefMeta(context.ItemDefinitionMeta, null, inputMeta.TypeName); if (inputnode.ComponentSpecified) { var ctx = MakeContextInputs(itemMeta.Name, inputnode.Component, itemMeta, context.ItemDefinitionMeta); inputDicts.Add(inputnode.Name, ctx); } else if (inputnode.ListSpecified) { var lv = MakeList(itemMeta.Name, inputnode.List, itemMeta, context.ItemDefinitionMeta); inputDicts.Add(inputnode.Name, lv); } else { if (itemMeta != null) { inputDicts.Add(inputnode.Name, VariableHelper.MakeVariable(GetValueType(inputnode.Value), itemMeta.TypeName)); } else { inputDicts.Add(inputnode.Name, VariableHelper.MakeVariable(GetValueType(inputnode.Value), inputMeta.TypeName)); } } } return(inputDicts); }
public void BasicDoWhileTest() { Variable <int> counter = VariableHelper.CreateInitialized <int>("counter", 0); TestSequence outerSequence = new TestSequence("sequence1") { Variables = { counter }, Activities = { new TestDoWhile("dowhile act") { ConditionExpression = ((env) => ((int)counter.Get(env)) < 10), Body = new TestSequence("test sequence act") { Activities = { new TestWriteLine("write hello", "Its a small world after all"), new TestAssign <int>("Increment Counter") { ToVariable = counter, ValueExpression = ((env) => (((int)counter.Get(env))) + 1), // OR you can assign value directly (not using expression) // Value = 15 }, }, }, HintIterationCount = 10, } } }; TestRuntime.RunAndValidateWorkflow(outerSequence); }
public void SimpleDoWhileConditionTrue() { // Test case description: // Set condition to a valid rule and run with an activity in it. Condition is true Variable <int> counter = VariableHelper.CreateInitialized <int>("counter", 0); TestSequence outerSequence = new TestSequence("sequence1") { Variables = { counter }, Activities = { new TestDoWhile("dowhile act") { ConditionExpression = ((env) => ((int)counter.Get(env)) < 10), Body = new TestSequence("test sequence act") { Activities = { new TestWriteLine("write hello", "Its a small world after all"), new TestIncrement("Increment Counter") { CounterVariable = counter, }, }, }, HintIterationCount = 10, } } }; TestRuntime.RunAndValidateWorkflow(outerSequence); }
private void AssertResultByIndividualType(object expected, Variable actualrslt, string name = null) { if (expected == null) { if (actualrslt.IsListType()) { Assert.True(actualrslt.ListVal.Count == 0, name); return; } Assert.True(actualrslt.ValueType == DataTypeEnum.Null, name); return; } //singleton list if (actualrslt.IsListType() && actualrslt.ListVal.Count == 1) { Assert.Equal <Variable> (VariableHelper.MakeVariable(expected, actualrslt.ListVal[0].ValueType), actualrslt.ListVal[0]); return; } Assert.True(VariableHelper.MakeVariable(expected, actualrslt.ValueType).Equals(actualrslt), $"Failed asserting equal for expected:{expected} for decision name:{name}"); //Assert.Equal<Variable> (VariableHelper.MakeVariable (expected, actualrslt.ValueType), actualrslt); }
/// <summary> /// Initialization sequence. Request variables state from the 4x4 /// </summary> public async void Init() { LogHelper.LogInfo("Initialize model..."); try { VariableHelper.Init(); foreach (VariableModel variable in VariableHelper.Variables.Values) { VariableHelper.SetVariableValue(variable, await _FourByFourService.CommandGetVariable(variable.VariableName)); Event_VariableChanged(this, variable); } LogHelper.LogInfo("Variables loaded."); } catch (Exception e) { LogHelper.LogError(e.Message); } IsPanelLoadingVisible = false; IsPanelMainVisible = true; }
public void Should_be_possible_to_generate_itemTypes_from_objectTypes_with_regex_operation() { string hiveHKLM = eHiveNames.HKEY_LOCAL_MACHINE.ToString(); string startKey = "SOFTWARE\\Microsoft\\Windows"; var obj50003 = WindowsTestHelper.GetObjectFromDefinitions(DEFINITIONS_REGEX_ON_VALUE, OBJ_50003_ID); BaseObjectCollector fakeDataSource = WindowsTestHelper.GetDataSourceFakeWithRegex(startKey, 2); WmiDataProvider wmiDataProvider = new WmiDataProviderExpectFactory().GetFakeWmiDataProviderForTestInvokeMethodEnumKeyWithReturnSuccess(); RegistryItemTypeGenerator itemGenerator = new RegistryItemTypeGenerator() { SystemDataSource = fakeDataSource, WmiDataProvider = wmiDataProvider }; var itemsToCollect = itemGenerator.GetItemsToCollect(obj50003, VariableHelper.CreateEmptyEvaluatedVariables()).Cast <registry_item>(); Assert.AreEqual(4, itemsToCollect.Count()); this.AssertGeneratedRegistryItem(itemsToCollect.ElementAt(0), hiveHKLM, "SOFTWARE\\Microsoft\\Windows\\CurrentBuild", "CurrentBuild"); this.AssertGeneratedRegistryItem(itemsToCollect.ElementAt(1), hiveHKLM, "SOFTWARE\\Microsoft\\Windows\\CurrentBuild", "LastBuild"); this.AssertGeneratedRegistryItem(itemsToCollect.ElementAt(2), hiveHKLM, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion", "CurrentBuild"); this.AssertGeneratedRegistryItem(itemsToCollect.ElementAt(3), hiveHKLM, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion", "LastBuild"); }
private static string FormatActivityNameInXpath(string expression) { // @"\$([^/]*)\/" // \$ # Escaped parenthesis, means "starts with a '$' character" // ( # Parentheses in a regex mean "put (capture) the stuff in between into the Groups array" // [^/"")] # Any character that is not a '/', '"', ',', ')' character // * # Zero or more occurrences of the aforementioned chars" // ) # Close the capturing group // \/"") # "Ends with a '/', '"', ',', ')' character //var regex = new Regex(@"\$([^/]*)\/"); var regex = new Regex(@"\$([^/"",)]*)[/"",)]"); var variables = regex.Matches(expression); foreach (Match variable in variables) { string variableNameToModify = variable.Groups[1].ToString(); expression = expression.Replace("$" + variableNameToModify, VariableHelper.ToVariableName(variableNameToModify.Replace("$", string.Empty).Replace('-', '_').Replace('.', '_'))); } //expression = expression.Replace("$", string.Empty); return(expression); }
public void FlowSwitchConnectedToFlowDecision() { TestFlowchart flowchart = new TestFlowchart(); TestWriteLine wStart = new TestWriteLine("Start", "Flowchart started"); TestWriteLine wDefault = new TestWriteLine("Default", "Default"); TestWriteLine w1 = new TestWriteLine("One", "One wont execute"); TestWriteLine w3 = new TestWriteLine("Three", "Three wont execute"); TestWriteLine w2True = new TestWriteLine("True", "True will execute"); TestWriteLine w2False = new TestWriteLine("False", "False wont execute"); TestFlowStep fs1 = new TestFlowStep(w1); TestFlowStep fs3 = new TestFlowStep(w3); Variable <int> margin = VariableHelper.CreateInitialized <int>("Margin", 10); flowchart.Variables.Add(margin); TestFlowConditional flowDecision = new TestFlowConditional(HintTrueFalse.True) { ConditionExpression = (context => margin.Get(context) > 0) }; flowchart.AddConditionalLink(null, flowDecision, w2True, w2False); Dictionary <string, TestFlowElement> cases = new Dictionary <string, TestFlowElement>(); cases.Add("One", fs1); cases.Add("Two", flowDecision); cases.Add("Three", fs3); List <int> hints = new List <int>(); hints.Add(1); flowchart.AddStartLink(wStart); flowchart.AddSwitchLink <string>(wStart, cases, hints, "Two", wDefault); TestRuntime.RunAndValidateWorkflow(flowchart); }
public void ConnectFromFlowconditionalBothTrueAndFalseToDifferentFlowconditional() { TestFlowchart flowchart = new TestFlowchart(); Variable <int> counter = VariableHelper.CreateInitialized <int>("counter", 0); flowchart.Variables.Add(counter); TestAssign <int> assign = new TestAssign <int>("assign"); assign.ValueExpression = (e => counter.Get(e) + 1); assign.ToVariable = counter; List <HintTrueFalse> hints = new List <HintTrueFalse>(); for (int i = 0; i < 4; i++) { hints.Add(HintTrueFalse.False); } hints.Add(HintTrueFalse.True); TestFlowConditional conditional1 = new TestFlowConditional(hints.ToArray()); conditional1.ConditionExpression = (e => counter.Get(e) == 5); TestFlowConditional conditional2 = new TestFlowConditional(); conditional2.Condition = true; TestFlowConditional conditional3 = new TestFlowConditional(); conditional3.Condition = true; flowchart.AddLink(new TestWriteLine("Start", "Flowchart Started"), assign); flowchart.AddConditionalLink(assign, conditional1, conditional3, conditional2); flowchart.AddConditionalLink(null, conditional2, assign, (TestActivity)null); flowchart.AddConditionalLink(null, conditional3, new TestWriteLine("End", "The End"), (TestActivity)null); TestRuntime.RunAndValidateWorkflow(flowchart); }
public void FlowSwitchWithNodePointingToParentFlowSwitch() { TestFlowchart flowchart = new TestFlowchart(); Variable <int> counter = VariableHelper.CreateInitialized <int>("counter", 0); flowchart.Variables.Add(counter); TestIncrement increment = new TestIncrement("Inc", 1) { CounterVariable = counter }; TestWriteLine w1 = new TestWriteLine("One", "Will execute on first iteration"); TestWriteLine w2 = new TestWriteLine("Two", "Will execute on second iteration"); TestWriteLine w3 = new TestWriteLine("Three", "Will execute on third iteration"); TestWriteLine w4 = new TestWriteLine("Four", "Will execute on final iteration"); Dictionary <int, TestActivity> cases = new Dictionary <int, TestActivity>(); cases.Add(1, w1); cases.Add(2, w2); cases.Add(3, w3); List <int> hints = new List <int>(); hints.Add(0); hints.Add(1); hints.Add(2); hints.Add(-1); flowchart.AddLink(new TestWriteLine("Start", "Flowchart Started"), increment); flowchart.AddSwitchLink <int>(increment, cases, hints, env => counter.Get(env), w4); flowchart.AddLink(w1, increment); flowchart.AddLink(w2, increment); flowchart.AddLink(w3, increment); TestRuntime.RunAndValidateWorkflow(flowchart); }
public object Execute(VariableContext context = null) { if (context != null) { var ctxVar = VariableContextHelper.RetrieveLocaContext(context, _nameInput, false); if (ctxVar != null) { return(ctxVar); } var funcVar = VariableContextHelper.RetrieveFunctionInput(context, _nameInput, false); if (funcVar != null) { return(funcVar); } //get the input variables first before decision names if there is overlapping name conflicts var outVar = VariableContextHelper.RetrieveInputVariable(context, _nameInput, false); if (outVar != null) { return(outVar); } var decisionVar = DMNDoerHelper.EvaluateDecisionByName(context, _nameInput); if (decisionVar != null) { //all the values that override is always string variable var overrideVar = VariableContextHelper.RetrieveInputVariable(context, _nameInput, false); if (overrideVar != null) { return(VariableHelper.MakeVariable(overrideVar.StringVal, decisionVar.ValueType)); } return(decisionVar); } } return(new Variable(_nameInput)); }
private static Variable MakeList(string name, Collection <ValueType> listItems, ItemDefinitionMeta curItemDefMeta, Dictionary <string, ItemDefinitionMeta> itemDefMetaDict) { var iL = new List <Variable> (); var nested = false; foreach (var item in listItems) { if (item.ComponentSpecified) { var nestedCtx = MakeContextInputs(name, item.Component, curItemDefMeta, itemDefMetaDict); iL.Add(nestedCtx); nested = true; continue; } if (item.ListSpecified) { var nestedList = MakeList(name, item.List, curItemDefMeta, itemDefMetaDict); iL.Add(nestedList); nested = true; continue; } if (curItemDefMeta.TypeName == null) { throw new TCKException($"Missing type name for for item definition:{item.Value}"); } iL.Add(VariableHelper.MakeVariable(GetValueType(item.Value), curItemDefMeta.TypeName)); } if (!nested) { return(VariableHelper.MakeList(iL, curItemDefMeta.TypeName)); } return(iL); }
public void SimpleIfElse() { // Test case description: // Have simple if-else scenario with if, and else TestSequence outerSequence = new TestSequence("sequence1"); TestSequence innerSequence = new TestSequence("sequence act"); TestAssign <int> changeCounter = new TestAssign <int>("Elif"); Variable <int> counter = VariableHelper.CreateInitialized <int>("counter", 0); TestWriteLine writeLine = new TestWriteLine("write hello") { Message = "Its a small world after all" }; changeCounter.ToVariable = counter; changeCounter.ValueExpression = (env) => ((int)counter.Get(env)) + 15; TestIf ifAct = new TestIf("if act1", HintThenOrElse.Else) { ConditionExpression = ((env) => ((int)counter.Get(env)) > 10), ThenActivity = new TestWriteLine("NotExecuting", "Wont Execute"), ElseActivity = changeCounter }; TestIf ifAct2 = new TestIf("if act 2", HintThenOrElse.Then) { ConditionExpression = ((env) => ((int)counter.Get(env)) > 10), ThenActivity = innerSequence, }; outerSequence.Activities.Add(ifAct); outerSequence.Activities.Add(ifAct2); innerSequence.Activities.Add(writeLine); outerSequence.Variables.Add(counter); TestRuntime.RunAndValidateWorkflow(outerSequence); }
public void ThrowExceptionInIfCondition() { Variable <int> intVar = VariableHelper.CreateInitialized <int>("intVariable", 3); TestSequence sequence = new TestSequence("Sequence1") { Variables = { intVar, }, Activities = { new TestIf("if act", HintThenOrElse.Neither) { ExpectedOutcome = Outcome.UncaughtException(typeof(DivideByZeroException)), ConditionExpression = ((env) => (1 / ((int)(intVar.Get(env)) - 3) == 0)), ThenActivity = new TestSequence("Then Branch"), ElseActivity = new TestSequence("Else Branch"), } } }; TestRuntime.RunAndValidateAbortedException(sequence, typeof(DivideByZeroException), new Dictionary <string, string>()); }
public void Should_be_possible_to_get_a_registryObject_with_his_variables_processed() { oval_definitions definitions = ProbeHelper.GetFakeOvalDefinitions(DEFINITIONS_WITH_CONST_VARIABLES); registry_object ovalRegistryObject = (registry_object)ProbeHelper.GetOvalComponentByOvalID(definitions, OBJ_3000_ID); Assert.IsNotNull(ovalRegistryObject, "the oval registry object is not exists in the fakeDefinitions"); Dictionary <String, EntityObjectStringType> allRegistryEntities = OvalHelper.GetRegistryEntitiesFromObjectType(ovalRegistryObject); string expectedHiveValue = allRegistryEntities[registry_object_ItemsChoices.hive.ToString()].Value; string expectedNameValue = allRegistryEntities[registry_object_ItemsChoices.name.ToString()].Value; VariablesEvaluated variablesEvaluated = VariableHelper.CreateVariableWithOneValue(OBJ_3000_ID, VAR_3000_ID, VAR_3000_VALUE_1); RegistryEntityVariableEvaluator registryEntityVariableEvaluator = new RegistryEntityVariableEvaluator(variablesEvaluated); IEnumerable <RegistryObject> registries = registryEntityVariableEvaluator.ProcessVariableForRegistryObject(ovalRegistryObject); Assert.AreEqual(1, registries.Count(), "the quantity of registries is not expected"); Assert.AreEqual(expectedHiveValue, registries.ElementAt(0).Hive, "the hive value is not expected"); Assert.AreEqual(VAR_3000_VALUE_1, registries.ElementAt(0).Key, "the key value is not expected"); Assert.AreEqual(expectedNameValue, registries.ElementAt(0).Name, "the name value is not expected"); }
public void Should_be_possible_to_create_items_to_collect_from_object_WITHOUT_referenced_variable() { #region regkeyeffectiverights53_object //<regkeyeffectiverights53_object id="oval:modulo:obj:750" version="1" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#windows"> // <hive>HKEY_LOCAL_MACHINE</hive> // <key>SOFTWARE\Modulo\RiskManager</key> // <trustee_sid>S-1-5-21-501351562-481299158-1019697294-10279</trustee_sid> //</regkeyeffectiverights53_object> #endregion var EXPECTED_HIVE = "HKEY_LOCAL_MACHINE"; var EXPECTED_KEY = @"SOFTWARE\Modulo\RiskManager"; var EXPECTED_TRUSTEE = "S-1-5-21-501351562-481299158-1019697294-10279"; var regKeyEffectiveRightsObject = ProbeHelper.GetDefinitionObjectTypeByID("definitionsSimple.xml", "750"); var generatedItems = CreateRegKeyEffectiveRightsItemTypeGeneratorWithoutBehavior() .GetItemsToCollect(regKeyEffectiveRightsObject, VariableHelper.CreateEmptyEvaluatedVariables()); ItemTypeChecker.DoBasicAssertForItems(generatedItems.ToArray(), 1, typeof(regkeyeffectiverights_item), StatusEnumeration.notcollected); AssertGeneratedRegKeyEffectiveRightsItem(generatedItems.ElementAt(0), EXPECTED_HIVE, EXPECTED_KEY, EXPECTED_TRUSTEE); }
public void Should_be_possible_to_collect_a_FileObject_that_contains_a_referenced_variable() { // Arrange var objectType = ProbeHelper.GetDefinitionObjectTypeByID("definitionsSimple.xml", "oval:modulo:obj:3"); var variables = VariableHelper.CreateVariableWithOneValue("oval:modulo:obj:3", "oval:modulo:var:3", "c:\\temp"); var fakeCollectInfo = ProbeHelper.CreateFakeCollectInfo(new Definitions.ObjectType[] { objectType }, variables, null); var fakeWmiObjects = new WmiObject[] { this.createFakeWmiObject() }; var fakeFileItems = new ItemType[] { this.CreateFakeFileItem(null, "c:\\temp", "file1.txt") }; var fileProber = this.CreateMockedFileProber(fakeWmiObjects, fakeFileItems, null); // Act var collectedObjects = (List <CollectedObject>)fileProber.Execute(FakeContext, FakeTarget, fakeCollectInfo).CollectedObjects; // Assert Assert.IsNotNull(collectedObjects, "The result of file collect cannot be null"); Assert.IsNotNull(collectedObjects.Single(), string.Format("There is no collected object.")); this.AssertCollectedFileItems(collectedObjects.Single(), fakeWmiObjects); var collectedItem = (file_item)collectedObjects.Single().SystemData[0]; this.AssertPathAndFileNameEntitiesExistence(collectedItem); Assert.AreEqual("c:\\temp", collectedItem.path.Value, "The variable value was not set to file item entity."); }
public void SimpleEmptyWhile() { // Test case description: // Set condition to a valid rule and run 5-6 iterations without any activities in. Variable <int> counter = VariableHelper.CreateInitialized <int>("counter", 0); TestSequence rootSequence = new TestSequence("rootSequence"); rootSequence.Variables.Add(counter); TestWhile whileAct = new TestWhile("while act") { ConditionExpression = ((env) => ((int)counter.Get(env)) < 0), Body = new TestSequence("innerseq"), HintIterationCount = 10, }; rootSequence.Activities.Add(whileAct); whileAct.Body = null; TestRuntime.RunAndValidateWorkflow(rootSequence); }
public void WhileVariableNotInScope() { Variable <int> counter = VariableHelper.CreateInitialized <int>("counter", 0); TestWhile whileAct = new TestWhile("while act") { Condition = false, Body = new TestAssign <int> { Value = 12, ToVariable = counter, }, HintIterationCount = 10, }; string constraint1 = string.Format(ErrorStrings.VariableShouldBeOpen, counter.Name); string constraint2 = string.Format(ErrorStrings.VariableNotVisible, counter.Name); List <TestConstraintViolation> constraints = new List <TestConstraintViolation>(2); constraints.Add(new TestConstraintViolation(constraint1, "VariableReference<Int32>")); constraints.Add(new TestConstraintViolation(constraint2, "VariableReference<Int32>")); TestRuntime.ValidateWorkflowErrors(whileAct, constraints, constraint1); }
public void OnInit(DictionaryAtom initAtom) { InitializationAtom = initAtom; var kernel = (IKernel)initAtom.GetObject("Ninject.Kernel"); CommandExecutor = (CommandExecutor)kernel.Get <ICommandExecutor>(); _parsers = new Dictionary <string, IParser> { { "Command", kernel.Get <IParser>("CommandParser") }, { "Social", kernel.Get <IParser>("SocialCommandParser") }, { "Channel", kernel.Get <IParser>("PlayerChannelParser") }, { "Movement", kernel.Get <IParser>("MovementParser") } }; Log.DebugFormat("CommandManager registered {0} parsers.", _parsers.Count); VariableHelper.RegisterVariables(); Log.DebugFormat("CommandManager registered {0} variables.", VariableHelper.Count); Log.DebugFormat("{0} setup.", GetType()); EventManager.RegisterListener(this, typeof(OnGameInitialize), Instance_OnGameInitialize); }
public void DoWhileConditionThrowsException() { Variable <int> intVar = VariableHelper.CreateInitialized <int>("intVar", 3); TestDoWhile doWhile = new TestDoWhile("Do While") { ConditionOutcome = Outcome.UncaughtException(typeof(DivideByZeroException)), Variables = { intVar }, ConditionExpression = ((env) => (1 / ((int)(intVar.Get(env)) - 3) == 0)), Body = new TestWriteLine("Writeline") { Message = "This will be displayed once" }, HintIterationCount = 1 }; TestRuntime.RunAndValidateAbortedException(doWhile, typeof(DivideByZeroException), new Dictionary <string, string>()); }
public void DoWhileWithWorkFlowInvoker() { Variable <int> counter = VariableHelper.CreateInitialized <int>("counter", 0); TestAssign <int> increment = new TestAssign <int>("Increment Counter"); increment.ToVariable = counter; increment.ValueExpression = ((env) => (((int)counter.Get(env))) + 1); TestDoWhile doWhile = new TestDoWhile("dowhile") { ConditionExpression = (env) => ((int)counter.Get(env)) < 2, Body = increment, HintIterationCount = 2, Variables = { counter } }; TestWriteLine writeLine = new TestWriteLine("write hello"); writeLine.Message = "Its a small world after all"; TestRuntime.RunAndValidateUsingWorkflowInvoker(doWhile, null, null, null); }
private QilGenerator(bool debug) { _scope = new CompilerScopeManager<QilIterator>(); _outputScope = new OutputScopeManager(); _prefixesInUse = new HybridDictionary(); _f = new XsltQilFactory(new QilFactory(), debug); _xpathBuilder = new XPathBuilder((IXPathEnvironment)this); _xpathParser = new XPathParser<QilNode>(); _ptrnBuilder = new XPathPatternBuilder((IXPathEnvironment)this); _ptrnParser = new XPathPatternParser(); _refReplacer = new ReferenceReplacer(_f.BaseFactory); _invkGen = new InvokeGenerator(_f, debug); _matcherBuilder = new MatcherBuilder(_f, _refReplacer, _invkGen); _singlFocus = new SingletonFocus(_f); _funcFocus = new FunctionFocus(); _curLoop = new LoopFocus(_f); _strConcat = new QilStrConcatenator(_f); _varHelper = new VariableHelper(_f); _elementOrDocumentType = T.DocumentOrElement; _textOrAttributeType = T.NodeChoice(XmlNodeKindFlags.Text | XmlNodeKindFlags.Attribute); _nameCurrent = _f.QName("current", XmlReservedNs.NsXslDebug); _namePosition = _f.QName("position", XmlReservedNs.NsXslDebug); _nameLast = _f.QName("last", XmlReservedNs.NsXslDebug); _nameNamespaces = _f.QName("namespaces", XmlReservedNs.NsXslDebug); _nameInit = _f.QName("init", XmlReservedNs.NsXslDebug); _formatterCnt = 0; }