Removed untyped contructor from ComponentRegistration and add a protected setter.
[castle.git] / MonoRail / Castle.MonoRail.Framework.Tests / ViewComponents / DiggStylePaginationTestCase.cs
blobad2c8904e93eef6becef7b77813319b5b70c5e0b
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.MonoRail.Framework.Tests.ViewComponents
17 using System.Collections;
18 using System.Collections.Generic;
19 using System.IO;
20 using Castle.MonoRail.Framework.Helpers;
21 using Castle.MonoRail.Framework.ViewComponents;
22 using Castle.MonoRail.TestSupport;
23 using NUnit.Framework;
25 [TestFixture]
26 public class DiggStylePaginationTestCase : BaseViewComponentTest
28 private DiggStylePagination diggComponent;
29 private IPaginatedPage singlePage, secondPageOfThree;
31 [SetUp]
32 public void Init()
34 diggComponent = new DiggStylePagination();
36 singlePage = new Page(new string[] {"a", "b", "c"}, 1, 4, 1);
37 secondPageOfThree = new Page(new string[] {"a", "b", "c", "d"}, 2, 4, 10);
39 BuildEngineContext("area", "controller", "action");
42 [TearDown]
43 public void Terminate()
45 CleanUp();
48 [Test, ExpectedException(typeof(ViewComponentException), "The DiggStylePagination requires a view component " +
49 "parameter named 'page' which should contain 'IPaginatedPage' instance"
51 public void ThrowsExceptionIfNoPageWasSupplied()
53 diggComponent.Page = null;
54 diggComponent.Initialize();
57 [Test]
58 public void PageWithNoLinksInvokesStartAndEndSections()
60 List<string> actions = new List<string>();
62 SectionRender["startblock"] = delegate { actions.Add("started"); };
63 SectionRender["endblock"] = delegate { actions.Add("ended"); };
64 SectionRender["link"] = delegate { actions.Add("link"); };
66 diggComponent.Page = singlePage;
67 Request.FilePath = "/something";
68 PrepareViewComponent(diggComponent);
69 diggComponent.Render();
71 Assert.AreEqual(2, actions.Count);
72 Assert.AreEqual("started", actions[0]);
73 Assert.AreEqual("ended", actions[1]);
76 [Test]
77 public void PageWithLinksInvokesStartAndEndAndLinkSections()
79 List<string> actions = new List<string>();
81 SectionRender["startblock"] = delegate { actions.Add("started"); };
82 SectionRender["endblock"] = delegate { actions.Add("ended"); };
83 SectionRender["link"] = delegate { actions.Add("link"); };
85 diggComponent.Page = secondPageOfThree;
86 Request.FilePath = "/something";
87 PrepareViewComponent(diggComponent);
88 diggComponent.Render();
90 Assert.AreEqual(6, actions.Count);
91 Assert.AreEqual("started", actions[0]);
92 Assert.AreEqual("link", actions[1]);
93 Assert.AreEqual("link", actions[2]);
94 Assert.AreEqual("link", actions[3]);
95 Assert.AreEqual("link", actions[4]);
96 Assert.AreEqual("ended", actions[5]);
99 [Test]
100 public void PageWithNoLinksPrintsNoLinks()
102 SectionRender["startblock"] = delegate(IDictionary context, TextWriter writer) { writer.Write("started"); };
103 SectionRender["endblock"] = delegate(IDictionary context, TextWriter writer) { writer.Write("ended"); };
105 diggComponent.UseInlineStyle = false;
106 diggComponent.Page = singlePage;
107 Request.FilePath = "/something";
108 PrepareViewComponent(diggComponent);
109 diggComponent.Render();
111 Assert.AreEqual("started<span class=\"disabled\">&laquo; prev</span>\r\n" +
112 "<span class=\"current\">1</span>\r\n" +
113 "<span class=\"disabled\">next &raquo;</span>ended", Output);
116 [Test]
117 public void PageWithPrevNextPrintsCustomizedLinks()
119 SectionRender["startblock"] = delegate(IDictionary context, TextWriter writer) { writer.Write("started"); };
120 SectionRender["endblock"] = delegate(IDictionary context, TextWriter writer) { writer.Write("ended"); };
121 SectionRender["prev"] = delegate(IDictionary context, TextWriter writer) { writer.Write("customprev"); };
122 SectionRender["next"] = delegate(IDictionary context, TextWriter writer) { writer.Write("customnext"); };
124 diggComponent.UseInlineStyle = false;
125 diggComponent.Page = singlePage;
126 Request.FilePath = "/something";
127 PrepareViewComponent(diggComponent);
128 diggComponent.Render();
130 Assert.AreEqual("started<span class=\"disabled\">customprev</span>\r\n" +
131 "<span class=\"current\">1</span>\r\n" +
132 "<span class=\"disabled\">customnext</span>ended", Output);
135 [Test]
136 public void PageWithLinksPrintsLinks()
138 SectionRender["startblock"] = delegate(IDictionary context, TextWriter writer) { writer.Write("started"); };
139 SectionRender["endblock"] = delegate(IDictionary context, TextWriter writer) { writer.Write("ended"); };
140 SectionRender["link"] = delegate(IDictionary context, TextWriter writer)
142 writer.Write(" <{0} {1} {2}> ", context["pageIndex"], context["url"], context["text"]);
145 diggComponent.UseInlineStyle = false;
146 diggComponent.Page = secondPageOfThree;
147 Request.FilePath = "/something";
148 PrepareViewComponent(diggComponent);
149 diggComponent.Render();
151 Assert.AreEqual("started <1 /something?page=1 &laquo; prev> " +
152 "<1 /something?page=1 1> \r\n<span class=\"current\">2</span>\r\n " +
153 "<3 /something?page=3 3> <3 /something?page=3 next &raquo;> ended", Output);
156 [Test]
157 public void SupportsSections()
159 Assert.IsTrue(diggComponent.SupportsSection("startblock"), "Supports startblock Section");
160 Assert.IsTrue(diggComponent.SupportsSection("endblock"), "Supports endblock Section");
161 Assert.IsTrue(diggComponent.SupportsSection("link"), "Supports Links Section");
162 Assert.IsFalse(diggComponent.SupportsSection("NotSupported"), "Unsupported section");