Fixing an issue with output parameters that are of type IntPtr
[castle.git] / MonoRail / Castle.MonoRail.Framework.Tests / Helpers / TextHelperTestCase.cs
blobfef7c585e5c6ba46753a5d2a9639723fd21bf19b
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.Helpers
17 using System;
18 using System.Collections;
19 using System.Globalization;
20 using System.Threading;
21 using Castle.MonoRail.Framework.Helpers;
22 using NUnit.Framework;
24 [TestFixture]
25 public class TextHelperTestCase
27 private static TextHelper helper = new TextHelper();
29 [Test]
30 public void FormatPhone_CanFormatForUSCulture()
32 CultureInfo en = CultureInfo.CreateSpecificCulture("en");
33 Thread.CurrentThread.CurrentCulture = en;
34 Thread.CurrentThread.CurrentUICulture = en;
36 Assert.AreEqual("(123) 456-1234", helper.FormatPhone("1234561234"));
39 [Test]
40 public void FormatPhone_IgnoresStringTooSmall()
42 CultureInfo en = CultureInfo.CreateSpecificCulture("en");
43 Thread.CurrentThread.CurrentCulture = en;
44 Thread.CurrentThread.CurrentUICulture = en;
46 Assert.AreEqual("123", helper.FormatPhone("123"));
49 [Test]
50 public void FormatPhone_IgnoresStringIfSomeNonNumericCharsArePresent()
52 CultureInfo en = CultureInfo.CreateSpecificCulture("en");
53 Thread.CurrentThread.CurrentCulture = en;
54 Thread.CurrentThread.CurrentUICulture = en;
56 Assert.AreEqual("123-111-1212", helper.FormatPhone("123-111-1212"));
57 Assert.AreEqual("(123)111-1212", helper.FormatPhone("(123)111-1212"));
58 Assert.AreEqual("123.111.1212", helper.FormatPhone("123.111.1212"));
61 [Test]
62 [ExpectedException(typeof(ArgumentNullException))]
63 public void PascalCaseToWord_CannotAcceptNulls()
65 TextHelper.PascalCaseToWord(null);
68 [Test]
69 public void PascalCaseToWord_SeparatesWordsBasedOnCase()
71 Assert.AreEqual("Sequence Info", TextHelper.PascalCaseToWord("SequenceInfo"));
74 [Test]
75 [ExpectedException(typeof(ArgumentNullException))]
76 public void ToSentenceWithNull()
78 string sentence = TextHelper.ToSentence(null);
79 Assert.AreEqual("", sentence);
82 [Test]
83 public void ToSentenceWithStringArrayNoElements()
85 string sentence = TextHelper.ToSentence(new string[0]);
86 Assert.AreEqual("", sentence);
89 [Test]
90 public void ToSentenceWithStringArrayOneElement()
92 string sentence = TextHelper.ToSentence(new string[] { "apple" });
93 Assert.AreEqual("apple", sentence);
96 [Test]
97 public void ToSentenceWithStringArrayTwoElements()
99 string sentence = TextHelper.ToSentence(new string[] { "apple", "banana" });
100 Assert.AreEqual("apple and banana", sentence);
103 [Test]
104 public void ToSentenceWithStringArrayThreeElements()
106 string sentence = TextHelper.ToSentence(new string[] { "apple", "banana", "mango" });
107 Assert.AreEqual("apple, banana and mango", sentence);
110 [Test]
111 public void ToSentenceWithSpecifiedConnector()
113 string sentence = TextHelper.ToSentence(new string[] { "apple", "banana", "mango" }, "y");
114 Assert.AreEqual("apple, banana y mango", sentence);
117 [Test]
118 public void ToSentenceWithCommaBeforeConnectorSpecified()
120 string sentence = TextHelper.ToSentence(new string[] { "apple", "banana", "mango" }, TextHelper.DefaultConnector, false);
121 Assert.AreEqual("apple, banana, and mango", sentence);
124 private class Person
126 private readonly string _firstName;
127 private readonly string _lastName;
129 public Person(string firstName, string lastName)
131 _firstName = firstName;
132 _lastName = lastName;
135 public override string ToString()
137 return _firstName + " " + _lastName;
141 [Test]
142 public void ToSentenceWithArrayListOfPeople()
144 ArrayList people = new ArrayList();
145 people.Add(new Person("Clark", "Kent"));
146 people.Add(new Person("Lois", "Lane"));
147 people.Add(new Person("Lex", "Luther"));
148 string sentence = TextHelper.ToSentence(people);
149 Assert.AreEqual("Clark Kent, Lois Lane and Lex Luther", sentence);