Subversion Repository Public Repository

ConnectionOdbcSdk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
´╗┐using System;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Cisco.UnityConnection.Utilities;

namespace ConnectionServerOdbcIntegrationTests.IntegrationTests
{
    [TestClass]
    public class StringExtensionUnitTests
    {
        // ReSharper does not handle the Assert. calls in unit test property - turn off checking for unreachable code
        // ReSharper disable HeuristicUnreachableCode

        #region Fields and Properties

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext { get; set; }

        #endregion


        [TestMethod]
        public void ToBool_True_Success()
        {
            Assert.IsTrue("true".ToBool(),"String extension failed to parse 'true' as bool");
        }
        
        [TestMethod]
        public void ToBool_False_Success()
        {
            Assert.IsFalse("false".ToBool(), "String extension failed to parse 'true' as bool");
        }

        [TestMethod]
        public void ToBool_1_Success()
        {
            Assert.IsTrue("1".ToBool(), "String extension failed to parse '1' as bool");
        }

        [TestMethod]
        public void ToBool_0_Success()
        {
            Assert.IsFalse("0".ToBool(), "String extension failed to parse '0' as bool");
        }

        [TestMethod]
        public void ToBool_Invalid_Failure()
        {
            Assert.IsFalse("bogus".ToBool(), "string extension failed to return false on invalid boolean string");
        }

        [TestMethod]
        public void ToInt_1_Success()
        {
            int iTemp = "1".ToInt();
            Assert.IsTrue(iTemp == 1, "String extension failed to parse '1' as integer");

            }

        [TestMethod]
        public void ToInt_Negative_Success()
        {
            int iTemp = "-14".ToInt();
            Assert.IsTrue(iTemp == -14, "String extension failed to parse '-14' as integer");
        }

        [TestMethod]
        public void ToInt_Invalid_Success()
        {
            int iTemp = "bogus".ToInt();
            Assert.IsTrue(iTemp == 0, "String extension failed to return 0 for 'bogus' as integer");
         }

        [TestMethod]
        public void ToLong_1_Success()
        {
            long lTemp = "1".ToLong();
            Assert.IsTrue(lTemp == 1, "String extension failed to parse '1' as integer");
        }

        [TestMethod]
        public void ToLong_Negative_Success()
        {
            long lTemp = "-14".ToLong();
            Assert.IsTrue(lTemp == -14, "String extension failed to parse '-14' as integer");

        }

        [TestMethod]
        public void ToLong_Invalid_Failure()
        {
            long lTemp = "bogus".ToLong();
            Assert.IsTrue(lTemp == 0, "String extension failed to return 0 for 'bogus' as long");
        }

        [TestMethod]
        public void QuerySafe_SingleQuote_Success()
        {
            string strTemp = "O'Riley".QuerySafe();
            Assert.IsTrue(strTemp.Contains("''"), "string extension query safe did not replace single quote with double");
        }

        [TestMethod]
        public void QuerySafe_EmptyString_Success()
        {
            string strTemp = "".QuerySafe();
            Assert.IsTrue(string.IsNullOrEmpty(strTemp), "string extension query safe did not return empty string for empty string");
        }

        [TestMethod]
        public void ToDate_Success()
        {
            DateTime oDate = "1/20/2010".ToDate();
            Assert.IsTrue(oDate != DateTime.MinValue, "String extension failed to parse '1/20/2010' as date");
        }

        [TestMethod]
        public void ToDate_InvalidDate_Failure()
        {
            DateTime oDate = "bogus".ToDate();
            Assert.IsTrue(oDate == DateTime.MinValue, "String extension failed to return min date on 'bogus' as date");
        }

        [TestMethod]
        public void ConvertToDateFormat_Success()
        {
            string strTemp = "1/20/2010".ConvertToDateFormat();
            Assert.IsFalse(string.IsNullOrEmpty(strTemp),"Failed to convert date string into general date format");
        }

        [TestMethod]
        public void ConvertToDateFormat_InvalidDate()
        {
            string strTemp = "bogus".ConvertToDateFormat();
            Assert.IsTrue(strTemp.Equals("bogus"), "Invalid date format did not return string passed in for ConvertToDateFormat");
        }

        [TestMethod]
        public void ToAscii_Success()
        {
            string strTemp = "1234".ToAscii();
            Assert.IsFalse(string.IsNullOrEmpty(strTemp), "Failed to convert string into asci");
        }

        [TestMethod]
        public void ToAscii_EmptyString()
        {
            string strTemp = "".ToAscii();
            Assert.IsTrue(string.IsNullOrEmpty(strTemp), "string extension ToAscii did not return empty string for empty string");
        }

        [TestMethod]
        public void ToUtf8_Success()
        {
            string strTemp = "1234".ToUtf8();
            Assert.IsFalse(string.IsNullOrEmpty(strTemp), "Failed to convert string into utf8");
        }

        [TestMethod]
        public void ToUtf8_EmptyString()
        {
            string strTemp = "".ToUtf8();
            Assert.IsTrue(string.IsNullOrEmpty(strTemp), "string extension ToUtf8 did not return empty string for empty string");
        }

        [TestMethod]
        public void DetectEncoding_Success()
        {
            Encoding oEncoding = "blah".DetectEncoding();
            Assert.IsFalse(oEncoding == null, "Failed to detect string encoding");
        }

        [TestMethod]
        public void RemoveBraces_WithBraces()
        {
            string strTemp = "{remove braces}".RemoveBraces();
            Assert.IsTrue(strTemp.Equals("remove braces"),"Failed to remove braces.");
        }

        [TestMethod]
        public void RemoveBraces_WithOutBraces()
        {
            string strTemp = "remove braces".RemoveBraces();
            Assert.IsTrue(strTemp.Equals("remove braces"), "Failed to remove braces.");
        }


        [TestMethod]
        public void ContainedInList_InList()
        {
            bool bTemp = "item4".ContainedInList("item1", "item2", "item3", "item4", "item5");
            Assert.IsTrue(bTemp,"Failed to find an item in a list of strings");
        }

        [TestMethod]
        public void ContainedInList_NotInList()
        {
            bool bTemp = "item6".ContainedInList("item1", "item2", "item3", "item4", "item5");
            Assert.IsFalse(bTemp, "Returned true incorrectly for list membership check");
        }

        [TestMethod]
        public void UriSafe_EmptyString()
        {
            string ret = "".UriSafe();
            Assert.IsTrue(string.IsNullOrEmpty(ret),"Empty string to UriSafe should return empty string");
        }

        [TestMethod]
        public void UriSafe_RemoveSpace()
        {
            string ret = "string with spaces".UriSafe();
            Assert.IsFalse(ret.Contains(" "), "Spaces should be removed by UriSafe");
        }

        [TestMethod]
        public void UriSafe_RemoveAndSign()
        {
            string ret = "string&with&Ands".UriSafe();
            Assert.IsFalse(ret.Contains("&"), "And signs should be removed by UriSafe");
        }

        [TestMethod]
        public void UriSafe_RemoveQuestionMark()
        {
            string ret = "string?with?QuestionMarks".UriSafe();
            Assert.IsFalse(ret.Contains("?"), "Question marks should be removed by UriSafe");
        }

        [TestMethod]
        public void UriSafe_RemoveSemiColon()
        {
            string ret = "string;with;SemiColons".UriSafe();
            Assert.IsFalse(ret.Contains(";"), "Semi colons should be removed by UriSafe");
        }

        [TestMethod]
        public void HtmlBodySafe_EmptyString()
        {
            string ret = "".HtmlBodySafe();
            Assert.IsTrue(string.IsNullOrEmpty(ret), "Empty string input to HtmlBodySafe should return empty string");
        }

        [TestMethod]
        public void HtmlBodySafe_RemoveAndSign()
        {
            string ret = "string&withAnds".HtmlBodySafe();
            Assert.IsTrue(ret.Contains("&#38;"), "And signs should be replaced by &#38; by HtmlBodySafe");
        }

        [TestMethod]
        public void TrimToEndOfToken_EmptyString()
        {
            string ret = "".TrimToEndOfToken("junk");
            Assert.IsTrue(string.IsNullOrEmpty(ret), "Empty string to TrimToEndOfToken should return empty string");
        }

        [TestMethod]
        public void TrimToEndOfToken_EmptyToken()
        {
            const string strString = "Junk";
            string ret = strString.TrimToEndOfToken("");
            Assert.IsTrue(ret.Equals(strString), "Empty token passed to TrimToEndOfToken should return original string");
        }

        [TestMethod]
        public void TrimToEndOfToken_NoTokenMatch()
        {
            const string strString = "testing string with no token in it";
            string ret = strString.TrimToEndOfToken("junk");
            Assert.IsTrue(ret.Equals(strString), "If token does not appear in string, string should be returned unchanged");
        }

        [TestMethod]
        public void TrimToEndOfToken_TokenMatch()
        {
            const string strString = "testing string with no token in it";
            const string strExpected = "no token in it";
            string ret = strString.TrimToEndOfToken("with ");
            Assert.IsTrue(ret.Equals(strExpected), "String not trimed from token:"+ret);
        }


        [TestMethod]
        public void TrimTokenFromEnd_EmptyString()
        {
            string ret = "".TrimTokenFromEnd("junk");
            Assert.IsTrue(string.IsNullOrEmpty(ret), "Empty string to TrimTokenFromEnd should return empty string");
        }

        [TestMethod]
        public void TrimTokenFromEnd_EmptyToken()
        {
            const string strString = "Junk";
            string ret = strString.TrimTokenFromEnd("");
            Assert.IsTrue(ret.Equals(strString), "Empty token passed to TrimTokenFromEnd should return original string");
        }

        [TestMethod]
        public void TrimTokenFromEnd_TokenMatch()
        {
            const string strString = "testing string with no token in it";
            const string strExpected = "testing string with no";
            string ret = strString.TrimTokenFromEnd(" token in it");
            Assert.IsTrue(ret.Equals(strExpected), "Token not trimmed form end:" + ret);
        }

        [TestMethod]
        public void TrimTokenFromEnd_NoTokenFound()
        {
            const string strString = "testing string with no token in it";
            string ret = strString.TrimTokenFromEnd("junk");
            Assert.IsTrue(ret.Equals(strString), "If token not found original string should be returned:" + ret);
        }

    }
}

Commits for ConnectionOdbcSdk/trunk/ConnectionServerOdbcIntegrationTests/UnitTests/StringExtensionUnitTests.cs

Diff revisions: vs.
Revision Author Commited Message
11 jlindborg picture jlindborg Mon 02 Sep, 2013 23:29:09 +0000

continuing to work on unit tests -