예제 #1
0
        public void IfFalseCondition()
        {
            var compiler = new OxygeneViewCompiler { BaseClass = "Spark.SparkViewBase" };

            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.If, Condition="arg = 6", Body=trueChunks},
                                        new SendLiteralChunk {Text = "</p>"}
                                    });
            var instance = compiler.CreateInstance();
            var contents = instance.RenderView();
            Assert.AreEqual("<p></p>", contents);
        }
예제 #2
0
 public void StrictNullUsesException()
 {
     var compiler = new VisualBasicViewCompiler()
                    {
                        BaseClass = "Spark.Tests.Stubs.StubSparkView",
                        NullBehaviour = NullBehaviour.Strict
                    };
     var chunks = new Chunk[]
                  {
                      new ViewDataChunk { Name="comment", Type="Spark.Tests.Models.Comment"},
                      new SendExpressionChunk {Code = "comment.Text", SilentNulls = false}
                  };
     compiler.CompileView(new[] { chunks }, new[] { chunks });
     Assert.That(compiler.SourceCode.Contains("Catch ex As Global.System.NullReferenceException"));
     Assert.That(compiler.SourceCode.Contains("ArgumentNullException("));
     Assert.That(compiler.SourceCode.Contains(", ex)"));
 }
예제 #3
0
        public void Markdown()
        {
            var compiler = new CSharpViewCompiler { BaseClass = "Spark.SparkViewBase" };

              var innerChunks = new Chunk[] { new SendLiteralChunk { Text = "*test*" } };

              DoCompileView(compiler, new Chunk[]
                                    {
                                        new MarkdownChunk {Body = innerChunks}
                                    });

              Assert.That(compiler.SourceCode, Text.Contains("using(MarkdownOutputScope())"));
              Assert.That(compiler.SourceCode, Text.Contains("Output.Write(\"*test*\");"));

              var instance = compiler.CreateInstance();
              var contents = instance.RenderView().Trim();

              Assert.That(contents, Is.EqualTo("<p><em>test</em></p>"));
        }
예제 #4
0
 public void LenientSilentNullDoesNotCauseWarningCS0168()
 {
     var compiler = new CSharpViewCompiler()
                    {
                        BaseClass = "Spark.Tests.Stubs.StubSparkView",
                        NullBehaviour = NullBehaviour.Lenient
                    };
     var chunks = new Chunk[]
                  {
                      new ViewDataChunk { Name="comment", Type="Spark.Tests.Models.Comment"},
                      new SendExpressionChunk {Code = "comment.Text", SilentNulls = true}
                  };
     compiler.CompileView(new[] { chunks }, new[] { chunks });
     Assert.That(compiler.SourceCode.Contains("catch(System.NullReferenceException)"));
 }
예제 #5
0
        public void UnlessTrueCondition()
        {
            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=5", Body=trueChunks},
                                        new SendLiteralChunk {Text = "</p>"}
                                    });
            var instance = compiler.CreateInstance();
            var contents = instance.RenderView();
            Assert.AreEqual("<p></p>", contents);
        }