OSDN Git Service

5d6ffd101ed8fc97f7c12f0487a80cbe184119dc
[wptscs/wpts.git] / WptscsTest / Utilities / FormUtilsTest.cs
1 // ================================================================================================
2 // <summary>
3 //      FormUtilsのテストクラスソース。</summary>
4 //
5 // <copyright file="FormUtilsTest.cs" company="honeplusのメモ帳">
6 //      Copyright (C) 2012 Honeplus. All rights reserved.</copyright>
7 // <author>
8 //      Honeplus</author>
9 // ================================================================================================
10
11 namespace Honememo.Wptscs.Utilities
12 {
13     using System;
14     using System.Windows.Forms;
15     using Honememo.Wptscs.Utilities;
16     using NUnit.Framework;
17
18     /// <summary>
19     /// FormUtilsのテストクラスです。
20     /// </summary>
21     /// <remarks>
22     /// その性質上、画面周りのメソッドならびに設定ファイル関連のメソッドについてはテストケースが作成できていない。
23     /// これらのメソッドに手を入れる際は注意すること。
24     /// </remarks>
25     [TestFixture]
26     public class FormUtilsTest
27     {
28         #region リソース関連テストケース
29
30         /// <summary>
31         /// ReplaceInvalidFileNameCharsメソッドテストケース。
32         /// </summary>
33         [Test]
34         public void TestApplicationName()
35         {
36             // ※ バージョンが変わるごとにバージョン表記の部分を書き換えるのは面倒なので置換
37             Assert.AreEqual(
38                 "Wikipedia 翻訳支援ツール VerX.XX",
39                 new System.Text.RegularExpressions.Regex("Ver[0-9]+\\.[0-9]+").Replace(FormUtils.ApplicationName(), "VerX.XX"));
40         }
41
42         /// <summary>
43         /// ReplaceInvalidFileNameCharsメソッドテストケース。
44         /// </summary>
45         [Test]
46         public void TestReplaceInvalidFileNameChars()
47         {
48             Assert.AreEqual("C__test_test.doc", FormUtils.ReplaceInvalidFileNameChars("C:\\test\\test.doc"));
49             Assert.AreEqual("_home_test_test.doc", FormUtils.ReplaceInvalidFileNameChars("/home/test/test.doc"));
50             Assert.AreEqual("______", FormUtils.ReplaceInvalidFileNameChars("*?\"<>|"));
51
52             // 一見普通のファイル名に見えるが、&nbsp;由来の半角スペース (u00a0) が含まれており問題を起こす
53             // 通常の半角スペース (u0020) に変換する
54             Assert.AreEqual("Fuji (Spacecraft).xml", FormUtils.ReplaceInvalidFileNameChars("Fuji (Spacecraft).xml"));
55         }
56
57         #endregion
58
59         #region null値許容メソッドテストケース
60
61         /// <summary>
62         /// ToStringメソッドテストケース。
63         /// </summary>
64         [Test]
65         public void TestToString()
66         {
67             // 引数二つ
68             Assert.IsNull(FormUtils.ToString(null, null));
69             Assert.IsNull(FormUtils.ToString(new DummyCell(), null));
70             Assert.AreEqual("null", FormUtils.ToString(new DummyCell(), "null"));
71             Assert.AreEqual("not null", FormUtils.ToString(new DummyCell { Value = "not null" }, "null"));
72             Assert.AreNotEqual("null", FormUtils.ToString(new DummyCell { Value = new object() }, "null"));
73
74             // 引数一つ
75             Assert.AreEqual(String.Empty, FormUtils.ToString(null));
76             Assert.AreEqual(String.Empty, FormUtils.ToString(new DummyCell()));
77             Assert.AreEqual("not null", FormUtils.ToString(new DummyCell { Value = "not null" }));
78             Assert.IsNotEmpty(FormUtils.ToString(new DummyCell { Value = new object() }));
79         }
80
81         #endregion
82
83         #region モッククラス
84
85         /// <summary>
86         /// DataGridViewCellテスト用のモッククラスです。
87         /// </summary>
88         public class DummyCell : DataGridViewCell
89         {
90         }
91
92         #endregion
93     }
94 }