public void GlobalVariables() { var compiler = new VisualBasicViewCompiler { BaseClass = "Spark.AbstractSparkView" }; DoCompileView(compiler, new Chunk[] { new SendExpressionChunk { Code = "title" }, new AssignVariableChunk { Name = "item", Value = "8" }, new SendLiteralChunk { Text = ":" }, new SendExpressionChunk { Code = "item" }, new GlobalVariableChunk { Name = "title", Value = "\"hello world\"" }, new GlobalVariableChunk { Name = "item", Value = "3" } }); var instance = compiler.CreateInstance(); var contents = instance.RenderView(); Assert.AreEqual("hello world:8", contents); }
public void UnlessFalseCondition() { var compiler = new VisualBasicViewCompiler { BaseClass = "Spark.AbstractSparkView" }; var trueChunks = new Chunk[] { new SendLiteralChunk { Text = "wastrue" } }; DoCompileView(compiler, new Chunk[] { new SendLiteralChunk { Text = "<p>" }, new LocalVariableChunk { Name = "arg", Value = "5" }, new ConditionalChunk { Type = ConditionalType.Unless, Condition = "arg=6", Body = trueChunks }, new SendLiteralChunk { Text = "</p>" } }); var instance = compiler.CreateInstance(); var contents = instance.RenderView(); Assert.AreEqual("<p>wastrue</p>", contents); }
public void ForEachAutoVariables() { var compiler = new VisualBasicViewCompiler { BaseClass = "Spark.AbstractSparkView" }; DoCompileView(compiler, new Chunk[] { new LocalVariableChunk { Name = "data", Value = "new Integer(){3,4,5}" }, new SendLiteralChunk { Text = "<ul>" }, new ForEachChunk { Code = "item As Integer in data", Body = new Chunk[] { new SendLiteralChunk { Text = "<li>" }, new SendExpressionChunk { Code = "item" }, new SendExpressionChunk { Code = "itemIsFirst" }, new SendExpressionChunk { Code = "itemIsLast" }, new SendExpressionChunk { Code = "itemIndex" }, new SendExpressionChunk { Code = "itemCount" }, new SendLiteralChunk { Text = "</li>" } } }, new SendLiteralChunk { Text = "</ul>" } }); var instance = compiler.CreateInstance(); var contents = instance.RenderView(); Assert.AreEqual("<ul><li>3TrueFalse03</li><li>4FalseFalse13</li><li>5FalseTrue23</li></ul>", contents); }
public void SimpleOutput() { var compiler = new VisualBasicViewCompiler { BaseClass = "Spark.AbstractSparkView" }; DoCompileView(compiler, new[] { new SendExpressionChunk { Code = "3 + 4" } }); var instance = compiler.CreateInstance(); string contents = instance.RenderView(); Assert.AreEqual("7", contents); }
public void TargetNamespace() { var compiler = new VisualBasicViewCompiler { BaseClass = "Spark.AbstractSparkView", Descriptor = new SparkViewDescriptor { TargetNamespace = "Testing.Target.Namespace" } }; DoCompileView(compiler, new Chunk[] { new SendLiteralChunk { Text = "Hello" } }); var instance = compiler.CreateInstance(); Assert.AreEqual("Testing.Target.Namespace", instance.GetType().Namespace); }
public void LocalVariableDecl() { var compiler = new VisualBasicViewCompiler { BaseClass = "Spark.AbstractSparkView" }; DoCompileView(compiler, new Chunk[] { new LocalVariableChunk { Name = "i", Value = "5" }, new SendExpressionChunk { Code = "i" } }); var instance = compiler.CreateInstance(); string contents = instance.RenderView(); Assert.AreEqual("5", contents); }
public void StronglyTypedBase() { var compiler = new VisualBasicViewCompiler { BaseClass = "Spark.Tests.Stubs.StubSparkView" }; DoCompileView(compiler, new Chunk[] { new SendLiteralChunk { Text = "hello world" }, new ViewDataModelChunk { TModel = "Global.System.String" } }); var instance = compiler.CreateInstance(); string contents = instance.RenderView(); Assert.That(contents.Contains("hello world")); }
public void ForEachLoop() { var compiler = new VisualBasicViewCompiler { BaseClass = "Spark.AbstractSparkView" }; DoCompileView(compiler, new Chunk[] { new LocalVariableChunk { Name = "data", Value = "new Integer(){3,4,5}" }, new SendLiteralChunk { Text = "<ul>" }, new ForEachChunk { Code = "item in data", Body = new Chunk[] { new SendLiteralChunk { Text = "<li>" }, new SendExpressionChunk { Code = "item" }, new SendLiteralChunk { Text = "</li>" } } }, new SendLiteralChunk { Text = "</ul>" } }); var instance = compiler.CreateInstance(); var contents = instance.RenderView(); Assert.AreEqual("<ul><li>3</li><li>4</li><li>5</li></ul>", contents); }