OSDN Git Service

GetRequest.BuildUriWithQueryをUriQueryBuilderクラスに移動
authorKimura Youichi <kim.upsilon@bucyou.net>
Mon, 11 Dec 2023 17:49:58 +0000 (02:49 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Tue, 12 Dec 2023 17:44:58 +0000 (02:44 +0900)
OpenTween.Tests/Connection/GetRequestTest.cs
OpenTween.Tests/Connection/UriQueryBuilderTest.cs [new file with mode: 0644]
OpenTween/Connection/DeleteRequest.cs
OpenTween/Connection/GetRequest.cs
OpenTween/Connection/UriQueryBuilder.cs [new file with mode: 0644]

index db738b6..efad646 100644 (file)
@@ -46,36 +46,5 @@ namespace OpenTween.Connection
             Assert.Equal(HttpMethod.Get, requestMessage.Method);
             Assert.Equal(new("https://api.twitter.com/v1/statuses/show.json?id=12345"), requestMessage.RequestUri);
         }
-
-        [Fact]
-        public void BuildUriWithQuery_Test()
-        {
-            var uri = new Uri("https://example.com/hoge");
-            var query = new Dictionary<string, string>
-            {
-                ["foo"] = "bar",
-            };
-            Assert.Equal(new("https://example.com/hoge?foo=bar"), GetRequest.BuildUriWithQuery(uri, query));
-        }
-
-        [Fact]
-        public void BuildUriWithQuery_NullTest()
-        {
-            var uri = new Uri("https://example.com/hoge");
-            Assert.Equal(new("https://example.com/hoge"), GetRequest.BuildUriWithQuery(uri, null));
-        }
-
-        [Fact]
-        public void BuildUriWithQuery_CannotMergeTest()
-        {
-            var uri = new Uri("https://example.com/hoge?aaa=111");
-            var query = new Dictionary<string, string>
-            {
-                ["bbb"] = "222",
-            };
-            Assert.Throws<NotSupportedException>(
-                () => GetRequest.BuildUriWithQuery(uri, query)
-            );
-        }
     }
 }
diff --git a/OpenTween.Tests/Connection/UriQueryBuilderTest.cs b/OpenTween.Tests/Connection/UriQueryBuilderTest.cs
new file mode 100644 (file)
index 0000000..02eaca9
--- /dev/null
@@ -0,0 +1,61 @@
+// OpenTween - Client of Twitter
+// Copyright (c) 2023 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
+// All rights reserved.
+//
+// This file is part of OpenTween.
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program. If not, see <http://www.gnu.org/licenses/>, or write to
+// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+using System;
+using System.Collections.Generic;
+using Xunit;
+
+namespace OpenTween.Connection
+{
+    public class UriQueryBuilderTest
+    {
+        [Fact]
+        public void Build_Test()
+        {
+            var uri = new Uri("https://example.com/hoge");
+            var query = new Dictionary<string, string>
+            {
+                ["foo"] = "bar",
+            };
+            Assert.Equal(new("https://example.com/hoge?foo=bar"), UriQueryBuilder.Build(uri, query));
+        }
+
+        [Fact]
+        public void Build_NullTest()
+        {
+            var uri = new Uri("https://example.com/hoge");
+            Assert.Equal(new("https://example.com/hoge"), UriQueryBuilder.Build(uri, null));
+        }
+
+        [Fact]
+        public void Build_CannotMergeTest()
+        {
+            var uri = new Uri("https://example.com/hoge?aaa=111");
+            var query = new Dictionary<string, string>
+            {
+                ["bbb"] = "222",
+            };
+            Assert.Throws<NotSupportedException>(
+                () => UriQueryBuilder.Build(uri, query)
+            );
+        }
+    }
+}
index f155028..e8bd353 100644 (file)
@@ -39,7 +39,7 @@ namespace OpenTween.Connection
             => new()
             {
                 Method = HttpMethod.Delete,
-                RequestUri = GetRequest.BuildUriWithQuery(new(baseUri, this.RequestUri), this.Query),
+                RequestUri = UriQueryBuilder.Build(new(baseUri, this.RequestUri), this.Query),
             };
     }
 }
index 018354a..48682c3 100644 (file)
@@ -39,18 +39,7 @@ namespace OpenTween.Connection
             => new()
             {
                 Method = HttpMethod.Get,
-                RequestUri = BuildUriWithQuery(new(baseUri, this.RequestUri), this.Query),
+                RequestUri = UriQueryBuilder.Build(new(baseUri, this.RequestUri), this.Query),
             };
-
-        public static Uri BuildUriWithQuery(Uri uri, IEnumerable<KeyValuePair<string, string>>? query)
-        {
-            if (query == null)
-                return uri;
-
-            if (!MyCommon.IsNullOrEmpty(uri.Query))
-                throw new NotSupportedException("Merging uri query is not supported");
-
-            return new Uri(uri, "?" + MyCommon.BuildQueryString(query));
-        }
     }
 }
diff --git a/OpenTween/Connection/UriQueryBuilder.cs b/OpenTween/Connection/UriQueryBuilder.cs
new file mode 100644 (file)
index 0000000..2c30dd3
--- /dev/null
@@ -0,0 +1,42 @@
+// OpenTween - Client of Twitter
+// Copyright (c) 2023 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
+// All rights reserved.
+//
+// This file is part of OpenTween.
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program. If not, see <http://www.gnu.org/licenses/>, or write to
+// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+#nullable enable
+
+using System;
+using System.Collections.Generic;
+
+namespace OpenTween.Connection
+{
+    public static class UriQueryBuilder
+    {
+        public static Uri Build(Uri uri, IEnumerable<KeyValuePair<string, string>>? query)
+        {
+            if (query == null)
+                return uri;
+
+            if (!MyCommon.IsNullOrEmpty(uri.Query))
+                throw new NotSupportedException("Merging uri query is not supported");
+
+            return new(uri, "?" + MyCommon.BuildQueryString(query));
+        }
+    }
+}