OSDN Git Service

テストコードのMemberDataにTheoryData<T>を使用する
authorKimura Youichi <kim.upsilon@bucyou.net>
Wed, 28 Aug 2019 19:18:47 +0000 (04:18 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Wed, 28 Aug 2019 19:26:42 +0000 (04:26 +0900)
OpenTween.Tests/Api/ApiLimitTest.cs
OpenTween.Tests/Api/TwitterApiStatusTest.cs
OpenTween.Tests/MyCommonTest.cs

index 1e008e0..17d0359 100644 (file)
@@ -30,18 +30,15 @@ namespace OpenTween.Api
 {
     public class ApiLimitTest
     {
-        public static IEnumerable<object[]> Equals_TestCase
+        public static readonly TheoryData<object, bool> Equals_TestCase = new TheoryData<object, bool>
         {
-            get
-            {
-                yield return new object[] { new ApiLimit(150, 100, new DateTimeUtc(2013, 1, 1, 0, 0, 0)), true };
-                yield return new object[] { new ApiLimit(350, 100, new DateTimeUtc(2013, 1, 1, 0, 0, 0)), false };
-                yield return new object[] { new ApiLimit(150, 150, new DateTimeUtc(2013, 1, 1, 0, 0, 0)), false };
-                yield return new object[] { new ApiLimit(150, 100, new DateTimeUtc(2012, 12, 31, 0, 0, 0)), false };
-                yield return new object[] { null, false };
-                yield return new object[] { new object(), false };
-            }
-        }
+            { new ApiLimit(150, 100, new DateTimeUtc(2013, 1, 1, 0, 0, 0)), true },
+            { new ApiLimit(350, 100, new DateTimeUtc(2013, 1, 1, 0, 0, 0)), false },
+            { new ApiLimit(150, 150, new DateTimeUtc(2013, 1, 1, 0, 0, 0)), false },
+            { new ApiLimit(150, 100, new DateTimeUtc(2012, 12, 31, 0, 0, 0)), false },
+            { null, false },
+            { new object(), false },
+        };
 
         [Theory]
         [MemberData(nameof(Equals_TestCase))]
index 310651c..105a5d0 100644 (file)
@@ -49,43 +49,40 @@ namespace OpenTween.Api
             Assert.Equal(TwitterApiAccessLevel.Anonymous, apiStatus.AccessLevel);
         }
 
-        public static IEnumerable<object[]> ParseRateLimit_TestCase
+        public static readonly TheoryData<IDictionary<string, string>, ApiLimit> ParseRateLimit_TestCase = new TheoryData<IDictionary<string, string>, ApiLimit>
         {
-            get
             {
-                yield return new object[] {
-                    new Dictionary<string, string> {
-                        ["X-RateLimit-Limit"] = "150",
-                        ["X-RateLimit-Remaining"] = "100",
-                        ["X-RateLimit-Reset"] = "1356998400",
-                    },
-                    new ApiLimit(150, 100, new DateTimeUtc(2013, 1, 1, 0, 0, 0)),
-                };
-                yield return new object[] {
-                    new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase) {
-                        ["x-ratelimit-limit"] = "150",
-                        ["x-ratelimit-remaining"] = "100",
-                        ["x-ratelimit-reset"] = "1356998400",
-                    },
-                    new ApiLimit(150, 100, new DateTimeUtc(2013, 1, 1, 0, 0, 0)),
-                };
-                yield return new object[] {
-                    new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase) {
-                        ["X-RateLimit-Limit"] = "150",
-                        ["X-RateLimit-Remaining"] = "100",
-                        ["X-RateLimit-Reset"] = "hogehoge",
-                    },
-                    null,
-                };
-                yield return new object[] {
-                    new Dictionary<string, string> {
-                        ["X-RateLimit-Limit"] = "150",
-                        ["X-RateLimit-Remaining"] = "100",
-                    },
-                    null,
-                };
-            }
-        }
+                new Dictionary<string, string> {
+                    ["X-RateLimit-Limit"] = "150",
+                    ["X-RateLimit-Remaining"] = "100",
+                    ["X-RateLimit-Reset"] = "1356998400",
+                },
+                new ApiLimit(150, 100, new DateTimeUtc(2013, 1, 1, 0, 0, 0))
+            },
+            {
+                new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase) {
+                    ["x-ratelimit-limit"] = "150",
+                    ["x-ratelimit-remaining"] = "100",
+                    ["x-ratelimit-reset"] = "1356998400",
+                },
+                new ApiLimit(150, 100, new DateTimeUtc(2013, 1, 1, 0, 0, 0))
+            },
+            {
+                new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase) {
+                    ["X-RateLimit-Limit"] = "150",
+                    ["X-RateLimit-Remaining"] = "100",
+                    ["X-RateLimit-Reset"] = "hogehoge",
+                },
+                null
+            },
+            {
+                new Dictionary<string, string> {
+                    ["X-RateLimit-Limit"] = "150",
+                    ["X-RateLimit-Remaining"] = "100",
+                },
+                null
+            },
+        };
 
         [Theory]
         [MemberData(nameof(ParseRateLimit_TestCase))]
@@ -95,35 +92,32 @@ namespace OpenTween.Api
             Assert.Equal(expected, limit);
         }
 
-        public static IEnumerable<object[]> ParseMediaRateLimit_TestCase
+        public static readonly TheoryData<IDictionary<string, string>, ApiLimit> ParseMediaRateLimit_TestCase = new TheoryData<IDictionary<string, string>, ApiLimit>
         {
-            get
             {
-                yield return new object[] {
-                    new Dictionary<string, string> {
-                        ["X-MediaRateLimit-Limit"] = "30",
-                        ["X-MediaRateLimit-Remaining"] = "20",
-                        ["X-MediaRateLimit-Reset"] = "1234567890",
-                    },
-                    new ApiLimit(30, 20, new DateTimeUtc(2009, 2, 13, 23, 31, 30)),
-                };
-                yield return new object[] {
-                    new Dictionary<string, string> {
-                        ["X-MediaRateLimit-Limit"] = "30",
-                        ["X-MediaRateLimit-Remaining"] = "20",
-                        ["X-MediaRateLimit-Reset"] = "hogehoge",
-                    },
-                    null,
-                };
-                yield return new object[] {
-                    new Dictionary<string, string> {
-                        ["X-MediaRateLimit-Limit"] = "30",
-                        ["X-MediaRateLimit-Remaining"] = "20",
-                    },
-                    null,
-                };
-            }
-        }
+                new Dictionary<string, string> {
+                    ["X-MediaRateLimit-Limit"] = "30",
+                    ["X-MediaRateLimit-Remaining"] = "20",
+                    ["X-MediaRateLimit-Reset"] = "1234567890",
+                },
+                new ApiLimit(30, 20, new DateTimeUtc(2009, 2, 13, 23, 31, 30))
+            },
+            {
+                new Dictionary<string, string> {
+                    ["X-MediaRateLimit-Limit"] = "30",
+                    ["X-MediaRateLimit-Remaining"] = "20",
+                    ["X-MediaRateLimit-Reset"] = "hogehoge",
+                },
+                null
+            },
+            {
+                new Dictionary<string, string> {
+                    ["X-MediaRateLimit-Limit"] = "30",
+                    ["X-MediaRateLimit-Remaining"] = "20",
+                },
+                null
+            },
+        };
 
         [Theory]
         [MemberData(nameof(ParseMediaRateLimit_TestCase))]
@@ -133,32 +127,29 @@ namespace OpenTween.Api
             Assert.Equal(expected, limit);
         }
 
-        public static IEnumerable<object[]> ParseAccessLevel_TestCase
+        public static readonly TheoryData<IDictionary<string, string>, TwitterApiAccessLevel?> ParseAccessLevel_TestCase = new TheoryData<IDictionary<string, string>, TwitterApiAccessLevel?>
         {
-            get
             {
-                yield return new object[] {
-                    new Dictionary<string, string> { {"X-Access-Level", "read"} },
-                    TwitterApiAccessLevel.Read,
-                };
-                yield return new object[] {
-                    new Dictionary<string, string> { {"X-Access-Level", "read-write"} },
-                    TwitterApiAccessLevel.ReadWrite,
-                };
-                yield return new object[] {
-                    new Dictionary<string, string> { {"X-Access-Level", "read-write-directmessages"} },
-                    TwitterApiAccessLevel.ReadWriteAndDirectMessage,
-                };
-                yield return new object[] {
-                    new Dictionary<string, string> { {"X-Access-Level", ""} }, // 何故かたまに出てくるやつ
-                    null,
-                };
-                yield return new object[] {
-                    new Dictionary<string, string> { },
-                    null,
-                };
-            }
-        }
+                new Dictionary<string, string> { {"X-Access-Level", "read"} },
+                TwitterApiAccessLevel.Read
+            },
+            {
+                new Dictionary<string, string> { {"X-Access-Level", "read-write"} },
+                TwitterApiAccessLevel.ReadWrite
+            },
+            {
+                new Dictionary<string, string> { {"X-Access-Level", "read-write-directmessages"} },
+                TwitterApiAccessLevel.ReadWriteAndDirectMessage
+            },
+            {
+                new Dictionary<string, string> { {"X-Access-Level", ""} }, // 何故かたまに出てくるやつ
+                null
+            },
+            {
+                new Dictionary<string, string> { },
+                null
+            },
+        };
 
         [Theory]
         [MemberData(nameof(ParseAccessLevel_TestCase))]
index a71ff5a..84a3942 100644 (file)
@@ -121,16 +121,13 @@ namespace OpenTween
             [DataMember(Name = "id")] public string Id { get; set; }
             [DataMember(Name = "body")] public string Body { get; set; }
         }
-        public static IEnumerable<object[]> CreateDataFromJson_TestCase
+        public static readonly TheoryData<string, JsonData> CreateDataFromJson_TestCase = new TheoryData<string, JsonData>
         {
-            get
             {
-                yield return new object[] {
-                    @"{""id"":""1"", ""body"":""hogehoge""}",
-                    new JsonData { Id = "1", Body = "hogehoge" },
-                };
-            }
-        }
+                @"{""id"":""1"", ""body"":""hogehoge""}",
+                new JsonData { Id = "1", Body = "hogehoge" }
+            },
+        };
 
         [Theory]
         [MemberData(nameof(CreateDataFromJson_TestCase))]
@@ -185,20 +182,17 @@ namespace OpenTween
         public void GetReadableVersionTest(string fileVersion, string expected)
             => Assert.Equal(expected, MyCommon.GetReadableVersion(fileVersion));
 
-        public static IEnumerable<object[]> GetStatusUrlTest1_TestCase
+        public static readonly TheoryData<PostClass, string> GetStatusUrlTest1_TestCase = new TheoryData<PostClass, string>
         {
-            get
             {
-                yield return new object[] {
-                    new PostClass { StatusId = 249493863826350080L, ScreenName = "Favstar_LM", RetweetedId = null, RetweetedBy = null },
-                    "https://twitter.com/Favstar_LM/status/249493863826350080",
-                };
-                yield return new object[] {
-                    new PostClass { StatusId = 216033842434289664L, ScreenName = "haru067", RetweetedId = 200245741443235840L, RetweetedBy = "re4k"},
-                    "https://twitter.com/haru067/status/200245741443235840",
-                };
-            }
-        }
+                new PostClass { StatusId = 249493863826350080L, ScreenName = "Favstar_LM", RetweetedId = null, RetweetedBy = null },
+                "https://twitter.com/Favstar_LM/status/249493863826350080"
+            },
+            {
+                new PostClass { StatusId = 216033842434289664L, ScreenName = "haru067", RetweetedId = 200245741443235840L, RetweetedBy = "re4k"},
+                "https://twitter.com/haru067/status/200245741443235840"
+            },
+        };
 
         [Theory]
         [MemberData(nameof(GetStatusUrlTest1_TestCase))]