Permalink
Browse files

Merge branch 'whitespace-management' of http://github.com/otac0n/spark

…into otac0n-whitespace-management
  • Loading branch information...
2 parents 87e9b5e + 6d40ed1 commit 3d8f360734a61d011f2529748b47bbcefd655dec @RobertTheGrey RobertTheGrey committed Nov 8, 2010
Oops, something went wrong.
@@ -0,0 +1,102 @@
+//-------------------------------------------------------------------------
+// <copyright file="Constraints.cs">
+// Copyright 2008-2010 Louis DeJardin - http://whereslou.com
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+// </copyright>
+// <author>Louis DeJardin</author>
+// <author>John Gietzen</author>
+//-------------------------------------------------------------------------
+
+namespace Castle.MonoRail.Views.Spark.Tests
+{
+ using System;
+ using NUnit.Framework;
+ using NUnit.Framework.Constraints;
+
+ /// <summary>
+ /// The Is class is a helper class with properties and methods that supply a
+ /// number of constraints used in Asserts.
+ /// </summary>
+ public static class Contains
+ {
+ /// <summary>
+ /// Contains.InOrder returns a constraint that tests whether the actual value
+ /// contains all of the specified items in order.
+ /// </summary>
+ /// <param name="items">The list of items to test.</param>
+ /// <returns>true, if all items are contained within the actual value, in order; false, otherwise.</returns>
+ public static Constraint InOrder(params string[] items)
+ {
+ return new ContainsInOrderConstraint(items);
+ }
+
+ /// <summary>
+ /// A constraint that tests whether the actual value contains all of the specified items in order.
+ /// </summary>
+ private class ContainsInOrderConstraint : Constraint
+ {
+ /// <summary>
+ /// Holds the list of items to test.
+ /// </summary>
+ private readonly string[] items;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ContainsInOrderConstraint"/> class.
+ /// </summary>
+ /// <param name="items">The list of items to test.</param>
+ public ContainsInOrderConstraint(params string[] items)
+ {
+ this.items = items;
+ }
+
+ /// <summary>
+ /// Tests whether the actual value contains all of the specified items in order.
+ /// </summary>
+ /// <param name="actual">The actual value to test.</param>
+ /// <returns>true, if all items are contained within the actual value, in order; false, otherwise.</returns>
+ public override bool Matches(object actual)
+ {
+ if (actual == null)
+ {
+ return this.items.Length == 0;
+ }
+
+ var actualString = actual.ToString();
+
+ int index = 0;
+ foreach (string value in this.items)
+ {
+ int nextIndex = actualString.IndexOf(value, index);
+ if (nextIndex < 0)
+ {
+ return false;
+ }
+
+ index = nextIndex + value.Length;
+ }
+
+ return true;
+ }
+
+ /// <summary>
+ /// Writes the constraint description to a MessageWriter.
+ /// </summary>
+ /// <param name="writer">The writer on which the description is displayed.</param>
+ public override void WriteDescriptionTo(MessageWriter writer)
+ {
+ writer.WriteLine("Tests whether the actual value contains all of the specified items in order.");
+ }
+ }
+ }
+}
@@ -1,122 +1,128 @@
-// Copyright 2008-2009 Louis DeJardin - http://whereslou.com
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-using System.IO;
-using Castle.MonoRail.Framework;
-using Castle.MonoRail.Framework.Services;
-using Castle.MonoRail.Framework.Test;
-using Castle.MonoRail.Views.Spark.Tests.Stubs;
-using NUnit.Framework;
-using Rhino.Mocks;
-
-namespace Castle.MonoRail.Views.Spark.Tests.ViewComponents
-{
- [TestFixture]
- public class ViewComponentSectionTests : BaseViewComponentTests
- {
- public override void Init()
- {
- base.Init();
- viewComponentFactory.Registry.AddViewComponent("ComponentWithSections", typeof(ComponentWithSections));
- }
-
- [Test]
- public void ComponentWithSimpleSections()
- {
- mocks.ReplayAll();
-
- var writer = new StringWriter();
- factory.Process("Home\\ComponentWithSimpleSections.spark", writer, engineContext, controller, controllerContext);
-
- var output = writer.ToString();
- Assert.IsTrue(output.Contains("this-is-a-header"));
- Assert.IsTrue(output.Contains("this-is-a-body"));
- Assert.IsTrue(output.Contains("this-is-a-footer"));
- }
-
- [Test]
- public void ComponentWithIfConditionInSection()
- {
- mocks.ReplayAll();
-
- var writer = new StringWriter();
- factory.Process("Home\\ComponentWithComplexSections.spark", writer, engineContext, controller, controllerContext);
-
- var output = writer.ToString();
- Assert.IsTrue(output.Contains("this-should-show-up"));
- Assert.IsFalse(output.Contains("this-should-not-show-up"));
- Assert.IsFalse(output.Contains("if condition"));
- }
-
- [Test]
- public void ComponentWithForEachInSection()
- {
- mocks.ReplayAll();
-
- var writer = new StringWriter();
- factory.Process("Home\\ComponentWithComplexSections.spark", writer, engineContext, controller, controllerContext);
-
- var output = writer.ToString();
- Assert.IsTrue(output.Contains("1,2,3,"));
- Assert.IsTrue(output.Contains("<span>10</span><span>9</span><span>8</span>"));
- Assert.IsFalse(output.Contains("for each"));
- Assert.IsFalse(output.Contains("span each"));
- }
-
- [Test]
- public void ComponentWithPartialsInSection()
- {
- mocks.ReplayAll();
-
- var writer = new StringWriter();
- factory.Process("Home\\ComponentWithPartialsInSection.spark", writer, engineContext, controller, controllerContext);
-
- var output = writer.ToString();
- Assert.IsTrue(output.Contains("this is some text: test123"));
- }
-
- [Test]
- public void NestedComponentInSection()
- {
- mocks.ReplayAll();
-
- var writer = new StringWriter();
- factory.Process("Home\\NestedComponentInSection.spark", writer, engineContext, controller, controllerContext);
-
- var output = writer.ToString();
- Assert.IsTrue(output.Contains("header1"));
- Assert.IsTrue(output.Contains("header2"));
- Assert.IsTrue(output.Contains("body1"));
- Assert.IsTrue(output.Contains("body2"));
- Assert.IsTrue(output.Contains("footer1"));
- Assert.IsTrue(output.Contains("footer2"));
-
- Assert.IsFalse(output.Contains("<header>"));
- Assert.IsFalse(output.Contains("<body>"));
- Assert.IsFalse(output.Contains("<footer>"));
- Assert.IsFalse(output.Contains("</ComponentWithSections>"));
- }
-
- [ViewComponentDetails("ComponentWithSections",Sections="header,body,footer")]
- class ComponentWithSections : ViewComponent
- {
- public override void Render()
- {
- RenderSection("header");
- RenderSection("body");
- RenderSection("footer");
- }
- }
- }
-}
+//-------------------------------------------------------------------------
+// <copyright file="Constraints.cs">
+// Copyright 2008-2010 Louis DeJardin - http://whereslou.com
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+// </copyright>
+// <author>Louis DeJardin</author>
+// <author>John Gietzen</author>
+//-------------------------------------------------------------------------
+
+namespace Castle.MonoRail.Views.Spark.Tests.ViewComponents
+{
+ using System;
+ using System.IO;
+ using Castle.MonoRail.Framework;
+ using NUnit.Framework;
+
+ [TestFixture]
+ public class ViewComponentSectionTests : BaseViewComponentTests
+ {
+ public override void Init()
+ {
+ base.Init();
+ viewComponentFactory.Registry.AddViewComponent("ComponentWithSections", typeof(ComponentWithSections));
+ }
+
+ [Test]
+ public void ComponentWithSimpleSections()
+ {
+ mocks.ReplayAll();
+
+ var writer = new StringWriter();
+ factory.Process("Home\\ComponentWithSimpleSections.spark", writer, engineContext, controller, controllerContext);
+
+ var output = writer.ToString();
+ Assert.IsTrue(output.Contains("this-is-a-header"));
+ Assert.IsTrue(output.Contains("this-is-a-body"));
+ Assert.IsTrue(output.Contains("this-is-a-footer"));
+ }
+
+ [Test]
+ public void ComponentWithIfConditionInSection()
+ {
+ mocks.ReplayAll();
+
+ var writer = new StringWriter();
+ factory.Process("Home\\ComponentWithComplexSections.spark", writer, engineContext, controller, controllerContext);
+
+ var output = writer.ToString();
+ Assert.IsTrue(output.Contains("this-should-show-up"));
+ Assert.IsFalse(output.Contains("this-should-not-show-up"));
+ Assert.IsFalse(output.Contains("if condition"));
+ }
+
+ [Test]
+ public void ComponentWithForEachInSection()
+ {
+ mocks.ReplayAll();
+
+ var writer = new StringWriter();
+ factory.Process("Home\\ComponentWithComplexSections.spark", writer, engineContext, controller, controllerContext);
+
+ var output = writer.ToString();
+ Assert.That(output, Contains.InOrder(
+ "1,2,3,",
+ "<span>10</span>",
+ "<span>9</span>",
+ "<span>8</span>"));
+ Assert.IsFalse(output.Contains("for each"));
+ Assert.IsFalse(output.Contains("span each"));
+ }
+
+ [Test]
+ public void ComponentWithPartialsInSection()
+ {
+ mocks.ReplayAll();
+
+ var writer = new StringWriter();
+ factory.Process("Home\\ComponentWithPartialsInSection.spark", writer, engineContext, controller, controllerContext);
+
+ var output = writer.ToString();
+ Assert.IsTrue(output.Contains("this is some text: test123"));
+ }
+
+ [Test]
+ public void NestedComponentInSection()
+ {
+ mocks.ReplayAll();
+
+ var writer = new StringWriter();
+ factory.Process("Home\\NestedComponentInSection.spark", writer, engineContext, controller, controllerContext);
+
+ var output = writer.ToString();
+ Assert.IsTrue(output.Contains("header1"));
+ Assert.IsTrue(output.Contains("header2"));
+ Assert.IsTrue(output.Contains("body1"));
+ Assert.IsTrue(output.Contains("body2"));
+ Assert.IsTrue(output.Contains("footer1"));
+ Assert.IsTrue(output.Contains("footer2"));
+
+ Assert.IsFalse(output.Contains("<header>"));
+ Assert.IsFalse(output.Contains("<body>"));
+ Assert.IsFalse(output.Contains("<footer>"));
+ Assert.IsFalse(output.Contains("</ComponentWithSections>"));
+ }
+
+ [ViewComponentDetails("ComponentWithSections",Sections="header,body,footer")]
+ class ComponentWithSections : ViewComponent
+ {
+ public override void Render()
+ {
+ RenderSection("header");
+ RenderSection("body");
+ RenderSection("footer");
+ }
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit 3d8f360

Please sign in to comment.