public void AddInheritedAction() { int parentEventsRaised = 0; int childEventsRaised = 0; Event parentEvent = new Event(Workspace.Instance.GetPlugin(TriggerOccursEventType)); parentEvent.Statements.CollectionChanged += (sender, e) => parentEventsRaised++; parentEvent.AddStatement(new Action(Workspace.Instance.GetPlugin(FireTriggerActionType))); ReadOnlyEvent childEvent = new ReadOnlyEvent(parentEvent); childEvent.Statements.CollectionChanged += (sender, e) => childEventsRaised++; Assert.AreEqual(1, childEvent.Statements.Count); parentEvent.AddStatement(new Action(Workspace.Instance.GetPlugin(FireTriggerActionType))); Assert.AreEqual(2, childEvent.Statements.Count); Assert.AreEqual(2, parentEventsRaised); Assert.AreEqual(1, childEventsRaised); }
public void AddLocalAction() { int eventsRaised = 0; Event evt = new Event(Workspace.Instance.GetPlugin(TriggerOccursEventType)); evt.Statements.CollectionChanged += (sender, e) => eventsRaised++; Action action = new Action(Workspace.Instance.GetPlugin(FireTriggerActionType)); evt.AddStatement(action); Assert.AreEqual(1, eventsRaised); Assert.IsTrue(action.IsEditable); Assert.AreEqual(1, evt.Statements.Count); }
public void AddConditionGroup() { bool collectionChanged = false; Event evt = new Event(Workspace.Instance.GetPlugin(TriggerOccursEventType)); evt.Statements.CollectionChanged += (o, e) => collectionChanged = true; ConditionGroup group = new ConditionGroup(); evt.AddStatement(group); Assert.IsTrue(collectionChanged); Assert.AreEqual(1, evt.Statements.Count); Assert.IsNotNull(group.If); Assert.IsNull(group.Else); }
public void CannotRemoveInheritedActionFromInheritingEvent() { Event parentEvent = new Event(Workspace.Instance.GetPlugin(TriggerOccursEventType)); Action parentAction = new Action(Workspace.Instance.GetPlugin(FireTriggerActionType)); parentEvent.AddStatement(parentAction); ReadOnlyEvent childEvent = new ReadOnlyEvent(parentEvent); Assert.AreEqual(1, childEvent.Statements.Count); AbstractStatement childAction = childEvent.Statements.Single(); childEvent.RemoveStatement(childAction); Assert.AreEqual(1, childEvent.Statements.Count); }
public void AddMultipleActionsOfSameType() { int eventsRaised = 0; Event evt = new Event(Workspace.Instance.GetPlugin(TriggerOccursEventType)); evt.Statements.CollectionChanged += (sender, e) => eventsRaised++; evt.AddStatement(new Action(Workspace.Instance.GetPlugin(FireTriggerActionType))); evt.AddStatement(new Action(Workspace.Instance.GetPlugin(FireTriggerActionType))); Assert.AreEqual(2, eventsRaised); Assert.AreEqual(2, evt.Statements.Count); }
public void InheritedActionPropertyFollowsSource() { bool childPropertyChanged = false; Event parentEvent = new Event(Workspace.Instance.GetPlugin(TriggerOccursEventType)); Action parentAction = new Action(Workspace.Instance.GetPlugin(FireTriggerActionType)); parentAction.SetProperty("Name", new Value("test", true)); parentEvent.AddStatement(parentAction); ReadOnlyEvent childEvent = new ReadOnlyEvent(parentEvent); AbstractProperty childProperty = ((AbstractAction)childEvent.Statements.Single()).GetProperty("Name"); childProperty.PropertyChanged += (sender, e) => childPropertyChanged |= (e.PropertyName == "Value"); parentAction.SetProperty("Name", new Value("test2", true)); Assert.AreEqual("test2", childProperty.Value.Reader.GetStrValue()); Assert.IsTrue(childPropertyChanged); }
private void CreateStatement(ParseTreeNode statementNode, Event evt, CompositeStatement compositeStatement = null) { AbstractStatement statement = null; if (statementNode.Term == grammar.Action) { statement = createAction(statementNode); } else if (statementNode.Term == grammar.Condition) { ConditionGroup conditionGroup = new ConditionGroup(); conditionGroup.If.Expression = getStrVal(statementNode.ChildNodes.First(child => child.Term == grammar.Expr)); foreach (ParseTreeNode child in grammar.GetOfType(statementNode, grammar.Actions)) CreateStatement(child, evt, conditionGroup.If); foreach (ParseTreeNode elseNode in grammar.GetOfType(statementNode, grammar.Else)) { string expr = getStrVal(elseNode.ChildNodes.FirstOrDefault(child => child.Term == grammar.Expr)); AbstractCondition cond; if (null == expr) { conditionGroup.Else = new BasicCondition(); cond = conditionGroup.Else; } else { cond = new ExpressionCondition() { Expression = expr }; conditionGroup.AddStatement(cond); } foreach (ParseTreeNode child in grammar.GetOfType(elseNode, grammar.Actions)) CreateStatement(child, evt, cond); } statement = conditionGroup; } else if (statementNode.Term == grammar.Assignment) { Assignment assignment = new Assignment(); assignment.Key = getStrVal(statementNode.ChildNodes[0]); assignment.Value = getStrVal(statementNode.ChildNodes.Last()); assignment.Operator = statementNode.ChildNodes.Count == 2 ? AssignmentOperator.Assign : AbstractAssignment.AssignmentValues[grammar.OpLookup[statementNode.ChildNodes[1].Term]]; statement = assignment; } else { CompositeStatement loop = null; switch (statementNode.ChildNodes.Count) { case 2: WhileLoop wl = new WhileLoop(); wl.Expression = getStrVal(statementNode.ChildNodes[0]); statement = loop = wl; break; case 3: ForLoop fl = new ForLoop(); fl.Expression = getStrVal(statementNode.ChildNodes[0]); //First assignment, expression, assignment, actions fl.PostExpression = getStrVal(statementNode.ChildNodes[1]); statement = loop = fl; break; case 4: ForLoop forLoop = new ForLoop(); forLoop.Expression = getStrVal(statementNode.ChildNodes[1]); //First assignment, expression, assignment, actions forLoop.PostExpression = getStrVal(statementNode.ChildNodes[2]); forLoop.PreExpression = getStrVal(statementNode.ChildNodes[0]); statement = loop = forLoop; break; } foreach (ParseTreeNode child in grammar.GetOfType(statementNode, grammar.Actions)) { // TODO: This is a hack to skip the Actions found in the first line of the for() statement. if (!statementNode.ChildNodes.Contains(child)) { CreateStatement(child, evt, loop); } } } if (compositeStatement == null) evt.AddStatement(statement); else compositeStatement.AddStatement(statement); }
public void AbstractConditionGroup_RemoveStatement() { var entity = new Entity(); var evt = new Event(Workspace.Instance.GetPlugin(typeof(TriggerOccursEvent))); var group = new ConditionGroup(); var elif = new ExpressionCondition(); var el = new BasicCondition(); group.AddStatement(elif); group.Else = el; evt.AddStatement(group); CommandHelper.TestUndoableCommand( () => Assert.AreEqual(elif, group.Statements.First()), () => entity.DeleteStatementCommand.Execute(elif), () => Assert.AreEqual(0, group.Statements.Count) ); CommandHelper.TestUndoableCommand( () => Assert.AreEqual(el, group.Else), () => entity.DeleteStatementCommand.Execute(el), () => Assert.IsNull(group.Else) ); }
public void Entity_DeleteStatement() { var entity = new Entity(); var evt = new Event(Workspace.Instance.GetPlugin(typeof(TriggerOccursEvent).FullName)); entity.AddEvent(evt); var loop = new WhileLoop(); evt.AddStatement(loop); CommandHelper.TestUndoableCommand( () => Assert.AreEqual(1, evt.Statements.Count), () => entity.DeleteStatementCommand.Execute(loop), () => Assert.AreEqual(0, evt.Statements.Count) ); }
public void AbstractStatement_InsertBefore() { var evt = new Event(Workspace.Instance.GetPlugin(typeof(TriggerOccursEvent).FullName)); var loop = new WhileLoop(); evt.AddStatement(loop); var stmt = new ForLoop(); CommandHelper.TestUndoableCommand( () => { Assert.AreEqual(1, evt.Statements.Count); Assert.AreEqual(0, evt.IndexOf(loop)); Assert.AreEqual(-1, evt.IndexOf(stmt)); }, () => loop.InsertBeforeCommand.Execute(stmt), () => { Assert.AreEqual(2, evt.Statements.Count); Assert.AreEqual(1, evt.IndexOf(loop)); Assert.AreEqual(0, evt.IndexOf(stmt)); } ); }
public void AddReadOnlyConditionGroup() { Event parentEvent = new Event(Workspace.Instance.GetPlugin(TriggerOccursEventType)); ReadOnlyEvent childEvent = new ReadOnlyEvent(parentEvent); parentEvent.AddStatement(new ConditionGroup()); Assert.AreEqual(1, childEvent.Statements.Count); ReadOnlyConditionGroup childGroup = childEvent.Statements.OfType<ReadOnlyConditionGroup>().Single(); Assert.IsNotNull(childGroup); }
public void RemoveConditionGroup() { int eventsFired = 0; Event evt = new Event(Workspace.Instance.GetPlugin(TriggerOccursEventType)); evt.Statements.CollectionChanged += (o, e) => eventsFired++; ConditionGroup group = new ConditionGroup(); evt.AddStatement(group); evt.RemoveStatement(group); Assert.AreEqual(2, eventsFired); Assert.AreEqual(0, evt.Statements.Count); }
public void AddReadOnlyElseIfCondition() { Event parentEvent = new Event(Workspace.Instance.GetPlugin(TriggerOccursEventType)); ReadOnlyEvent childEvent = new ReadOnlyEvent(parentEvent); ConditionGroup parentGroup = new ConditionGroup(); parentEvent.AddStatement(parentGroup); parentGroup.AddStatement(new ExpressionCondition() { Expression = "test > 1" }); Assert.AreEqual(1, childEvent.Statements.Count); ReadOnlyConditionGroup childGroup = childEvent.Statements.OfType<ReadOnlyConditionGroup>().Single(); Assert.IsNotNull(childGroup); ReadOnlyExpressionCondition childCondition = childGroup.Statements.OfType<ReadOnlyExpressionCondition>().Single(); Assert.AreEqual("test > 1", childCondition.Expression); }
public Event DeepCopy() { Event copy = new Event(Plugin); foreach (AbstractProperty property in Properties) { copy.SetProperty(property.Name, property.Value); } foreach (AbstractStatement statement in Statements) { copy.AddStatement(statement.DeepCopyStatement()); } return copy; }