1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
18 using System
.Collections
;
19 using Castle
.MonoRail
.Framework
.Helpers
;
20 using NUnit
.Framework
;
24 public class TextHelperTestCase
26 private TextHelper helper
= new TextHelper();
29 [ExpectedException(typeof(ArgumentNullException
))]
30 public void PascalCaseToWord_CannotAcceptNulls()
32 TextHelper
.PascalCaseToWord(null);
36 public void PascalCaseToWord_SeparatesWordsBasedOnCase()
38 Assert
.AreEqual("Sequence Info", TextHelper
.PascalCaseToWord("SequenceInfo"));
42 [ExpectedException(typeof(ArgumentNullException
))]
43 public void ToSentenceWithNull()
45 string sentence
= helper
.ToSentence(null);
46 Assert
.AreEqual("", sentence
);
50 public void ToSentenceWithStringArrayNoElements()
52 string sentence
= helper
.ToSentence(new string[0]);
53 Assert
.AreEqual("", sentence
);
57 public void ToSentenceWithStringArrayOneElement()
59 string sentence
= helper
.ToSentence(new string[] {"apple"}
);
60 Assert
.AreEqual("apple", sentence
);
64 public void ToSentenceWithStringArrayTwoElements()
66 string sentence
= helper
.ToSentence(new string[] {"apple", "banana"}
);
67 Assert
.AreEqual("apple and banana", sentence
);
71 public void ToSentenceWithStringArrayThreeElements()
73 string sentence
= helper
.ToSentence(new string[] {"apple", "banana", "mango"}
);
74 Assert
.AreEqual("apple, banana and mango", sentence
);
78 public void ToSentenceWithSpecifiedConnector()
80 string sentence
= helper
.ToSentence(new string[] {"apple", "banana", "mango"}
, "y");
81 Assert
.AreEqual("apple, banana y mango", sentence
);
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
);
93 private readonly string _firstName
;
94 private readonly string _lastName
;
96 public Person(string firstName
, string lastName
)
98 _firstName
= firstName
;
102 public override string ToString()
104 return _firstName
+ " " + _lastName
;
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
);