OSDN Git Service

不要な ListView.SelectedIndices への参照を削除
[opentween/open-tween.git] / OpenTween.Tests / HashtagManageTest.cs
index 1756f2a..384c286 100644 (file)
@@ -38,106 +38,114 @@ namespace OpenTween
         {
             var hashtags = new[] { "#foo", "#bar" };
 
-            using (var atDialog = new AtIdSupplement())
-            using (var hashDialog = new HashtagManage(atDialog, hashtags, "", false, false, false))
-            {
-                hashDialog.RunSilent = true;
-
-                Assert.Equal(new[] { "#foo", "#bar" }, hashDialog.HistoryHashList.Items.Cast<string>());
-                Assert.Equal(new[] { "#foo", "#bar" }, hashDialog.HashHistories);
-            }
+            using var atDialog = new AtIdSupplement();
+            using var hashDialog = new HashtagManage(atDialog, hashtags, "", false, false, false);
+            hashDialog.RunSilent = true;
+
+            Assert.Equal(new[] { "#foo", "#bar" }, hashDialog.HistoryHashList.Items.Cast<string>());
+            Assert.Equal(new[] { "#foo", "#bar" }, hashDialog.HashHistories);
         }
 
         [Fact]
         public void InitHashtagHistory_EmptyTest()
         {
-            var hashtags = new string[0];
+            var hashtags = Array.Empty<string>();
 
-            using (var atDialog = new AtIdSupplement())
-            using (var hashDialog = new HashtagManage(atDialog, hashtags, "", false, false, false))
-            {
-                hashDialog.RunSilent = true;
+            using var atDialog = new AtIdSupplement();
+            using var hashDialog = new HashtagManage(atDialog, hashtags, "", false, false, false);
+            hashDialog.RunSilent = true;
 
-                Assert.Empty(hashDialog.HistoryHashList.Items);
-                Assert.Empty(hashDialog.HashHistories);
-            }
+            Assert.Empty(hashDialog.HistoryHashList.Items);
+            Assert.Empty(hashDialog.HashHistories);
         }
 
         [Fact]
         public void AddHashtag_Test()
         {
-            using (var atDialog = new AtIdSupplement())
-            using (var hashDialog = new HashtagManage(atDialog, new string[0], "", false, false, false))
-            {
-                hashDialog.RunSilent = true;
+            using var atDialog = new AtIdSupplement();
+            using var hashDialog = new HashtagManage(atDialog, Array.Empty<string>(), "", false, false, false);
+            hashDialog.RunSilent = true;
 
-                TestUtils.FireEvent(hashDialog.AddButton, "Click"); // 「新規 (&N)」ボタン
+            TestUtils.FireEvent(hashDialog.AddButton, "Click"); // 「新規 (&N)」ボタン
 
-                hashDialog.UseHashText.Text = "#OpenTween";
+            hashDialog.UseHashText.Text = "#OpenTween";
 
-                TestUtils.FireEvent(hashDialog.PermOK_Button, "Click"); // 「詳細」グループ内の「OK」ボタン
+            TestUtils.FireEvent(hashDialog.PermOK_Button, "Click"); // 「詳細」グループ内の「OK」ボタン
 
-                Assert.Equal(new[] { "#OpenTween" }, hashDialog.HistoryHashList.Items.Cast<string>());
-                Assert.Equal(new[] { "#OpenTween" }, hashDialog.HashHistories);
-            }
+            Assert.Equal(new[] { "#OpenTween" }, hashDialog.HistoryHashList.Items.Cast<string>());
+            Assert.Equal(new[] { "#OpenTween" }, hashDialog.HashHistories);
         }
 
         [Fact]
         public void AddHashtag_FullWidthTest()
         {
-            using (var atDialog = new AtIdSupplement())
-            using (var hashDialog = new HashtagManage(atDialog, new string[0], "", false, false, false))
-            {
-                hashDialog.RunSilent = true;
+            using var atDialog = new AtIdSupplement();
+            using var hashDialog = new HashtagManage(atDialog, Array.Empty<string>(), "", false, false, false);
+            hashDialog.RunSilent = true;
+
+            TestUtils.FireEvent(hashDialog.AddButton, "Click"); // 「新規 (&N)」ボタン
+
+            hashDialog.UseHashText.Text = "#ほげほげ";
+
+            TestUtils.FireEvent(hashDialog.PermOK_Button, "Click"); // 「詳細」グループ内の「OK」ボタン
+
+            Assert.Equal(new[] { "#ほげほげ" }, hashDialog.HistoryHashList.Items.Cast<string>());
+            Assert.Equal(new[] { "#ほげほげ" }, hashDialog.HashHistories);
+        }
+
+        [Fact]
+        public void AddHashtag_CombiningCharacterSequenceTest()
+        {
+            // ハッシュタグを表す「#」の直後に結合文字 (濁点など) が続いた場合に対するテスト
 
-                TestUtils.FireEvent(hashDialog.AddButton, "Click"); // 「新規 (&N)」ボタン
+            using var atDialog = new AtIdSupplement();
+            using var hashDialog = new HashtagManage(atDialog, Array.Empty<string>(), "", false, false, false);
+            hashDialog.RunSilent = true;
 
-                hashDialog.UseHashText.Text = "#ほげほげ";
+            TestUtils.FireEvent(hashDialog.AddButton, "Click"); // 「新規 (&N)」ボタン
 
-                TestUtils.FireEvent(hashDialog.PermOK_Button, "Click"); // 「詳細」グループ内の「OK」ボタン
+            // どんちき└(^ω^ )┐♫ ┌( ^ω^)┘♫どんちき
+            hashDialog.UseHashText.Text = "#゛t゛e゛s゛a゛b゛u゛";
 
-                Assert.Equal(new[] { "#ほげほげ" }, hashDialog.HistoryHashList.Items.Cast<string>());
-                Assert.Equal(new[] { "#ほげほげ" }, hashDialog.HashHistories);
-            }
+            TestUtils.FireEvent(hashDialog.PermOK_Button, "Click"); // 「詳細」グループ内の「OK」ボタン
+
+            Assert.Equal(new[] { "#゛t゛e゛s゛a゛b゛u゛" }, hashDialog.HistoryHashList.Items.Cast<string>());
+            Assert.Equal(new[] { "#゛t゛e゛s゛a゛b゛u゛" }, hashDialog.HashHistories);
         }
 
         [Fact]
         public void AddHashtag_MultipleTest()
         {
-            using (var atDialog = new AtIdSupplement())
-            using (var hashDialog = new HashtagManage(atDialog, new string[0], "", false, false, false))
-            {
-                hashDialog.RunSilent = true;
+            using var atDialog = new AtIdSupplement();
+            using var hashDialog = new HashtagManage(atDialog, Array.Empty<string>(), "", false, false, false);
+            hashDialog.RunSilent = true;
 
-                TestUtils.FireEvent(hashDialog.AddButton, "Click"); // 「新規 (&N)」ボタン
+            TestUtils.FireEvent(hashDialog.AddButton, "Click"); // 「新規 (&N)」ボタン
 
-                hashDialog.UseHashText.Text = "#foo #bar";
+            hashDialog.UseHashText.Text = "#foo #bar";
 
-                TestUtils.FireEvent(hashDialog.PermOK_Button, "Click"); // 「詳細」グループ内の「OK」ボタン
+            TestUtils.FireEvent(hashDialog.PermOK_Button, "Click"); // 「詳細」グループ内の「OK」ボタン
 
-                Assert.Equal(new[] { "#foo #bar" }, hashDialog.HistoryHashList.Items.Cast<string>());
-                Assert.Equal(new[] { "#foo #bar" }, hashDialog.HashHistories);
-            }
+            Assert.Equal(new[] { "#foo #bar" }, hashDialog.HistoryHashList.Items.Cast<string>());
+            Assert.Equal(new[] { "#foo #bar" }, hashDialog.HashHistories);
         }
 
         [Fact]
         public void AddHashtag_InvalidTest()
         {
-            using (var atDialog = new AtIdSupplement())
-            using (var hashDialog = new HashtagManage(atDialog, new string[0], "", false, false, false))
-            {
-                hashDialog.RunSilent = true;
+            using var atDialog = new AtIdSupplement();
+            using var hashDialog = new HashtagManage(atDialog, Array.Empty<string>(), "", false, false, false);
+            hashDialog.RunSilent = true;
 
-                TestUtils.FireEvent(hashDialog.AddButton, "Click"); // 「新規 (&N)」ボタン
+            TestUtils.FireEvent(hashDialog.AddButton, "Click"); // 「新規 (&N)」ボタン
 
-                hashDialog.UseHashText.Text = "hogehoge";
+            hashDialog.UseHashText.Text = "hogehoge";
 
-                TestUtils.FireEvent(hashDialog.PermOK_Button, "Click"); // 「詳細」グループ内の「OK」ボタン
-                // 実際にはここでエラーメッセージが出る
+            TestUtils.FireEvent(hashDialog.PermOK_Button, "Click"); // 「詳細」グループ内の「OK」ボタン
+                                                                    // 実際にはここでエラーメッセージが出る
 
-                Assert.Empty(hashDialog.HistoryHashList.Items);
-                Assert.Empty(hashDialog.HashHistories);
-            }
+            Assert.Empty(hashDialog.HistoryHashList.Items);
+            Assert.Empty(hashDialog.HashHistories);
         }
 
         [Fact]
@@ -145,22 +153,20 @@ namespace OpenTween
         {
             var hashtags = new[] { "#foo", "#bar" };
 
-            using (var atDialog = new AtIdSupplement())
-            using (var hashDialog = new HashtagManage(atDialog, hashtags, "", false, false, false))
-            {
-                hashDialog.RunSilent = true;
+            using var atDialog = new AtIdSupplement();
+            using var hashDialog = new HashtagManage(atDialog, hashtags, "", false, false, false);
+            hashDialog.RunSilent = true;
 
-                hashDialog.HistoryHashList.SelectedIndices.Add(0);
+            hashDialog.HistoryHashList.SelectedIndices.Add(0);
 
-                TestUtils.FireEvent(hashDialog.EditButton, "Click"); // 「編集(&E)」ボタン
+            TestUtils.FireEvent(hashDialog.EditButton, "Click"); // 「編集(&E)」ボタン
 
-                hashDialog.UseHashText.Text = "#hoge";
+            hashDialog.UseHashText.Text = "#hoge";
 
-                TestUtils.FireEvent(hashDialog.PermOK_Button, "Click"); // 「詳細」グループ内の「OK」ボタン
+            TestUtils.FireEvent(hashDialog.PermOK_Button, "Click"); // 「詳細」グループ内の「OK」ボタン
 
-                Assert.Equal(new[] { "#hoge", "#bar" }, hashDialog.HistoryHashList.Items.Cast<string>());
-                Assert.Equal(new[] { "#hoge", "#bar" }, hashDialog.HashHistories);
-            }
+            Assert.Equal(new[] { "#hoge", "#bar" }, hashDialog.HistoryHashList.Items.Cast<string>());
+            Assert.Equal(new[] { "#hoge", "#bar" }, hashDialog.HashHistories);
         }
 
         [Fact]
@@ -168,18 +174,34 @@ namespace OpenTween
         {
             var hashtags = new[] { "#foo", "#bar" };
 
-            using (var atDialog = new AtIdSupplement())
-            using (var hashDialog = new HashtagManage(atDialog, hashtags, "", false, false, false))
-            {
-                hashDialog.RunSilent = true;
+            using var atDialog = new AtIdSupplement();
+            using var hashDialog = new HashtagManage(atDialog, hashtags, "", false, false, false);
+            hashDialog.RunSilent = true;
+
+            hashDialog.HistoryHashList.SelectedIndices.Add(1);
+
+            TestUtils.FireEvent(hashDialog.DeleteButton, "Click"); // 「削除(&D)」ボタン
+
+            Assert.Equal(new[] { "#foo" }, hashDialog.HistoryHashList.Items.Cast<string>());
+            Assert.Equal(new[] { "#foo" }, hashDialog.HashHistories);
+        }
+
+        [Fact]
+        public void DeleteHashtag_MultipleTest()
+        {
+            var hashtags = new[] { "#foo", "#bar", "#baz" };
+
+            using var atDialog = new AtIdSupplement();
+            using var hashDialog = new HashtagManage(atDialog, hashtags, "", false, false, false);
+            hashDialog.RunSilent = true;
 
-                hashDialog.HistoryHashList.SelectedIndices.Add(1);
+            hashDialog.HistoryHashList.SelectedIndices.Add(2);
+            hashDialog.HistoryHashList.SelectedIndices.Add(1);
 
-                TestUtils.FireEvent(hashDialog.DeleteButton, "Click"); // 「削除(&D)」ボタン
+            TestUtils.FireEvent(hashDialog.DeleteButton, "Click"); // 「削除(&D)」ボタン
 
-                Assert.Equal(new[] { "#foo" }, hashDialog.HistoryHashList.Items.Cast<string>());
-                Assert.Equal(new[] { "#foo" }, hashDialog.HashHistories);
-            }
+            Assert.Equal(new[] { "#foo" }, hashDialog.HistoryHashList.Items.Cast<string>());
+            Assert.Equal(new[] { "#foo" }, hashDialog.HashHistories);
         }
 
         [Fact]
@@ -187,18 +209,16 @@ namespace OpenTween
         {
             var hashtags = new[] { "#foo", "#bar" };
 
-            using (var atDialog = new AtIdSupplement())
-            using (var hashDialog = new HashtagManage(atDialog, hashtags, "", false, false, false))
-            {
-                hashDialog.RunSilent = true;
+            using var atDialog = new AtIdSupplement();
+            using var hashDialog = new HashtagManage(atDialog, hashtags, "", false, false, false);
+            hashDialog.RunSilent = true;
 
-                // ハッシュタグを選択していない状態
+            // ハッシュタグを選択していない状態
 
-                TestUtils.FireEvent(hashDialog.DeleteButton, "Click"); // 「削除(&D)」ボタン
+            TestUtils.FireEvent(hashDialog.DeleteButton, "Click"); // 「削除(&D)」ボタン
 
-                Assert.Equal(new[] { "#foo", "#bar" }, hashDialog.HistoryHashList.Items.Cast<string>());
-                Assert.Equal(new[] { "#foo", "#bar" }, hashDialog.HashHistories);
-            }
+            Assert.Equal(new[] { "#foo", "#bar" }, hashDialog.HistoryHashList.Items.Cast<string>());
+            Assert.Equal(new[] { "#foo", "#bar" }, hashDialog.HashHistories);
         }
 
         [Fact]
@@ -206,47 +226,43 @@ namespace OpenTween
         {
             var hashtags = new[] { "#foo" };
 
-            using (var atDialog = new AtIdSupplement())
-            using (var hashDialog = new HashtagManage(atDialog, hashtags, "", false, false, false))
-            {
-                hashDialog.RunSilent = true;
+            using var atDialog = new AtIdSupplement();
+            using var hashDialog = new HashtagManage(atDialog, hashtags, "", false, false, false);
+            hashDialog.RunSilent = true;
 
-                hashDialog.HistoryHashList.SelectedIndices.Add(0);
+            hashDialog.HistoryHashList.SelectedIndices.Add(0);
 
-                TestUtils.FireEvent(hashDialog.UnSelectButton, "Click"); // 「非使用(&U)」ボタン
+            TestUtils.FireEvent(hashDialog.UnSelectButton, "Click"); // 「非使用(&U)」ボタン
 
-                Assert.Empty(hashDialog.HistoryHashList.SelectedIndices);
-            }
+            Assert.Empty(hashDialog.HistoryHashList.SelectedIndices);
         }
 
         [Fact]
         public void EditModeSwitch_Test()
         {
-            using (var atDialog = new AtIdSupplement())
-            using (var hashDialog = new HashtagManage(atDialog, new string[0], "", false, false, false))
-            {
-                hashDialog.RunSilent = true;
+            using var atDialog = new AtIdSupplement();
+            using var hashDialog = new HashtagManage(atDialog, Array.Empty<string>(), "", false, false, false);
+            hashDialog.RunSilent = true;
 
-                Assert.True(hashDialog.GroupHashtag.Enabled);
-                Assert.True(hashDialog.TableLayoutButtons.Enabled);
-                Assert.False(hashDialog.GroupDetail.Enabled);
+            Assert.True(hashDialog.GroupHashtag.Enabled);
+            Assert.True(hashDialog.TableLayoutButtons.Enabled);
+            Assert.False(hashDialog.GroupDetail.Enabled);
 
-                TestUtils.FireEvent(hashDialog.AddButton, "Click"); // 「新規 (&N)」ボタン
+            TestUtils.FireEvent(hashDialog.AddButton, "Click"); // 「新規 (&N)」ボタン
 
-                // 編集モードに入る
-                Assert.False(hashDialog.GroupHashtag.Enabled);
-                Assert.False(hashDialog.TableLayoutButtons.Enabled);
-                Assert.True(hashDialog.GroupDetail.Enabled);
+            // 編集モードに入る
+            Assert.False(hashDialog.GroupHashtag.Enabled);
+            Assert.False(hashDialog.TableLayoutButtons.Enabled);
+            Assert.True(hashDialog.GroupDetail.Enabled);
 
-                hashDialog.UseHashText.Text = "#hogehoge";
+            hashDialog.UseHashText.Text = "#hogehoge";
 
-                TestUtils.FireEvent(hashDialog.PermOK_Button, "Click"); // 「詳細」グループ内の「OK」ボタン
+            TestUtils.FireEvent(hashDialog.PermOK_Button, "Click"); // 「詳細」グループ内の「OK」ボタン
 
-                // 編集モードから抜ける
-                Assert.True(hashDialog.GroupHashtag.Enabled);
-                Assert.True(hashDialog.TableLayoutButtons.Enabled);
-                Assert.False(hashDialog.GroupDetail.Enabled);
-            }
+            // 編集モードから抜ける
+            Assert.True(hashDialog.GroupHashtag.Enabled);
+            Assert.True(hashDialog.TableLayoutButtons.Enabled);
+            Assert.False(hashDialog.GroupDetail.Enabled);
         }
     }
 }