OSDN Git Service

#30244 Visual Studio 2012 Express for Windows Desktop, StyleCop 4.7, WiX 3.6 に合わせたソース...
[wptscs/wpts.git] / HmLibTest / Models / IgnoreCaseDictionaryTest.cs
1 // ================================================================================================
2 // <summary>
3 //      IgnoreCaseDictionaryのテストクラスソース。</summary>
4 //
5 // <copyright file="IgnoreCaseDictionaryTest.cs" company="honeplusのメモ帳">
6 //      Copyright (C) 2012 Honeplus. All rights reserved.</copyright>
7 // <author>
8 //      Honeplus</author>
9 // ================================================================================================
10
11 namespace Honememo.Models
12 {
13     using System;
14     using System.Collections.Generic;
15     using Microsoft.VisualStudio.TestTools.UnitTesting;
16
17     /// <summary>
18     /// <see cref="IgnoreCaseDictionary&lt;TValue&gt;"/>のテストクラスです。
19     /// </summary>
20     [TestClass]
21     public class IgnoreCaseDictionaryTest
22     {
23         #region コンストラクタテストケース
24
25         /// <summary>
26         /// コンストラクタテストケース(引数なし)。
27         /// </summary>
28         [TestMethod]
29         public void TestConstructor()
30         {
31             IgnoreCaseDictionary<string> d = new IgnoreCaseDictionary<string>();
32             Assert.AreEqual(0, d.Dictionary.Count);
33         }
34
35         /// <summary>
36         /// コンストラクタテストケース(引数Dictionary)。
37         /// </summary>
38         [TestMethod]
39         public void TestConstructorDictionary()
40         {
41             IDictionary<string, string> inner = new Dictionary<string, string>();
42             inner.Add("TestKey", "TestValue");
43             IgnoreCaseDictionary<string> d = new IgnoreCaseDictionary<string>(inner);
44             Assert.AreEqual(inner, d.Dictionary);
45             Assert.IsTrue(d.ContainsKey("TESTkey"));
46         }
47
48         /// <summary>
49         /// コンストラクタテストケース(引数Dictionary、null値)。
50         /// </summary>
51         [TestMethod]
52         [ExpectedException(typeof(ArgumentNullException))]
53         public void TestConstructorDictionaryNull()
54         {
55             new IgnoreCaseDictionary<string>(null);
56         }
57
58         #endregion
59
60         #region 独自実装公開プロパティテストケース
61         
62         /// <summary>
63         /// Dictionaryプロパティテストケース(正常系)。
64         /// </summary>
65         [TestMethod]
66         public void TestDictionary()
67         {
68             IgnoreCaseDictionary<string> d = new IgnoreCaseDictionary<string>();
69             IDictionary<string, string> inner = new Dictionary<string, string>();
70             inner.Add("TestKey", "TestValue");
71             d.Dictionary = inner;
72             Assert.AreSame(inner, d.Dictionary);
73             Assert.IsTrue(d.ContainsKey("TESTkey"));
74         }
75
76         /// <summary>
77         /// Dictionaryプロパティテストケース(null値)。
78         /// </summary>
79         [TestMethod]
80         [ExpectedException(typeof(ArgumentNullException))]
81         public void TestDictionaryNull()
82         {
83             IgnoreCaseDictionary<string> d = new IgnoreCaseDictionary<string>();
84             d.Dictionary = null;
85         }
86  
87         #endregion
88
89         #region ラップするインスタンスを参照するプロパティテストケース
90
91         /// <summary>
92         /// Keysプロパティテストケース。
93         /// </summary>
94         [TestMethod]
95         public void TestKeys()
96         {
97             // ラップするIDictionaryと同じ値であること
98             IDictionary<string, string> inner = new Dictionary<string, string>();
99             inner.Add("TestKey", "TestValue");
100             IgnoreCaseDictionary<string> d = new IgnoreCaseDictionary<string>(inner);
101             Assert.AreEqual(inner.Keys, d.Keys);
102         }
103
104         /// <summary>
105         /// Valuesプロパティテストケース。
106         /// </summary>
107         [TestMethod]
108         public void TestValues()
109         {
110             // ラップするIDictionaryと同じ値であること
111             IDictionary<string, string> inner = new Dictionary<string, string>();
112             inner.Add("TestKey", "TestValue");
113             IgnoreCaseDictionary<string> d = new IgnoreCaseDictionary<string>(inner);
114             Assert.AreEqual(inner.Values, d.Values);
115         }
116
117         /// <summary>
118         /// Countプロパティテストケース。
119         /// </summary>
120         [TestMethod]
121         public void TestCount()
122         {
123             // ラップするIDictionaryと同じ値であること
124             IDictionary<string, string> inner = new Dictionary<string, string>();
125             inner.Add("TestKey", "TestValue");
126             IgnoreCaseDictionary<string> d = new IgnoreCaseDictionary<string>(inner);
127             Assert.AreEqual(inner.Count, d.Count);
128         }
129         
130         /// <summary>
131         /// IsReadOnlyプロパティテストケース。
132         /// </summary>
133         [TestMethod]
134         public void TestIsReadOnly()
135         {
136             // ラップするIDictionaryと同じ値であること
137             IDictionary<string, string> inner = new Dictionary<string, string>();
138             inner.Add("TestKey", "TestValue");
139             IgnoreCaseDictionary<string> d = new IgnoreCaseDictionary<string>(inner);
140             Assert.AreEqual(inner.IsReadOnly, d.IsReadOnly);
141         }
142
143         #endregion
144         
145         #region 独自実装インデクサーテストケース
146
147         /// <summary>
148         /// thisインデクサーテストケース(正常系)。
149         /// </summary>
150         [TestMethod]
151         public void TestThis()
152         {
153             IgnoreCaseDictionary<string> d = new IgnoreCaseDictionary<string>();
154             d["TestKey"] = "TestValue";
155             Assert.AreEqual("TestValue", d["TESTkey"]);
156             Assert.AreEqual("TestValue", d.Dictionary["TestKey"]);
157             d["tESTkEY"] = "TestValue2";
158             Assert.AreEqual("TestValue2", d["TESTkey"]);
159             Assert.AreEqual("TestValue2", d.Dictionary["tESTkEY"]);
160             Assert.IsFalse(d.Dictionary.ContainsKey("TestKey"));
161         }
162
163         /// <summary>
164         /// thisインデクサーテストケース(get、null値)。
165         /// </summary>
166         [TestMethod]
167         [ExpectedException(typeof(ArgumentNullException))]
168         public void TestThisGetNull()
169         {
170             IgnoreCaseDictionary<string> d = new IgnoreCaseDictionary<string>();
171             string dymmy = d[null];
172         }
173
174         /// <summary>
175         /// thisインデクサーテストケース(set、null値)。
176         /// </summary>
177         [TestMethod]
178         [ExpectedException(typeof(ArgumentNullException))]
179         public void TestThisSetNull()
180         {
181             IgnoreCaseDictionary<string> d = new IgnoreCaseDictionary<string>();
182             d[null] = "TestValue";
183         }
184
185         /// <summary>
186         /// thisインデクサーテストケース(get、値なし)。
187         /// </summary>
188         [TestMethod]
189         [ExpectedException(typeof(KeyNotFoundException))]
190         public void TestThisKeyNotFound()
191         {
192             IgnoreCaseDictionary<string> d = new IgnoreCaseDictionary<string>();
193             string dymmy = d["TestKey"];
194         }
195
196         #endregion
197
198         #region 独自実装メソッドテストケース
199
200         /// <summary>
201         /// Addメソッドテストケース(正常系)。
202         /// </summary>
203         [TestMethod]
204         public void TestAdd()
205         {
206             // IDictionaryのAddメソッド
207             IgnoreCaseDictionary<string> d = new IgnoreCaseDictionary<string>();
208             Assert.AreEqual(0, d.Count);
209             d.Add("TestKey", "TestValue");
210             Assert.AreEqual(1, d.Count);
211             Assert.AreEqual("TestValue", d["TESTkey"]);
212             Assert.AreEqual("TestValue", d.Dictionary["TestKey"]);
213             Assert.IsFalse(d.Dictionary.ContainsKey("TESTkey"));
214             d.Add("tESTkEY2", "TestValue2");
215             Assert.AreEqual(2, d.Count);
216             Assert.AreEqual("TestValue2", d["TESTkey2"]);
217             Assert.AreEqual("TestValue2", d.Dictionary["tESTkEY2"]);
218
219             // ICollectionのAddメソッド
220             d.Add(new KeyValuePair<string, string>("tESTkEY3", "TestValue3"));
221             Assert.AreEqual(3, d.Count);
222             Assert.AreEqual("TestValue3", d["TESTkey3"]);
223             Assert.AreEqual("TestValue3", d.Dictionary["tESTkEY3"]);
224         }
225
226         /// <summary>
227         /// Addメソッドテストケース(null値)。
228         /// </summary>
229         [TestMethod]
230         [ExpectedException(typeof(ArgumentNullException))]
231         public void TestAddNull()
232         {
233             new IgnoreCaseDictionary<string>().Add(null, "TestValue");
234         }
235
236         /// <summary>
237         /// Addメソッドテストケース(KeyValuePairのKeyがnull)。
238         /// </summary>
239         [TestMethod]
240         [ExpectedException(typeof(ArgumentNullException))]
241         public void TestAddKeyNull()
242         {
243             new IgnoreCaseDictionary<string>().Add(new KeyValuePair<string, string>(null, "TestValue"));
244         }
245
246         /// <summary>
247         /// Addメソッドテストケース(重複)。
248         /// </summary>
249         [TestMethod]
250         [ExpectedException(typeof(ArgumentException))]
251         public void TestAddDuplicate()
252         {
253             // 大文字小文字が異なるキーでも重複と判断する
254             IgnoreCaseDictionary<string> d = new IgnoreCaseDictionary<string>();
255             d.Add("TestKey", "TestValue");
256             d.Add("tESTkEY", "TestValue2");
257         }
258
259         /// <summary>
260         /// Addメソッドテストケース(KeyValuePairのKeyが重複)。
261         /// </summary>
262         [TestMethod]
263         [ExpectedException(typeof(ArgumentException))]
264         public void TestAddKeyDuplicate()
265         {
266             // 大文字小文字が異なるキーでも重複と判断する
267             IgnoreCaseDictionary<string> d = new IgnoreCaseDictionary<string>();
268             d.Add(new KeyValuePair<string, string>("TestKey", "TestValue"));
269             d.Add(new KeyValuePair<string, string>("tESTkEY", "TestValue2"));
270         }
271
272         /// <summary>
273         /// ContainsKeyメソッドテストケース(正常系)。
274         /// </summary>
275         [TestMethod]
276         public void TestContainsKey()
277         {
278             IgnoreCaseDictionary<string> d = new IgnoreCaseDictionary<string>();
279             Assert.IsFalse(d.ContainsKey("TestKey"));
280             d.Add("TestKey", "TestValue");
281             Assert.IsTrue(d.ContainsKey("TestKey"));
282             Assert.IsTrue(d.ContainsKey("tESTkEy"));
283             Assert.IsFalse(d.ContainsKey("TestKey2"));
284         }
285
286         /// <summary>
287         /// ContainsKeyメソッドテストケース(null値)。
288         /// </summary>
289         [TestMethod]
290         [ExpectedException(typeof(ArgumentNullException))]
291         public void TestContainsKeyNull()
292         {
293             new IgnoreCaseDictionary<string>().ContainsKey(null);
294         }
295
296         /// <summary>
297         /// Removeメソッドテストケース(正常系)。
298         /// </summary>
299         [TestMethod]
300         public void TestRemove()
301         {
302             // IDictionaryのRemoveメソッド
303             IgnoreCaseDictionary<string> d = new IgnoreCaseDictionary<string>();
304             d.Add("TestKey", "TestValue");
305             d.Add("tESTkEY2", "TestValue2");
306             Assert.AreEqual(2, d.Count);
307             Assert.IsTrue(d.ContainsKey("TestKey"));
308             Assert.IsTrue(d.ContainsKey("tESTkEY2"));
309
310             Assert.IsTrue(d.Remove("tEstKey"));
311             Assert.AreEqual(1, d.Count);
312             Assert.IsFalse(d.ContainsKey("TestKey"));
313             Assert.IsTrue(d.ContainsKey("tESTkEY2"));
314
315             Assert.IsFalse(d.Remove("tESTkEY3"));
316             Assert.AreEqual(1, d.Count);
317             Assert.IsTrue(d.ContainsKey("tESTkEY2"));
318
319             // ICollectionのRemoveメソッド
320             Assert.IsFalse(d.Remove(new KeyValuePair<string, string>("tESTkEY3", "TestValue2")));
321             Assert.AreEqual(1, d.Count);
322             Assert.IsTrue(d.ContainsKey("tESTkEY2"));
323
324             Assert.IsTrue(d.Remove(new KeyValuePair<string, string>("TestKey2", "TestValue2")));
325             Assert.AreEqual(0, d.Count);
326             Assert.IsFalse(d.ContainsKey("tESTkEY2"));
327         }
328
329         /// <summary>
330         /// Removeメソッドテストケース(null値)。
331         /// </summary>
332         [TestMethod]
333         [ExpectedException(typeof(ArgumentNullException))]
334         public void TestRemoveNull()
335         {
336             new IgnoreCaseDictionary<string>().Remove(null);
337         }
338
339         /// <summary>
340         /// TryGetValueメソッドテストケース(正常系)。
341         /// </summary>
342         [TestMethod]
343         public void TestTryGetValue()
344         {
345             IgnoreCaseDictionary<string> d = new IgnoreCaseDictionary<string>();
346             string value;
347
348             Assert.IsFalse(d.TryGetValue("TestKey", out value));
349             Assert.IsNull(value);
350
351             d.Add("TestKey", "TestValue");
352             Assert.IsTrue(d.TryGetValue("TestKey", out value));
353             Assert.AreEqual("TestValue", value);
354
355             Assert.IsFalse(d.TryGetValue("TestKey2", out value));
356             Assert.IsNull(value);
357
358             Assert.IsTrue(d.TryGetValue("tESTkEy", out value));
359             Assert.AreEqual("TestValue", value);
360         }
361
362         /// <summary>
363         /// TryGetValueメソッドテストケース(null値)。
364         /// </summary>
365         [TestMethod]
366         [ExpectedException(typeof(ArgumentNullException))]
367         public void TestTryGetValueNull()
368         {
369             string dummy;
370             new IgnoreCaseDictionary<string>().TryGetValue(null, out dummy);
371         }
372
373         /// <summary>
374         /// Clearメソッドテストケース。
375         /// </summary>
376         [TestMethod]
377         public void TestClear()
378         {
379             // 全データが削除されること、またラップしているオブジェクトは維持されること
380             IDictionary<string, string> inner = new Dictionary<string, string>();
381             IgnoreCaseDictionary<string> d = new IgnoreCaseDictionary<string>(inner);
382             d.Add("TestKey", "TestValue");
383             d.Add("tESTkEY2", "TestValue2");
384             Assert.AreEqual(2, d.Count);
385             Assert.AreSame(inner, d.Dictionary);
386
387             d.Clear();
388             Assert.AreEqual(0, d.Count);
389             Assert.AreSame(inner, d.Dictionary);
390         }
391
392         /// <summary>
393         /// Containsメソッドテストケース。
394         /// </summary>
395         [TestMethod]
396         public void TestContains()
397         {
398             IgnoreCaseDictionary<string> d = new IgnoreCaseDictionary<string>();
399             Assert.IsFalse(d.Contains(new KeyValuePair<string, string>("TestKey", "TestValue")));
400             d.Add("TestKey", "TestValue");
401             Assert.IsTrue(d.Contains(new KeyValuePair<string, string>("TestKey", "TestValue")));
402             Assert.IsTrue(d.Contains(new KeyValuePair<string, string>("tESTkEy", "TestValue")));
403             Assert.IsFalse(d.Contains(new KeyValuePair<string, string>("TestKey2", "TestValue")));
404             Assert.IsFalse(d.Contains(new KeyValuePair<string, string>(null, "TestValue")));
405         }
406
407         /// <summary>
408         /// CopyToメソッドテストケース(正常系)。
409         /// </summary>
410         [TestMethod]
411         public void TestCopyTo()
412         {
413             IgnoreCaseDictionary<string> d = new IgnoreCaseDictionary<string>();
414             d.Add("TestKey", "TestValue");
415             d.Add("tESTkEY2", "TestValue2");
416             KeyValuePair<string, string>[] array = new KeyValuePair<string, string>[5];
417             d.CopyTo(array, 3);
418             Assert.IsNull(array[0].Key);
419             Assert.IsNull(array[0].Value);
420             Assert.IsNull(array[1].Key);
421             Assert.IsNull(array[1].Value);
422             Assert.IsNull(array[2].Key);
423             Assert.IsNull(array[2].Value);
424             Assert.AreEqual("TestKey", array[3].Key);
425             Assert.AreEqual("TestValue", array[3].Value);
426             Assert.AreEqual("tESTkEY2", array[4].Key);
427             Assert.AreEqual("TestValue2", array[4].Value);
428         }
429
430         /// <summary>
431         /// CopyToメソッドテストケース(null値)。
432         /// </summary>
433         [TestMethod]
434         [ExpectedException(typeof(ArgumentNullException))]
435         public void TestCopyToNull()
436         {
437             new IgnoreCaseDictionary<string>().CopyTo(null, 0);
438         }
439
440         /// <summary>
441         /// CopyToメソッドテストケース(インデックスがマイナス値)。
442         /// </summary>
443         [TestMethod]
444         [ExpectedException(typeof(ArgumentOutOfRangeException))]
445         public void TestCopyToOutOfRange()
446         {
447             new IgnoreCaseDictionary<string>().CopyTo(new KeyValuePair<string, string>[5], -1);
448         }
449
450         /// <summary>
451         /// CopyToメソッドテストケース(領域不足)。
452         /// </summary>
453         [TestMethod]
454         [ExpectedException(typeof(ArgumentException))]
455         public void TestCopyToOverflow()
456         {
457             IgnoreCaseDictionary<string> d = new IgnoreCaseDictionary<string>();
458             d.Add("TestKey", "TestValue");
459             d.Add("tESTkEY2", "TestValue2");
460             d.CopyTo(new KeyValuePair<string, string>[5], 4);
461         }
462
463         #endregion
464
465         #region ラップするインスタンスを参照するメソッドテストケース
466
467         /// <summary>
468         /// GetEnumeratorメソッドテストケース。
469         /// </summary>
470         [TestMethod]
471         public void TestGetEnumerator()
472         {
473             // ラップするIDictionaryと同じ値であること
474             IDictionary<string, string> inner = new Dictionary<string, string>();
475             inner.Add("TestKey", "TestValue");
476             IgnoreCaseDictionary<string> d = new IgnoreCaseDictionary<string>(inner);
477             Assert.AreEqual(inner.GetEnumerator(), d.GetEnumerator());
478         }
479
480         #endregion
481     }
482 }