Fix the build.
[castle.git] / MonoRail / Castle.MonoRail.Framework.Tests / Helpers / TextHelperTestCase.cs
blob1efe417f431b247c346fe42365c36e886c7f7a3a
1 // Copyright 2004-2007 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.Helpers
17 using System;
18 using System.Collections;
19 using Castle.MonoRail.Framework.Helpers;
20 using NUnit.Framework;
23 [TestFixture]
24 public class TextHelperTestCase
26 private TextHelper helper = new TextHelper();
28 [Test]
29 [ExpectedException(typeof(ArgumentNullException))]
30 public void PascalCaseToWord_CannotAcceptNulls()
32 TextHelper.PascalCaseToWord(null);
35 [Test]
36 public void PascalCaseToWord_SeparatesWordsBasedOnCase()
38 Assert.AreEqual("Sequence Info", TextHelper.PascalCaseToWord("SequenceInfo"));
41 [Test]
42 [ExpectedException(typeof(ArgumentNullException))]
43 public void ToSentenceWithNull()
45 string sentence = helper.ToSentence(null);
46 Assert.AreEqual("", sentence);
49 [Test]
50 public void ToSentenceWithStringArrayNoElements()
52 string sentence = helper.ToSentence(new string[0]);
53 Assert.AreEqual("", sentence);
56 [Test]
57 public void ToSentenceWithStringArrayOneElement()
59 string sentence = helper.ToSentence(new string[] {"apple"});
60 Assert.AreEqual("apple", sentence);
63 [Test]
64 public void ToSentenceWithStringArrayTwoElements()
66 string sentence = helper.ToSentence(new string[] {"apple", "banana"});
67 Assert.AreEqual("apple and banana", sentence);
70 [Test]
71 public void ToSentenceWithStringArrayThreeElements()
73 string sentence = helper.ToSentence(new string[] {"apple", "banana", "mango"});
74 Assert.AreEqual("apple, banana and mango", sentence);
77 [Test]
78 public void ToSentenceWithSpecifiedConnector()
80 string sentence = helper.ToSentence(new string[] {"apple", "banana", "mango"}, "y");
81 Assert.AreEqual("apple, banana y mango", sentence);
84 [Test]
85 public void ToSentenceWithCommaBeforeConnectorSpecified()
87 string sentence = helper.ToSentence(new string[] {"apple", "banana", "mango"}, TextHelper.DefaultConnector, false);
88 Assert.AreEqual("apple, banana, and mango", sentence);
91 private class Person
93 private readonly string _firstName;
94 private readonly string _lastName;
96 public Person(string firstName, string lastName)
98 _firstName = firstName;
99 _lastName = lastName;
102 public override string ToString()
104 return _firstName + " " + _lastName;
108 [Test]
109 public void ToSentenceWithArrayListOfPeople()
111 ArrayList people = new ArrayList();
112 people.Add(new Person("Clark", "Kent"));
113 people.Add(new Person("Lois", "Lane"));
114 people.Add(new Person("Lex", "Luther"));
115 string sentence = helper.ToSentence(people);
116 Assert.AreEqual("Clark Kent, Lois Lane and Lex Luther", sentence);