{
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))]
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))]
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))]
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))]
[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))]
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))]