/// <summary> /// Run the application. /// </summary> public override BoolMessageItem Execute() { // 1. Macro service loads classes with attribute "MacroAttribute" and of type IMacro. var macros = new MacroService(); // 2. Register Option 1: Load macro extensions from dll "CommonLibrary" macros.Load("CommonLibrary"); // 3. Register Option 2: Programmactically with macro attributes. macros.Register(new MacroAttribute() { Name = "helloworld" }, new MacroParameterAttribute[] { new MacroParameterAttribute() { Name = "language" } }, (tag) => "hello world using tag: " + tag.Name + ", " + tag.InnerContent); // 3. Register Option 3: Programmactically with simple api. macros.Register("helloworld2", "", "Simple hello world macro", (tag) => "hello world 2 : "); // 4. Now build the content by processing the macros var content = macros.BuildContent(_macroSampleText1); // 5. Render content that has a lamda based macro in it. // NOTE: Render content that has multiple macros involves the same method call. var content2 = macros.BuildContent(_macroSampleText2); return(BoolMessageItem.True); }
public void CanProcessViaAPI() { var service = new MacroService('$', '[', ']'); // 1. verbose api service.Register(new MacroAttribute() { Name = "helloworld1" }, new MacroParameterAttribute[] { new MacroParameterAttribute() { Name = "language" } }, (tag) => "hello world 1 : " + tag.Name + ", " + tag.InnerContent); // 2. quick api service.Register("helloworld2", "", "Simple hello world macro", (tag) => "hello world 2 : " + tag.InnerContent); var result1 = service.BuildContent(@"testing $[helloworld1 name=""kishore""]commonlibrary.net.cms[/hello]"); var result2 = service.BuildContent(@"testing $[helloworld2 name=""kishore""]commonlibrary.net.cms[/hello]"); Assert.AreEqual(result1, "testing hello world 1 : helloworld1, commonlibrary.net.cms"); Assert.AreEqual(result2, "testing hello world 2 : commonlibrary.net.cms"); }
public void CanProcessViaAPI_Multiple_NonEmptyTag_Attributes_DifferentLocations() { var service = new MacroService('$', '[', ']'); // 1. quick api service.Register("helloworld1", "", "", (tag) => "hello world 1 " + tag.Attributes.Get <string>("saying") + ", " + tag.InnerContent); // 2. quick api service.Register("helloworld2", "", "", (tag) => "hello world 2 " + tag.Attributes.Get <string>("saying") + ", " + tag.InnerContent); // Case 1 - no external content var result = service.BuildContent("$[helloworld1 saying=\"hi\"]inner[/helloworld1] $[helloworld2 saying=\"hi\"]inner[/helloworld2]"); Assert.AreEqual(result, "hello world 1 hi, inner hello world 2 hi, inner"); // Case 2 - content after result = service.BuildContent("$[helloworld1 saying=\"hi\"]inner[/helloworld1] after 1 $[helloworld2 saying=\"hi\"]inner[/helloworld2] after 2"); Assert.AreEqual(result, "hello world 1 hi, inner after 1 hello world 2 hi, inner after 2"); // Case 3 - content before result = service.BuildContent("before 1 $[helloworld1 saying=\"hi\"]inner[/helloworld1] before 2 $[helloworld2 saying=\"hi\"]inner[/helloworld2]"); Assert.AreEqual(result, "before 1 hello world 1 hi, inner before 2 hello world 2 hi, inner"); // Case 4 - content before and after result = service.BuildContent("before 1 $[helloworld1 saying=\"hi\"]inner[/helloworld1] after 1 before 2 $[helloworld2 saying=\"hi\"]inner[/helloworld2] after 2"); Assert.AreEqual(result, "before 1 hello world 1 hi, inner after 1 before 2 hello world 2 hi, inner after 2"); }
public void CanProcessViaAPI_EmptyTag_No_Attributes_DifferentLocations() { var service = new MacroService('$', '[', ']'); // 1. quick api service.Register("helloworld1", "", "", (tag) => "hello world 1"); service.Register("helloworld2", "", "", (tag) => "hello world 2"); service.Register("helloworld3", "", "", (tag) => "hello world 3"); service.Register("helloworld4", "", "", (tag) => "hello world 4"); service.Register("helloworld5", "", "", (tag) => "hello world 5"); // Case 1 - no external content var result = service.BuildContent("$[helloworld1/]"); Assert.AreEqual(result, "hello world 1"); // Case 2 - content after result = service.BuildContent("$[helloworld1/] after"); Assert.AreEqual(result, "hello world 1 after"); // Case 3 - content before result = service.BuildContent("before $[helloworld1/]"); Assert.AreEqual(result, "before hello world 1"); // Case 4 - content before and after result = service.BuildContent("before $[helloworld1/] after"); Assert.AreEqual(result, "before hello world 1 after"); }
public void CanProcessViaAPI_EmptyTag_Attributes_DifferentLocations() { var service = new MacroService('$', '[', ']'); // 1. quick api service.Register("helloworld1", "", "", (tag) => "hello world 1 " + tag.Attributes.Get <string>("saying")); // Case 1 - no external content var result = service.BuildContent("$[helloworld1 saying=\"hi\"/]"); Assert.AreEqual(result, "hello world 1 hi"); // Case 2 - content after result = service.BuildContent("$[helloworld1 saying=\"hi\"/] after"); Assert.AreEqual(result, "hello world 1 hi after"); // Case 3 - content before result = service.BuildContent("before $[helloworld1 saying=\"hi\"/]"); Assert.AreEqual(result, "before hello world 1 hi"); // Case 4 - content before and after result = service.BuildContent("before $[helloworld1 saying=\"hi\"/] after"); Assert.AreEqual(result, "before hello world 1 hi after"); }