public void VoidReturningCodeSnippet_Success() { using (var expression = new CSharpScript()) { Assert.AreEqual(0, expression.AddVoidReturnCodeSnippet("var i = 1; Console.WriteLine(i)")); Assert.AreEqual(null, expression.Execute()); } }
public void ExpressionUsingGlobalToKeepStateAcrossExecutions_Success() { using (var expression = new CSharpScript()) { Assert.AreEqual(0, expression.AddVoidReturnCodeSnippet("global.a = 0")); Assert.AreEqual(1, expression.AddExpression("global.a++")); Assert.AreEqual(null, expression.Execute()); // setup the global, runs first expression Assert.AreEqual(0, expression.Execute(1)); Assert.AreEqual(1, expression.Execute(1)); } }
public void ExpressionUsingGlobalPerformance_Success() { using (var expression = new CSharpScript()) { Assert.AreEqual(0, expression.AddVoidReturnCodeSnippet("global.a = 0")); Assert.AreEqual(1, expression.AddExpression("global.a++")); Assert.AreEqual(null, expression.Execute()); // setup the global var initialTicks = Environment.TickCount; for (uint i = 0; i < 1000000; i++) { Assert.AreEqual(i, expression.Execute(1)); } Assert.Less(Environment.TickCount - initialTicks, 2000); // 1 million executions in less than 2 seconds } }