1 // ================================================================================================
3 // FormUtilsのテストクラスソース。</summary>
5 // <copyright file="FormUtilsTest.cs" company="honeplusのメモ帳">
6 // Copyright (C) 2010 Honeplus. All rights reserved.</copyright>
9 // ================================================================================================
11 namespace Honememo.Utilities
14 using System.Windows.Forms;
15 using NUnit.Framework;
18 /// FormUtilsのテストクラスです。
21 /// その性質上、画面周りのメソッドならびに設定ファイル関連のメソッドについてはテストケースが作成できていない。
22 /// これらのメソッドに手を入れる際は注意すること。
25 public class FormUtilsTest
28 /// Websiteテスト用のモッククラスです。
30 public class DummyCell : DataGridViewCell
37 /// ReplaceInvalidFileNameCharsメソッドテストケース。
40 public void TestApplicationName()
42 // ※ バージョンが変わるごとにバージョン表記の部分を書き換えるのは面倒なので置換
44 "Wikipedia 翻訳支援ツール VerX.XX",
45 new System.Text.RegularExpressions.Regex("Ver[0-9]+\\.[0-9]+")
46 .Replace(FormUtils.ApplicationName(), "VerX.XX"));
50 /// ReplaceInvalidFileNameCharsメソッドテストケース。
53 public void TestReplaceInvalidFileNameChars()
55 Assert.AreEqual("C__test_test.doc", FormUtils.ReplaceInvalidFileNameChars("C:\\test\\test.doc"));
56 Assert.AreEqual("_home_test_test.doc", FormUtils.ReplaceInvalidFileNameChars("/home/test/test.doc"));
57 Assert.AreEqual("______", FormUtils.ReplaceInvalidFileNameChars("*?\"<>|"));
62 #region null値許容メソッドテストケース
65 /// ToStringメソッドテストケース。
68 public void TestToString()
71 Assert.IsNull(FormUtils.ToString(null, null));
72 Assert.IsNull(FormUtils.ToString(new DummyCell(), null));
73 Assert.AreEqual("null", FormUtils.ToString(new DummyCell(), "null"));
74 Assert.AreEqual("not null", FormUtils.ToString(new DummyCell { Value = "not null" }, "null"));
75 Assert.AreNotEqual("null", FormUtils.ToString(new DummyCell { Value = new object() }, "null"));
78 Assert.AreEqual(String.Empty, FormUtils.ToString(null));
79 Assert.AreEqual(String.Empty, FormUtils.ToString(new DummyCell()));
80 Assert.AreEqual("not null", FormUtils.ToString(new DummyCell { Value = "not null" }));
81 Assert.IsNotEmpty(FormUtils.ToString(new DummyCell { Value = new object() }));