public bool ItExecutesStatements(string code, User data) { var execution = DaisyCompiler.Compile <User>(code, statements).Execute(data); Console.WriteLine(new DaisyTracePrinter(execution.DebugInfo.Trace).Print()); return(execution.Outcome); }
public void ItPreservesAttachments() { var code = @"Set Attachment"; var program = DaisyCompiler.Compile <int>(code, new StatementSet().FromController(typeof(TestStatementController))); var result = program.Execute(4); Assert.AreEqual(5, result.Attachments["Test"]); }
/// <summary> /// Traces the specified code. /// </summary> /// <param name="code">The code.</param> /// <returns></returns> public TraceNode Trace(string code) { var statements = new StatementSet().FromAssemblyOf(typeof(UserController)); var program = DaisyCompiler.Compile <User>(code, statements); var result = program.Execute(TestData.Ben); Assert.IsNotNull(result.DebugInfo.Trace); return(result.DebugInfo.Trace); }
public void ItDoesNotAllowNongroupingStatementsToBeUsedAsGroups() { var code = @"Is greater than 2 Is greater than 10 "; var exp = Assert.Throws <FailedLinkException>(() => DaisyCompiler.Compile <int>(code, new StatementSet().FromController(typeof(TestStatementController)))); Assert.AreEqual(1, exp.Errors.Count); var err = exp.Errors.First(); Assert.IsInstanceOf <NoLinksPermittedError>(err); }
public void ItMonitorsPerformance() { var program = DaisyCompiler.Compile <User>(Statements.UserHasUnusedAccount, set); var result = program.Execute(TestData.Ben); Console.WriteLine(result.DebugInfo.DebugView); Assert.IsTrue(result.Outcome); Assert.IsNotNull(result.DebugInfo.Measurments); Assert.GreaterOrEqual(result.DebugInfo.Measurments.OpsExecuted, 7); Assert.GreaterOrEqual(result.DebugInfo.Measurments.TotalStatementsExecuted, 4); Assert.Greater(result.DebugInfo.Measurments.OpsExecuted, result.DebugInfo.Measurments.TotalStatementsExecuted); Assert.GreaterOrEqual(result.DebugInfo.Measurments.ExecutionTime, 0); Assert.Less(result.DebugInfo.Measurments.ExecutionTime, 10); }
public void ItExecutesPerformantly() { var code = Component.Statements.UserHasNoRecentTransactions; var statements = new StatementSet().FromAssemblyOf <UserController>(); var pgrm = DaisyCompiler.Compile <User>(code, statements); var stopwatch = new Stopwatch(); var iterations = 50000; stopwatch.Start(); for (int i = 0; i < iterations; ++i) { pgrm.Execute(Component.TestData.Ben); } stopwatch.Stop(); Console.WriteLine("Elapsed: " + stopwatch.ElapsedMilliseconds); Console.WriteLine("Per execution: " + ((double)stopwatch.ElapsedMilliseconds) / iterations); Assert.Less(stopwatch.ElapsedMilliseconds, 30000); }
public bool ItExecutesStatements(string code, User data) { var exec = DaisyCompiler.Compile <User>(code, statements).Execute(data); return(exec.Outcome); }
static void Main(string[] args) { var iterations = 5000000; var code = Tests.Daisy.Component.Statements.UserHasNoRecentTransactions; var stopwatch = new Stopwatch(); var statements = new StatementSet() .Add(new HasAccountSilverBulletStatement()) .Add(new HasTransactionSilverBulletStatement()) .Add(new IsActiveSilverBulletStatement()) .Add(new TimestampBeforeSilverBulletStatement()) ; var pgrm = DaisyCompiler.Compile <User>(code, statements); Console.WriteLine("Setup: " + stopwatch.ElapsedMilliseconds); stopwatch = new Stopwatch(); Console.WriteLine("Running Daisy with silver bullet..."); stopwatch.Start(); for (int i = 0; i < iterations; ++i) { pgrm.Execute(Tests.Daisy.Component.TestData.Ben); } stopwatch.Stop(); Console.WriteLine("Elapsed: " + stopwatch.ElapsedMilliseconds); Console.WriteLine("Per execution: " + ((double)stopwatch.ElapsedMilliseconds) / iterations); statements = new StatementSet() .FromController(typeof(UserController)) .FromController(typeof(TransactionController)) .FromController(typeof(AccountController)) ; pgrm = DaisyCompiler.Compile <User>(code, statements); Console.WriteLine("Running Daisy with reflection..."); GC.Collect(); GC.WaitForFullGCComplete(); stopwatch = new Stopwatch(); stopwatch.Start(); for (int i = 0; i < iterations; ++i) { pgrm.Execute(Tests.Daisy.Component.TestData.Ben); } stopwatch.Stop(); Console.WriteLine("Elapsed: " + stopwatch.ElapsedMilliseconds); Console.WriteLine("Per execution: " + ((double)stopwatch.ElapsedMilliseconds) / iterations); GC.Collect(); GC.WaitForFullGCComplete(); Console.WriteLine("Running raw iterations..."); stopwatch = new Stopwatch(); stopwatch.Start(); for (int i = 0; i < iterations; ++i) { var data = Tests.Daisy.Component.TestData.Ben; var result = data.IsActive && !data.Accounts.Any(account => account.Transactions.Any(transaction => DateTime.Now.AddYears(-1) > transaction.Timestamp ) ); } stopwatch.Stop(); Console.WriteLine("Elapsed: " + stopwatch.ElapsedMilliseconds); Console.WriteLine("Per execution: " + ((double)stopwatch.ElapsedMilliseconds) / iterations); Console.WriteLine("Running iterations from handlers..."); stopwatch = new Stopwatch(); stopwatch.Start(); var context = new ContextBundle(); var attachments = new ContextBundle(); var tracer = new Tracer(); for (int i = 0; i < iterations; ++i) { var data = Tests.Daisy.Component.TestData.Ben; var result = new UserController() { Scope = data, Context = context, Attachments = attachments, Tracer = tracer }.IsActive() && !new UserController() { Scope = data, Context = context, Attachments = attachments, Tracer = tracer }.HasAccount(account => new AccountController() { Scope = account, Context = context, Attachments = attachments, Tracer = tracer }.HasTransaction( transaction => new TransactionController() { Scope = transaction, Context = context, Attachments = attachments, Tracer = tracer }.TimestampBeforeYearsAgo(1) ) ); } stopwatch.Stop(); Console.WriteLine("Elapsed: " + stopwatch.ElapsedMilliseconds); Console.WriteLine("Per execution: " + ((double)stopwatch.ElapsedMilliseconds) / iterations); Console.ReadKey(); }