public void IsAnimatedGifTest(string filename, bool expected)
=> Assert.Equal(expected, MyCommon.IsAnimatedGif(filename));
- public static readonly TheoryData<string, DateTimeUtc> DateTimeParse_TestCase = new TheoryData<string, DateTimeUtc>
+ public static readonly TheoryData<string, DateTimeUtc> DateTimeParseTestCase = new()
{
{ "Sun Nov 25 06:10:00 +00:00 2012", new DateTimeUtc(2012, 11, 25, 6, 10, 0) },
{ "Sun, 25 Nov 2012 06:10:00 +00:00", new DateTimeUtc(2012, 11, 25, 6, 10, 0) },
};
[Theory]
- [MemberData(nameof(DateTimeParse_TestCase))]
+ [MemberData(nameof(DateTimeParseTestCase))]
public void DateTimeParseTest(string date, DateTimeUtc excepted)
=> Assert.Equal(excepted, MyCommon.DateTimeParse(date));
[DataContract]
public struct JsonData
{
- [DataMember(Name = "id")] public string Id { get; set; }
- [DataMember(Name = "body")] public string Body { get; set; }
+ [DataMember(Name = "id")]
+ public string Id { get; set; }
+
+ [DataMember(Name = "body")]
+ public string Body { get; set; }
}
- public static readonly TheoryData<string, JsonData> CreateDataFromJson_TestCase = new TheoryData<string, JsonData>
+
+ public static readonly TheoryData<string, JsonData> CreateDataFromJsonTestCase = new()
{
{
- @"{""id"":""1"", ""body"":""hogehoge""}",
+ """{"id":"1", "body":"hogehoge"}""",
new JsonData { Id = "1", Body = "hogehoge" }
},
};
[Theory]
- [MemberData(nameof(CreateDataFromJson_TestCase))]
- public void CreateDataFromJsonTest<T>(string json, T expected)
+ [MemberData(nameof(CreateDataFromJsonTestCase))]
+ public void CreateDataFromJson_StringTest<T>(string json, T expected)
=> Assert.Equal(expected, MyCommon.CreateDataFromJson<T>(json));
[Theory]
+ [MemberData(nameof(CreateDataFromJsonTestCase))]
+ public void CreateDataFromJson_BytesTest<T>(string json, T expected)
+ {
+ var jsonBytes = Encoding.UTF8.GetBytes(json);
+ Assert.Equal(expected, MyCommon.CreateDataFromJson<T>(jsonBytes));
+ }
+
+ [Theory]
[InlineData("hoge123@example.com", true)]
[InlineData("hogehoge", false)]
[InlineData("foo.bar@example.com", true)]
[InlineData(Keys.Control | Keys.Alt, new[] { Keys.Control, Keys.Alt }, true)]
[InlineData(Keys.Control | Keys.Alt, new[] { Keys.Shift }, false)]
public void IsKeyDownTest(Keys modifierKeys, Keys[] checkKeys, bool expected)
- => Assert.Equal(expected, MyCommon._IsKeyDown(modifierKeys, checkKeys));
+ => Assert.Equal(expected, MyCommon.IsKeyDownInternal(modifierKeys, checkKeys));
[Fact]
public void GetAssemblyNameTest()
public void GetReadableVersionTest(string fileVersion, string expected)
=> Assert.Equal(expected, MyCommon.GetReadableVersion(fileVersion));
- public static readonly TheoryData<PostClass, string> GetStatusUrlTest1_TestCase = new TheoryData<PostClass, string>
+ public static readonly TheoryData<PostClass, string> GetStatusUrlTest1TestCase = new()
{
{
- new PostClass { StatusId = 249493863826350080L, ScreenName = "Favstar_LM", RetweetedId = null, RetweetedBy = null },
+ new PostClass { StatusId = new TwitterStatusId("249493863826350080"), ScreenName = "Favstar_LM", RetweetedId = null, RetweetedBy = null },
"https://twitter.com/Favstar_LM/status/249493863826350080"
},
{
- new PostClass { StatusId = 216033842434289664L, ScreenName = "haru067", RetweetedId = 200245741443235840L, RetweetedBy = "re4k"},
+ new PostClass { StatusId = new TwitterStatusId("216033842434289664"), ScreenName = "haru067", RetweetedId = new TwitterStatusId("200245741443235840"), RetweetedBy = "re4k" },
"https://twitter.com/haru067/status/200245741443235840"
},
};
[Theory]
- [MemberData(nameof(GetStatusUrlTest1_TestCase))]
+ [MemberData(nameof(GetStatusUrlTest1TestCase))]
public void GetStatusUrlTest1(PostClass post, string expected)
=> Assert.Equal(expected, MyCommon.GetStatusUrl(post));
[InlineData("Favstar_LM", 249493863826350080L, "https://twitter.com/Favstar_LM/status/249493863826350080")]
[InlineData("haru067", 200245741443235840L, "https://twitter.com/haru067/status/200245741443235840")]
public void GetStatusUrlTest2(string screenName, long statusId, string expected)
- => Assert.Equal(expected, MyCommon.GetStatusUrl(screenName, statusId));
+ => Assert.Equal(expected, MyCommon.GetStatusUrl(screenName, new TwitterStatusId(statusId)));
[Fact]
public void GetErrorLogPathTest()
Assert.Equal(new[] { 5, 4, 3, 2, 1, 0 }, actual);
}
+
+ [Fact]
+ public void CreateBrowserProcessStartInfo_BrowserPathTest()
+ {
+ var startInfo = MyCommon.CreateBrowserProcessStartInfo("C:\\browser.exe", "https://example.com/");
+ Assert.Equal("C:\\browser.exe", startInfo.FileName);
+ Assert.Equal("\"https://example.com/\"", startInfo.Arguments);
+ Assert.False(startInfo.UseShellExecute);
+ }
+
+ [Fact]
+ public void CreateBrowserProcessStartInfo_BrowserPathWithSpacesTest()
+ {
+ var startInfo = MyCommon.CreateBrowserProcessStartInfo("C:\\Program Files\\browser.exe", "https://example.com/");
+ Assert.Equal("C:\\Program Files\\browser.exe", startInfo.FileName);
+ Assert.Equal("\"https://example.com/\"", startInfo.Arguments);
+ Assert.False(startInfo.UseShellExecute);
+ }
+
+ [Fact]
+ public void CreateBrowserProcessStartInfo_QuotedBrowserPathTest()
+ {
+ var startInfo = MyCommon.CreateBrowserProcessStartInfo("\"C:\\Program Files\\browser.exe\"", "https://example.com/");
+ Assert.Equal("C:\\Program Files\\browser.exe", startInfo.FileName);
+ Assert.Equal("\"https://example.com/\"", startInfo.Arguments);
+ Assert.False(startInfo.UseShellExecute);
+ }
+
+ [Fact]
+ public void CreateBrowserProcessStartInfo_QuotedBrowserPathWithArgsTest()
+ {
+ var startInfo = MyCommon.CreateBrowserProcessStartInfo("\"C:\\Program Files\\browser.exe\" /hoge", "https://example.com/");
+ Assert.Equal("C:\\Program Files\\browser.exe", startInfo.FileName);
+ Assert.Equal("/hoge \"https://example.com/\"", startInfo.Arguments);
+ Assert.False(startInfo.UseShellExecute);
+ }
+
+ public static readonly TheoryData<int[], (int Start, int End)[]> ToRangeChunkTestCase = new()
+ {
+ {
+ new[] { 1 },
+ new[] { (1, 1) }
+ },
+ {
+ new[] { 1, 2 },
+ new[] { (1, 2) }
+ },
+ {
+ new[] { 1, 3 },
+ new[] { (1, 1), (3, 3) }
+ },
+ };
+
+ [Theory]
+ [MemberData(nameof(ToRangeChunkTestCase))]
+ public void ToRangeChunk_Test(int[] values, (int Start, int End)[] expected)
+ {
+ Assert.Equal(expected, MyCommon.ToRangeChunk(values));
+ }
}
}