Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. asyncTest("BizLogic switch with default case and next operation", function() {
  2.     var logic = new apv.BizLogic();
  3.     logic.variables.push(new apv.Variable({ name: "var1", parameter: true }));
  4.     logic.variables.push(new apv.Variable({ name: "var2", parameter: false }));
  5.     logic.calls = [
  6.         new apv.Switch({
  7.             expr: "test",
  8.             cases: [
  9.                 {
  10.                     value: true,
  11.                     valueType: "boolean",
  12.                     calls: [new apv.Event(apv.Flow.Return, false)]
  13.                 },
  14.                 {
  15.                     value: false,
  16.                     valueType: "boolean",
  17.                     calls: [new apv.Event(apv.Flow.Return, false)]
  18.                 }
  19.             ],
  20.             otherwise: [new apv.SetValue({ variableName: "var2", valueExpr: true })]
  21.         }),
  22.         new apv.Event({ flow: apv.Flow.Return, returnExpr: "var2" })
  23.     ];
  24.     var compiler = new apv.BizLogicCompiler(logic);
  25.     var promise = compiler.run({ test: { name: "test", value: null } });
  26.     promise.done(function(result) {
  27.         equal(result, true);
  28.         start();
  29.     });
  30. });
  31.  
  32. export class BizLogicCompiler {
  33.     private functions: any;
  34.     logic: BizLogic;
  35.  
  36.     constructor(logic: BizLogic, functions?: any) {
  37.         this.functions = functions;
  38.         this.logic = logic;
  39.     }
  40.  
  41.     run(params: { [key: string]: any }): JQueryPromise<any> {
  42.         var variables: { [key: string]: any } = {};
  43.         this.logic.variables.forEach(variable => {
  44.             var value = variable.parameter ? params[variable.name] : variable;
  45.             variables[variable.name] = value;
  46.         });
  47.         return this.logic.run(variables, this.functions);
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement