public Action(PreCondition preCond, Enter enter, Execute execute, Exit exit) { this.preCond = preCond; this.enter = enter; this.execute = execute; this.exit = exit; }
public void TestRefactorStateMachine() { Dictionary dictionary = CreateDictionary("Test"); NameSpace nameSpace = CreateNameSpace(dictionary, "N1"); StateMachine stateMachine = CreateStateMachine(nameSpace, "TestSM"); State state1 = CreateState(stateMachine, "S1"); State state2 = CreateState(stateMachine, "S2"); stateMachine.Default = "S1"; RuleCondition ruleCondition = CreateRuleAndCondition(stateMachine, "Test"); PreCondition preCondition = CreatePreCondition(ruleCondition, "THIS in S1"); Action action = CreateAction(ruleCondition, "THIS <- S2"); Variable var = CreateVariable(nameSpace, "TheVariable", "TestSM"); var.setDefaultValue("TestSM.S1"); Refactor(stateMachine, "TestSM2"); Assert.AreEqual("THIS in S1", preCondition.ExpressionText); Assert.AreEqual("THIS <- S2", action.ExpressionText); Assert.AreEqual(var.Type, stateMachine); }
/// <summary> /// Invoke the provided action with the expectation that it will thrown an exception. /// Assert that the thrown exception matches the provided expected exception. /// </summary> /// <param name="action">The action to invoke.</param> /// <param name="expectedException">The expected exception. If this is null, then no /// exception validation will be performed and the actual exception will just be returned.</param> /// <returns></returns> public static T Throws <T>(Action action, T expectedException = null) where T : Exception { PreCondition.AssertNotNull(action, nameof(action)); Exception actualException = null; try { action.Invoke(); } catch (Exception e) { actualException = e; } if (actualException == null) { if (expectedException == null) { Assert.Fail("Expected an exception to be thrown."); } else { Assert.Fail($"Expected an exception of type {expectedException.GetType()} to be thrown, but no exception was thrown."); } } else if (expectedException != null) { Assert.AreEqual(expectedException.GetType(), actualException.GetType(), "Wrong exception type thrown."); Assert.AreEqual(expectedException.Message, actualException.Message, "Wrong exception message."); } return(actualException as T); }
public BasketPurchasePolicy(PreCondition pre) : base(pre) { MinItems = int.MaxValue; MaxItems = int.MinValue; MinBasketPrice = int.MaxValue; MaxBasketPrice = int.MinValue; }
public void TestCleanUp1() { Dictionary dictionary = CreateDictionary("Test"); NameSpace nameSpace1 = CreateNameSpace(dictionary, "N1"); NameSpace nameSpace2 = CreateNameSpace(nameSpace1, "N2"); Enum enumeration = CreateEnum(nameSpace2, "Mode"); CreateEnumValue(enumeration, "E1"); CreateEnumValue(enumeration, "E2"); Variable variable1 = CreateVariable(nameSpace1, "V", "N1.N2.Mode"); variable1.Default = "N1.N2.Mode.E1"; RuleCondition ruleCondition = CreateRuleAndCondition(nameSpace1, "Test"); PreCondition preCondition = CreatePreCondition(ruleCondition, "V == N1.N2.Mode.E1"); Action action = CreateAction(ruleCondition, "V <- N1.N2.Mode.E2"); Variable variable2 = CreateVariable(nameSpace2, "V2", "Mode"); variable2.Default = "N1.N2.Mode.E1"; CleanUpModel(); Assert.AreEqual("V == N2.Mode.E1", preCondition.ExpressionText); Assert.AreEqual("V <- N2.Mode.E2", action.ExpressionText); Assert.AreEqual("N2.Mode.E1", variable1.Default); Assert.AreEqual("Mode.E1", variable2.Default); }
public void TestRefactorNameSpaceName3() { Dictionary test = CreateDictionary("Test"); NameSpace n0 = CreateNameSpace(test, "N0"); NameSpace n1 = CreateNameSpace(n0, "N1"); Structure s1 = CreateStructure(n1, "S1"); StructureElement el1 = CreateStructureElement(s1, "E1", "Boolean"); Structure s2 = CreateStructure(n1, "S2"); StructureElement el2 = CreateStructureElement(s2, "E2", "S1"); Variable v = CreateVariable(n1, "V", "S1"); v.setDefaultValue("S1 { E1 => True }"); Function f = CreateFunction(n1, "f", "S2"); NameSpace n2 = CreateNameSpace(n0, "N2"); RuleCondition rc = CreateRuleAndCondition(n2, "Rule1"); PreCondition p = CreatePreCondition(rc, "N1.f().E2.E1"); Action a = CreateAction(rc, "N1.V <- N1.S1 { E1 => False }"); Refactor(n1, "NewN1"); Assert.AreEqual("S1 { E1 => True }", v.getDefaultValue()); Assert.AreEqual("NewN1.V <- NewN1.S1 { E1 => False }", a.ExpressionText); Assert.AreEqual("NewN1.f().E2.E1", p.ExpressionText); RefactorAndRelocate(p); Assert.AreEqual("NewN1.f().E2.E1", p.ExpressionText); }
public void LeaveChat(string playerToken) { PreCondition.AssertNotNullOrEmpty(playerToken, "playerToken"); var chat = GetAndCheckChat(playerToken); chat.RemovePlayer(playerToken); }
public void DoStuff(IEnumerable <T> collection) { PreCondition.NotIsOrHasNull(collection); foreach (var x in collection) { //Stuff } }
/// <summary> /// Duplicates this model element /// </summary> /// <returns></returns> public PreCondition duplicate() { PreCondition retVal = (PreCondition)Generated.acceptor.getFactory().createPreCondition(); retVal.Name = Name; retVal.ExpressionText = ExpressionText; return(retVal); }
private PkgdefTextSegment(int startIndex, string text, PkgdefSegmentType segmentType) { PreCondition.AssertGreaterThanOrEqualTo(startIndex, 0, nameof(startIndex)); PreCondition.AssertNotNullAndNotEmpty(text, nameof(text)); this.startIndex = startIndex; this.text = text; this.segmentType = segmentType; }
public void WriteLine(string playerToken, string text) { PreCondition.AssertNotNullOrEmpty(playerToken, "playerToken"); PreCondition.AssertNotNullOrEmpty(text, "text"); var chat = GetAndCheckChat(playerToken); chat.AddLine(playerToken, text); }
public void JoinChat(string playerToken, string chatId, string userName) { PreCondition.AssertNotNullOrEmpty(playerToken, "playerToken"); PreCondition.AssertNotNullOrEmpty(chatId, "chatId"); PreCondition.AssertNotNullOrEmpty(userName, "userName"); SetName(playerToken, userName); GetChat(chatId).AddPlayer(GetPlayer(playerToken)); }
public override bool IsEligiblePurchase(PurchaseBasket basket) { if (PreCondition.preCondNumber == CommonStr.PurchasePreCondition.OwnerCantBuy) { return(PreCondition.IsFulfilledOwnerCantBuyPurchase(basket.User, basket.Store.Id)); } else { return(false); } }
public override bool IsEligiblePurchase(PurchaseBasket basket) { if (PreCondition.preCondNumber == CommonStr.PurchasePreCondition.StoreMustBeActive) { return(PreCondition.IsFulfilledStoreMustBeActivePurchase(StoreId)); } else { return(false); } }
public List <ChatLine> GetLinesFrom(string playerToken) { PreCondition.AssertNotNullOrEmpty(playerToken, "playerToken"); var chat = GetAndCheckChat(playerToken); var player = chat.GetPlayer(playerToken); var list = chat.ChatLines.Where(x => x.Tick > player.Tick).ToList(); player.Tick = chat.ChatLines.Last().Tick; return(list); }
public string CreatePlayer(string playername, string password) { PreCondition.AssertNotNullOrEmpty(playername, "playername"); PreCondition.AssertNotNullOrEmpty(password, "password"); var player = RegisteredPlayers.FirstOrDefault(x => x.PlayerName == playername); if (player == null) { player = new Player(playername, password, Guid.NewGuid().ToString()); RegisteredPlayers.Add(player); } return(player.Id); }
public override bool IsEligiblePurchase(PurchaseBasket basket) { if (PreCondition.preCondNumber == CommonStr.PurchasePreCondition.MinUnitsOfProductType) { return(PreCondition.IsFulfilledMinUnitsOfProductTypePurchase(basket, ProductId, MinAmount)); } else if (PreCondition.preCondNumber == CommonStr.PurchasePreCondition.MaxUnitsOfProductType) { return(PreCondition.IsFulfilledMaxUnitsOfProductPurchase(basket, ProductId, MaxAmount)); } else { return(false); } }
public string CreateChannel(string playerToken, string channelName) { PreCondition.AssertNotNullOrEmpty(channelName, "channelName"); PreCondition.AssertNotNullOrEmpty(playerToken, "playerToken"); CheckPlayerToken(playerToken); var chat = ChatLobby.FirstOrDefault(x => x.Name == channelName);; if (chat == null) { chat = new Chat(channelName); ChatLobby.Add(chat); } return(chat.Id); }
public void TestEnclosing() { Dictionary dictionary = CreateDictionary("Test"); NameSpace nameSpace = CreateNameSpace(dictionary, "N1"); Structure structure = CreateStructure(nameSpace, "S"); StructureElement element = CreateStructureElement(structure, "E", "Integer"); StateMachine stateMachine = CreateStateMachine(structure, "SM"); RuleCondition condition = CreateRuleAndCondition(stateMachine, "Cond"); PreCondition preCondition = CreatePreCondition(condition, "ENCLOSING.E == 0"); RuleCheckerVisitor visitor = new RuleCheckerVisitor(dictionary); visitor.visit(nameSpace); Assert.Null(ErrorMessage(preCondition)); }
/// <summary> /// Handles a drop event /// </summary> /// <param name="sourceNode"></param> public override void AcceptDrop(BaseTreeNode sourceNode) { PreConditionTreeNode preConditionTreeNode = sourceNode as PreConditionTreeNode; if (preConditionTreeNode != null) { if ( MessageBox.Show("Are you sure you want to move the corresponding pre-condition ?", "Move pre-condition", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { PreCondition preCondition = preConditionTreeNode.Item; preConditionTreeNode.Delete(); Item.appendPreConditions(preCondition); Item.setVerified(false); } } }
public override double CalcDiscount(PurchaseBasket basket) { if (PreCondition.preCondNumber == CommonStr.DiscountPreConditions.BasketProductPriceAboveEqX) { double reduction = 0; foreach (int pid in basket.Products.Keys) { if (PreCondition.IsFulfilledProductPriceAboveEqXDiscount(basket, pid, MinProductPrice)) { int amount = basket.products[pid]; reduction += (Discount / 100) * basket.Store.GetProductDetails(pid).Item1.Price *amount; } } return(reduction); } else if (PreCondition.PreConditionNumber == CommonStr.DiscountPreConditions.NoDiscount) { return(0); } else if (PreCondition.PreConditionNumber == CommonStr.DiscountPreConditions.BasketPriceAboveX) { if (PreCondition.IsFulfilledMinBasketPriceDiscount(basket, MinBasketPrice)) { return((Discount / 100) * basket.GetBasketOrigPrice()); } else { return(0); } } else if (PreCondition.preCondNumber == CommonStr.DiscountPreConditions.NumUnitsInBasketAboveEqX) { if (PreCondition.IsFulfilledMinUnitsAtBasketDiscount(basket, MinUnitsAtBasket)) { return((Discount / 100) * basket.GetBasketOrigPrice()); } else { return(0); } } else { return(0); } }
public override double CalcDiscount(PurchaseBasket basket) { if (PreCondition.preCondNumber == CommonStr.DiscountPreConditions.NumUnitsOfProductAboveEqX) { double reduction = 0; if (PreCondition.IsFufillledMinProductUnitDiscount(basket, discountProdutId, MinUnits)) { int amount = basket.Products[discountProdutId]; reduction = (Discount / 100) * basket.Store.GetProductDetails(discountProdutId).Item1.Price *amount; } return(reduction); } else { return(0); } }
public RoutineDeclaration( Identifier name, bool isForeign, IEnumerable <Parameter> parameters, UnitRef returnType, IEnumerable <Entity> body, PreCondition preCondition = null, PostCondition postCondition = null ) : base(name) { IsForeign = isForeign; Parameters.AddRange(parameters); ReturnType = returnType; Body.AddRange(body); PreCondition = preCondition ?? new PreCondition(); PostCondition = postCondition ?? new PostCondition(); }
public void TestParameterTypeName_RelativePath() { Dictionary dictionary = CreateDictionary("Test"); NameSpace nameSpace = CreateNameSpace(dictionary, "N1"); NameSpace subNameSpace = CreateNameSpace(nameSpace, "N2"); Enum enumeration = CreateEnum(subNameSpace, "Enum"); EnumValue value1 = CreateEnumValue(enumeration, "First"); EnumValue value2 = CreateEnumValue(enumeration, "Second"); Function function = CreateFunction(nameSpace, "F1", "Boolean"); Parameter param = new Parameter(); param.setTypeName("N2.Enum"); param.setName("Value"); function.appendParameters(param); Case cas1 = CreateCase(function, "Case 1", "True", "Value == N2.Enum.First"); Case cas2 = CreateCase(function, "Case 2", "False"); Dictionary dictionary2 = CreateDictionary("TestUpdate"); dictionary2.setUpdates(dictionary.Guid); Function updatedFunction = function.CreateFunctionUpdate(dictionary2); Case cas3 = (Case)updatedFunction.Cases[0]; PreCondition preCondition = (PreCondition)cas3.PreConditions[0]; preCondition.ExpressionText = "Value == N2.Enum.Second"; Compiler.Compile_Synchronous(true); RuleCheckerVisitor ruleChecker = new RuleCheckerVisitor(dictionary2); ruleChecker.visit(updatedFunction); Assert.IsNull(ErrorMessage(updatedFunction)); Expression expression = new Parser().Expression(dictionary, "N1.F1(N1.N2.Enum.Second)"); IValue value = expression.GetExpressionValue(new InterpretationContext(), null); Assert.AreEqual(System.BoolType.True, value); }
public void DoClick() { if (PreCondition != null && !PreCondition.Invoke()) { return; } // Perform custom action if set ClickAction?.Invoke(); // Perform transition if (back) { parentScreen.GoBack(); } else { parentScreen.GoToScreen(nextScreen); } }
public void TestUpdateBranchingNameSpaces() { Dictionary dictionary = CreateDictionary("Test"); NameSpace nameSpace = CreateNameSpace(dictionary, "N"); NameSpace nameSpace1 = CreateNameSpace(nameSpace, "N1"); NameSpace nameSpace2 = CreateNameSpace(nameSpace, "N2"); Function function1 = CreateFunction(nameSpace1, "f", "Bool"); Case cas1 = CreateCase(function1, "Case 1", "N2.q()"); Function function2 = CreateFunction(nameSpace2, "q", "Bool"); Case cas2 = CreateCase(function2, "Case 1", "True"); Dictionary dictionary2 = CreateDictionary("TestUpdate"); dictionary2.setUpdates(dictionary.Guid); Function updateFunction1 = function1.CreateFunctionUpdate(dictionary2); updateFunction1.TypeName = "Integer"; Case updcas1 = (Case)updateFunction1.Cases[0]; updcas1.ExpressionText = "2"; PreCondition precond = CreatePreCondition(updcas1, "N2.q()"); Case newCase = CreateCase(updateFunction1, "Case 2", "1"); Function updateFunction2 = function2.CreateFunctionUpdate(dictionary2); ((Case)updateFunction2.Cases[0]).ExpressionText = "False"; Compiler.Compile_Synchronous(true); Expression expression = new Parser().Expression(dictionary, "N.N1.f()"); IValue value = expression.GetExpressionValue(new InterpretationContext(), null); IValue refVal = new IntValue(System.IntegerType, 1); Assert.AreEqual(refVal.LiteralName, value.LiteralName); }
public override bool IsEligiblePurchase(PurchaseBasket basket) { if (PreCondition.PreConditionNumber == CommonStr.PurchasePreCondition.allwaysTrue) { return(true); } else if (PreCondition.PreConditionNumber == CommonStr.PurchasePreCondition.MaxItemsAtBasket) { return(PreCondition.IsFulfilledMaxItemAtBasketPurchase(basket, MaxItems)); } else if (PreCondition.preCondNumber == CommonStr.PurchasePreCondition.MinItemsAtBasket) { return(PreCondition.IsFulfilledMinItemAtBasketPurchase(basket, MinItems)); } else if (PreCondition.PreConditionNumber == CommonStr.PurchasePreCondition.MinBasketPrice) { return(PreCondition.IsFulfilledMinBasketPricePurchase(basket, MinBasketPrice)); } else if (PreCondition.PreConditionNumber == CommonStr.PurchasePreCondition.MaxBasketPrice) { return(PreCondition.IsFulfilledMaxBasketPricePurchase(basket, MaxBasketPrice)); } return(false); }
/// <summary> /// Constructor /// </summary> /// <param name="panel"></param> /// <param name="model"></param> public PreConditionModelControl(ModelDiagramPanel panel, PreCondition model) : base(panel, model) { }
public void AddHandler(object sender, EventArgs args) { Item.appendPreConditions(PreCondition.CreateDefault(Item.PreConditions)); }
public override string ToString() { var text = null == FullCondition?PreCondition.ToString() : FullCondition.ToString(); return("WHEN " + text + " " + Effects.ToSeparatorList()); }