Ejemplo n.º 1
0
		public void WriteCode(ITemplate tpl, FragmentCodePoint point, CodeBuilder cb) {
			if (!string.IsNullOrEmpty(code))
				cb.AppendLine(code);
			for (int i = 0; i < indentEffect; i++)
				cb.Indent();
			for (int i = 0; i < -indentEffect; i++)
				cb.Outdent();
		}
		private void TestWriteCode_Works(FragmentCodePoint point) {
			var tpl = mocks.StrictMock<ITemplate>();
			mocks.ReplayAll();
			CodeBuilder cb = new CodeBuilder();
			new CodeExpressionFragment("[Some code]").WriteCode(tpl, point, cb);
			Assert.AreEqual("sb.Append([Some code]);" + Environment.NewLine, cb.ToString());
			Assert.AreEqual(0, cb.IndentLevel);
			mocks.VerifyAll();
		}
Ejemplo n.º 3
0
		private void TestWriteCode_CDataWorks(FragmentCodePoint point) {
			var tpl = mocks.StrictMock<ITemplate>();
			mocks.ReplayAll();
			CodeBuilder cb = new CodeBuilder();
			new LiteralFragment(" Test  \"fragment\"  ", true).WriteCode(tpl, point, cb);
			Assert.AreEqual("sb.Append(@\"<![CDATA[ Test  \"\"fragment\"\"  ]]>\");" + Environment.NewLine, cb.ToString());
			Assert.AreEqual(0, cb.IndentLevel);
			mocks.VerifyAll();
		}
		private void TestWriteCode_NoChildrenWorks(FragmentCodePoint point) {
			var tpl = mocks.StrictMock<ITemplate>();
			mocks.ReplayAll();
			CodeBuilder cb = new CodeBuilder();
			new InstantiatedControlFragment("CtlId", false, 0).WriteCode(tpl, point, cb);
			Assert.AreEqual("sb.Append(((IControl)CtlId).Html);" + Environment.NewLine, cb.ToString());
			Assert.AreEqual(0, cb.IndentLevel);
			mocks.VerifyAll();
		}
Ejemplo n.º 5
0
		private void TestWriteCode_Works(FragmentCodePoint point) {
			var tpl = mocks.StrictMock<ITemplate>();
			mocks.ReplayAll();
			CodeBuilder cb = new CodeBuilder();
			new PositionFragment().WriteCode(tpl, point, cb);
			Assert.AreEqual("sb.Append(PositionHelper.CreateStyle(Position, -1, -1));" + Environment.NewLine, cb.ToString());
			Assert.AreEqual(0, cb.IndentLevel);
			mocks.VerifyAll();
		}
		private void TestWriteCode_OneChildWorks(FragmentCodePoint point) {
			var tpl = mocks.StrictMock<ITemplate>();
			mocks.ReplayAll();
			CodeBuilder cb = new CodeBuilder();
			new InstantiatedControlFragment("CtlId", false, 1).WriteCode(tpl, point, cb);
			Assert.AreEqual("((IControlHost)CtlId).SetInnerFragments(new string[] { CtlId_inner1() });" + Environment.NewLine
			              + "sb.Append(((IControl)CtlId).Html);" + Environment.NewLine, cb.ToString());
			Assert.AreEqual(0, cb.IndentLevel);
			mocks.VerifyAll();
		}
		private void TestWriteCode_CustomInstantiateWorks(FragmentCodePoint point) {
			var tpl = mocks.StrictMock<ITemplate>();
			mocks.ReplayAll();
			CodeBuilder cb = new CodeBuilder();
			new InstantiatedControlFragment("CtlId", true, 0).WriteCode(tpl, point, cb);
			Assert.AreEqual("if (CtlId == null) throw new InvalidOperationException(\"The control instance CtlId must be assigned before the control can be rendered.\");" + Environment.NewLine
			              + "sb.Append(((IControl)CtlId).Html);" + Environment.NewLine, cb.ToString());
			Assert.AreEqual(0, cb.IndentLevel);
			mocks.VerifyAll();
		}
		public void WriteCode(ITemplate tpl, FragmentCodePoint point, CodeBuilder cb) {
			if (CustomInstantiate)
				cb.AppendLine("if (" + Id + " == null) throw new InvalidOperationException(\"The control instance " + Id + " must be assigned before the control can be rendered.\");");
			
			if (NumInnerFragments > 0) {
				cb.Append("((IControlHost)" + Id + ").SetInnerFragments(new string[] { ");
				for (int i = 0; i < NumInnerFragments; i++) {
					if (i > 0)
						cb.Append(", ");
					cb.Append(Id + "_inner" + (i + 1).ToString(System.Globalization.CultureInfo.InvariantCulture) + "()");
				}
				cb.AppendLine(" });");
			}

			cb.AppendLine(ParserUtils.RenderFunctionStringBuilderName + ".Append(((IControl)" + Id + ").Html);");
		}
Ejemplo n.º 9
0
		private void TestWriteCode_Works(FragmentCodePoint point) {
			for (int i = -5; i <= 5; i++) {
				var tpl = mocks.StrictMock<ITemplate>();
				mocks.ReplayAll();
			
				CodeBuilder cb = new CodeBuilder();
				for (int x = 0; x < 5; x++)
					cb.Indent();
				new CodeFragment("code", i).WriteCode(tpl, point, cb);
				Assert.AreEqual("\t\t\t\t\tcode" + Environment.NewLine, cb.ToString());
				Assert.AreEqual(5 + i, cb.IndentLevel);
				mocks.VerifyAll();

				tpl = mocks.StrictMock<ITemplate>();
				mocks.ReplayAll();
				cb = new CodeBuilder();
				for (int x = 0; x < 5; x++)
					cb.Indent();
				new CodeFragment(null, i).WriteCode(tpl, point, cb);
				Assert.AreEqual("", cb.ToString());
				Assert.AreEqual(5 + i, cb.IndentLevel);
				mocks.VerifyAll();
			}
		}
Ejemplo n.º 10
0
		public void WriteCode(ITemplate tpl, FragmentCodePoint point, CodeBuilder cb) {
			cb.AppendLine(ParserUtils.RenderFunctionStringBuilderName + ".Append(PositionHelper.CreateStyle(Position, -1, -1));");
		}
Ejemplo n.º 11
0
		public void WriteCode(ITemplate tpl, FragmentCodePoint point, CodeBuilder cb) {
			cb.AppendLine(ParserUtils.RenderFunctionStringBuilderName + ".Append(\"Copyright &copy; \" + Utils.ToStringInvariantInt(this.copyrightYear) + @\" " + text.Replace("\"", "\"\"") + "\");");
		}
Ejemplo n.º 12
0
		public void WriteCode(ITemplate tpl, FragmentCodePoint point, CodeBuilder cb) {
			cb.AppendLine(ParserUtils.RenderFunctionStringBuilderName + ".Append(@\"" + (IsCData ? "<![CDATA[" : "") + Text.Replace("\"", "\"\"") + (IsCData ? "]]>" : "") + "\");");
		}
		public void WriteCode(ITemplate tpl, FragmentCodePoint point, CodeBuilder cb) {
			cb.AppendLine(ParserUtils.RenderFunctionStringBuilderName + ".Append(" + Expression + ");");
		}
Ejemplo n.º 14
0
 public void WriteCode(ITemplate tpl, FragmentCodePoint point, CodeBuilder cb)
 {
     cb.AppendLine(ParserUtils.RenderFunctionStringBuilderName + ".Append(@\"" + (IsCData ? "<![CDATA[" : "") + Text.Replace("\"", "\"\"") + (IsCData ? "]]>" : "") + "\");");
 }
Ejemplo n.º 15
0
 public void WriteCode(ITemplate tpl, FragmentCodePoint point, CodeBuilder cb)
 {
     cb.AppendLine(ParserUtils.RenderFunctionStringBuilderName + ".Append(Id);");
 }