1 // OpenTween - Client of Twitter
2 // Copyright (c) 2012 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
3 // All rights reserved.
5 // This file is part of OpenTween.
7 // This program is free software; you can redistribute it and/or modify it
8 // under the terms of the GNU General Public License as published by the Free
9 // Software Foundation; either version 3 of the License, or (at your option)
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 // You should have received a copy of the GNU General Public License along
18 // with this program. If not, see <http://www.gnu.org/licenses/>, or write to
19 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
20 // Boston, MA 02110-1301, USA.
23 using System.Collections.Generic;
25 using System.Reflection;
28 using Xunit.Extensions;
32 public class PostClassTest
34 class TestPostClass : PostClass
37 string Nickname = null,
38 string textFromApi = null,
40 string ImageUrl = null,
41 string screenName = null,
42 DateTime createdAt = new DateTime(),
47 bool IsExcludeReply = false,
48 bool IsProtect = false,
51 string InReplyToUser = null,
52 long? InReplyToStatusId = null,
54 string SourceHtml = null,
55 List<string> ReplyToList = null,
59 bool FilterHit = false,
60 string RetweetedBy = null,
61 long? RetweetedId = null,
62 StatusGeo Geo = null) :
63 base(Nickname, textFromApi, text, ImageUrl, screenName, createdAt, statusId, IsFav, IsRead,
64 IsReply, IsExcludeReply, IsProtect, IsOwl, IsMark, InReplyToUser, InReplyToStatusId, Source,
65 SourceHtml, ReplyToList, IsMe, IsDm, userId, FilterHit, RetweetedBy, RetweetedId, Geo)
69 protected override PostClass GetRetweetSource(long statusId)
71 return PostClassTest.TestCases.ContainsKey(statusId) ?
72 PostClassTest.TestCases[statusId] :
77 private static Dictionary<long, PostClass> TestCases;
79 public PostClassTest()
81 PostClassTest.TestCases = new Dictionary<long, PostClass>
83 {1L, new TestPostClass(statusId: 1L)},
84 {2L, new TestPostClass(statusId: 2L, IsFav: true)},
85 {3L, new TestPostClass(statusId: 3L, IsFav: false, RetweetedId: 2L)},
90 public void CloneTest()
92 var post = new PostClass();
93 var clonePost = post.Clone();
95 TestUtils.CheckDeepCloning(post, clonePost);
99 [InlineData(null, null)]
101 [InlineData("aaa\nbbb", "aaa bbb")]
102 public void TextSingleLineTest(string text, string expected)
104 var post = new TestPostClass(textFromApi: text);
106 Assert.Equal(expected, post.TextSingleLine);
110 [InlineData(1L, false)]
111 [InlineData(2L, true)]
112 [InlineData(3L, true)]
113 public void GetIsFavTest(long statusId, bool expected)
115 Assert.Equal(expected, PostClassTest.TestCases[statusId].IsFav);
119 [InlineData(2L, true)]
120 [InlineData(2L, false)]
121 [InlineData(3L, true)]
122 [InlineData(3L, false)]
123 public void SetIsFavTest(long statusId, bool isFav)
125 var post = PostClassTest.TestCases[statusId];
128 Assert.Equal(isFav, post.IsFav);
130 if (post.RetweetedId != null)
131 Assert.Equal(isFav, PostClassTest.TestCases[post.RetweetedId.Value].IsFav);
135 [InlineData(false, false, false, false, -0x01)]
136 [InlineData( true, false, false, false, 0x00)]
137 [InlineData(false, true, false, false, 0x01)]
138 [InlineData( true, true, false, false, 0x02)]
139 [InlineData(false, false, true, false, 0x03)]
140 [InlineData( true, false, true, false, 0x04)]
141 [InlineData(false, true, true, false, 0x05)]
142 [InlineData( true, true, true, false, 0x06)]
143 [InlineData(false, false, false, true, 0x07)]
144 [InlineData( true, false, false, true, 0x08)]
145 [InlineData(false, true, false, true, 0x09)]
146 [InlineData( true, true, false, true, 0x0A)]
147 [InlineData(false, false, true, true, 0x0B)]
148 [InlineData( true, false, true, true, 0x0C)]
149 [InlineData(false, true, true, true, 0x0D)]
150 [InlineData( true, true, true, true, 0x0E)]
151 public void StateIndexTest(bool protect, bool mark, bool reply, bool geo, int expected)
153 var post = new TestPostClass
157 InReplyToStatusId = reply ? (long?)100L : null,
158 PostGeo = geo ? new PostClass.StatusGeo { Lat = -47.15, Lng = -126.716667 } : new PostClass.StatusGeo(),
161 Assert.Equal(expected, post.StateIndex);
165 public void DeleteTest()
167 var post = new TestPostClass
169 InReplyToStatusId = 10L,
170 InReplyToUser = "hogehoge",
171 InReplyToUserId = 100L,
173 ReplyToList = new List<string> {"hogehoge"},
176 post.IsDeleted = true;
178 Assert.Null(post.InReplyToStatusId);
179 Assert.Equal("", post.InReplyToUser);
180 Assert.Null(post.InReplyToUserId);
181 Assert.False(post.IsReply);
182 Assert.Empty(post.ReplyToList);
183 Assert.Equal(-1, post.StateIndex);