public void ItAddsFromAssembly() { var load = new StatementSet(); load.FromAssemblyOf(typeof(StatementSetTests)); Assert.That(load.Statements.OfType <ReflectionStatementDefinition>().Any(x => x.Name == "R1")); }
public void ItDiesOnMultipleLinksFound() { var linkedStatement1 = new Mock <ILinkedStatement>(); var statement = new Mock <IStatementDefinition>(); linkedStatement1.SetupGet(x => x.Definition).Returns(statement.Object); statement.Setup(x => x.Link(It.IsAny <string>())).Returns(linkedStatement1.Object); statement.SetupGet(x => x.Name).Returns("David"); statement.SetupGet(x => x.ScopeType).Returns(typeof(int)); var linkedStatement2 = new Mock <ILinkedStatement>(); var statement2 = new Mock <IStatementDefinition>(); linkedStatement2.SetupGet(x => x.Definition).Returns(statement2.Object); statement2.Setup(x => x.Link(It.IsAny <string>())).Returns(linkedStatement2.Object); statement2.SetupGet(x => x.Name).Returns("Tennant"); statement2.SetupGet(x => x.ScopeType).Returns(typeof(int)); var statementSet = new StatementSet().Add(statement.Object).Add(statement2.Object); var ast = new DaisyAst(new StatementNode("Hello gov'nor")); var load = new DaisyLinker(ast, statementSet, typeof(int)); var ex = Assert.Catch <FailedLinkException>(() => load.Link()); Assert.AreEqual(1, ex.Errors.Count); Assert.IsInstanceOf <MultipleLinksFoundError>(ex.Errors.First()); }
public void ItAddsFromType() { var load = new StatementSet(); load.FromController(typeof(MyStatement)); Assert.That(load.Statements.OfType <ReflectionStatementDefinition>().Any(x => x.Name == "R1")); }
public static DaisyProgram <T> Compile <T>(string code, StatementSet statements, DaisyMode mode = DaisyMode.Debug) { var ast = DaisyParser.Parse(code); var linker = new DaisyLinker(ast, statements, typeof(T)); linker.Link(); return(new DaisyProgram <T>(ast, mode)); }
public DaisyLinker(DaisyAst ast, StatementSet statements, Type rootType) { RootScopeType = rootType; this.ast = ast; this.statements = statements; #if DEBUG this.statementsAsString = statements.Statements.Select(s => s.Name).ToList(); #endif }
public void ItDiesOnFailureToLink() { var statementSet = new StatementSet(); var ast = new DaisyAst(new StatementNode("Hello gov'nor")); var load = new DaisyLinker(ast,statementSet,typeof(int)); var ex = Assert.Catch<FailedLinkException>(() => load.Link()); Assert.AreEqual(1, ex.Errors.Count); Assert.IsInstanceOf<NoLinksFoundError>(ex.Errors.First()); }
public void ItDiesOnFailureToLink() { var statementSet = new StatementSet(); var ast = new DaisyAst(new StatementNode("Hello gov'nor")); var load = new DaisyLinker(ast, statementSet, typeof(int)); var ex = Assert.Catch <FailedLinkException>(() => load.Link()); Assert.AreEqual(1, ex.Errors.Count); Assert.IsInstanceOf <NoLinksFoundError>(ex.Errors.First()); }
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; }
/// <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 ItLinksStatements() { var linkedStatement = new Mock <ILinkedStatement>(); var statement = new Mock <IStatementDefinition>(); statement.Setup(x => x.Link(It.IsAny <string>())).Returns(linkedStatement.Object); statement.SetupGet(x => x.Name).Returns("Tennant"); statement.SetupGet(x => x.ScopeType).Returns(typeof(Int32)); var statementSet = new StatementSet().Add(statement.Object); var ast = new DaisyAst(new StatementNode("Hello gov'nor")); var load = new DaisyLinker(ast, statementSet, typeof(int)); load.Link(); statement.Verify(x => x.Link(It.IsAny <string>()), Times.Once()); }
public void ItDiesOnLinkingGroupToNonGroup() { var linkedStatement1 = new Mock<ILinkedStatement>(); var statement = new Mock<IStatementDefinition>(); linkedStatement1.SetupGet(x => x.Definition).Returns(statement.Object); statement.Setup(x => x.Link(It.IsAny<string>())).Returns(linkedStatement1.Object); statement.SetupGet(x => x.Name).Returns("David"); statement.SetupGet(x => x.ScopeType).Returns(typeof(int)); statement.SetupGet(x => x.TransformsScopeTo).Returns((Type)null); var statementSet = new StatementSet().Add(statement.Object); var ast = new DaisyAst(new GroupOperatorNode("Hello gov'nor",new StatementNode("Blah"))); var load = new DaisyLinker(ast,statementSet,typeof(int)); var ex = Assert.Catch<FailedLinkException>(() => load.Link()); Assert.AreEqual(1, ex.Errors.Count); Assert.IsInstanceOf<NoLinksPermittedError>(ex.Errors.First()); }
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 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 void ItDiesOnLinkingGroupToNonGroup() { var linkedStatement1 = new Mock <ILinkedStatement>(); var statement = new Mock <IStatementDefinition>(); linkedStatement1.SetupGet(x => x.Definition).Returns(statement.Object); statement.Setup(x => x.Link(It.IsAny <string>())).Returns(linkedStatement1.Object); statement.SetupGet(x => x.Name).Returns("David"); statement.SetupGet(x => x.ScopeType).Returns(typeof(int)); statement.SetupGet(x => x.TransformsScopeTo).Returns((Type)null); var statementSet = new StatementSet().Add(statement.Object); var ast = new DaisyAst(new GroupOperatorNode("Hello gov'nor", new StatementNode("Blah"))); var load = new DaisyLinker(ast, statementSet, typeof(int)); var ex = Assert.Catch <FailedLinkException>(() => load.Link()); Assert.AreEqual(1, ex.Errors.Count); Assert.IsInstanceOf <NoLinksPermittedError>(ex.Errors.First()); }
public void ItDiesOnMultipleLinksFound() { var linkedStatement1 = new Mock<ILinkedStatement>(); var statement = new Mock<IStatementDefinition>(); linkedStatement1.SetupGet(x => x.Definition).Returns(statement.Object); statement.Setup(x => x.Link(It.IsAny<string>())).Returns(linkedStatement1.Object); statement.SetupGet(x => x.Name).Returns("David"); statement.SetupGet(x => x.ScopeType).Returns(typeof(int)); var linkedStatement2 = new Mock<ILinkedStatement>(); var statement2 = new Mock<IStatementDefinition>(); linkedStatement2.SetupGet(x => x.Definition).Returns(statement2.Object); statement2.Setup(x => x.Link(It.IsAny<string>())).Returns(linkedStatement2.Object); statement2.SetupGet(x => x.Name).Returns("Tennant"); statement2.SetupGet(x => x.ScopeType).Returns(typeof(int)); var statementSet = new StatementSet().Add(statement.Object).Add(statement2.Object); var ast = new DaisyAst(new StatementNode("Hello gov'nor")); var load = new DaisyLinker(ast,statementSet,typeof(int)); var ex = Assert.Catch<FailedLinkException>(() => load.Link()); Assert.AreEqual(1, ex.Errors.Count); Assert.IsInstanceOf<MultipleLinksFoundError>(ex.Errors.First()); }
public void Setup() { statements = new StatementSet().FromAssemblyOf(typeof(UserController)); }
public void ItLinksStatements() { var linkedStatement = new Mock<ILinkedStatement>(); var statement = new Mock<IStatementDefinition>(); statement.Setup(x => x.Link(It.IsAny<string>())).Returns(linkedStatement.Object); statement.SetupGet(x => x.Name).Returns("Tennant"); statement.SetupGet(x => x.ScopeType).Returns(typeof(Int32)); var statementSet = new StatementSet().Add(statement.Object); var ast = new DaisyAst(new StatementNode("Hello gov'nor")); var load = new DaisyLinker(ast,statementSet,typeof(int)); load.Link(); statement.Verify(x => x.Link(It.IsAny<string>()), Times.Once()); }
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(); }
public DocumentationSet(StatementSet statements, ICommentDocumentation commentDocumentation) { this.statements = statements; this.commentDocumentation = commentDocumentation; }
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(); }