-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathTweetConverterTest.cs
58 lines (57 loc) · 2.66 KB
/
TweetConverterTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using NowPlayingCore.Core;
using NowPlayingCore.NowPlaying;
using NowPlayingCore.Tsumugi;
using Xunit;
namespace NowPlayingV2UTest
{
public class TweetConverterTest
{
[Fact]
public void TestAutoShortenTweet()
{
//setup test instance
var dummysong = new SongInfo();
var constructor_twitter = typeof(TwitterAccount).GetConstructor(
BindingFlags.NonPublic | BindingFlags.Instance,
null, new Type[0], null);
var twitteraccount = (TwitterAccount) constructor_twitter.Invoke(null);
var constructor_mastodon = typeof(MastodonAccount).GetConstructor(
BindingFlags.NonPublic | BindingFlags.Instance,
null, new Type[0], null);
var mastodonaccount = (MastodonAccount) constructor_mastodon.Invoke(null);
//280 chars text
var testtext280 = "";
140.Times(i => { testtext280 += (new[] {"ほ", "げ"}).OrderBy((k => Guid.NewGuid())).ToArray().First(); });
//288 chars text
var testtext288 = testtext280 + "ほげほげ";
//500 chars text
var testtext500 = "";
500.Times(i => { testtext500 += (new[] {"ほ", "げ"}).OrderBy((k => Guid.NewGuid())).ToArray().First(); });
var testtext765 = "";
765.Times(i =>
{
testtext765 += "白石紬はぽんこつかわいい".ToCharArray().Select(c => c.ToString()).ToArray()
.OrderBy((k => Guid.NewGuid())).ToArray().First();
});
//Test Twitter counter
Assert.True(twitteraccount.CountText(testtext280) == 280);
var testconvtext1 = TweetConverter.SongInfoToString(testtext280, dummysong, true, twitteraccount);
Assert.True(testconvtext1 == testtext280);
var testconvtext2 = TweetConverter.SongInfoToString(testtext288, dummysong, true, twitteraccount);
Assert.True(twitteraccount.CountText(testconvtext2) == 279);
//Test Mastodon counter
Assert.True(mastodonaccount.CountText(testtext500) == 500);
var testconvtext3 = TweetConverter.SongInfoToString(testtext500, dummysong, true, mastodonaccount);
Assert.True(mastodonaccount.CountText(testconvtext3) == 500);
var testconvtext4 = TweetConverter.SongInfoToString(testtext765, dummysong, true, mastodonaccount);
Assert.True(mastodonaccount.CountText(testconvtext4) == 500);
}
}
}