PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/MAIN/Source/Facebook.Tests/Facebook.Tests.Synchronous/streamTest.cs

#
C# | 307 lines | 216 code | 18 blank | 73 comment | 3 complexity | 98d5a39852b1c862cd90d53ae39c5cd8 MD5 | raw file
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using Facebook.Schema;
  3. using System;
  4. using System.Collections.Generic;
  5. using Facebook.Rest;
  6. using Facebook.Session;
  7. namespace Facebook.Tests.Synchronous
  8. {
  9. /// <summary>
  10. ///This is a test class for applicationTest and is intended
  11. ///to contain all applicationTest Unit Tests
  12. ///</summary>
  13. [TestClass()]
  14. public class streamTest : Test
  15. {
  16. #region Additional test attributes
  17. //
  18. //You can use the following additional attributes as you write your tests:
  19. //
  20. //Use ClassInitialize to run code before running the first test in the class
  21. //[ClassInitialize()]
  22. //public static void MyClassInitialize(TestContext testContext)
  23. //{
  24. //}
  25. //
  26. //Use ClassCleanup to run code after all tests in a class have run
  27. //[ClassCleanup()]
  28. //public static void MyClassCleanup()
  29. //{
  30. //}
  31. //
  32. //Use TestInitialize to run code before running each test
  33. //[TestInitialize()]
  34. //public void MyTestInitialize()
  35. //{
  36. //}
  37. //
  38. //Use TestCleanup to run code after each test has run
  39. //[TestCleanup()]
  40. //public void MyTestCleanup()
  41. //{
  42. //}
  43. //
  44. #endregion
  45. /// <summary>
  46. ///A test for getTest
  47. ///</summary>
  48. [TestMethod()]
  49. public void getTest()
  50. {
  51. var actual = _api.Stream.Get(0,null,Constants.MinFacebookDate, DateTime.MaxValue, 0,null);
  52. Assert.IsNotNull(actual);
  53. }
  54. /// <summary>
  55. ///A test for getTest
  56. ///</summary>
  57. [TestMethod()]
  58. public void getTest1()
  59. {
  60. var actual = _api.Stream.Get(0, null, Constants.MinFacebookDate, DateTime.MaxValue, 2, null);
  61. Assert.IsNotNull(actual);
  62. Assert.IsTrue(actual.albums.album.Count <= 2);
  63. Assert.IsTrue(actual.posts.stream_post.Count <= 2);
  64. }
  65. /// <summary>
  66. ///A test for getTest
  67. ///</summary>
  68. [TestMethod()]
  69. public void getTest2()
  70. {
  71. var actual = _api.Stream.Get(0, new List<long>() { 665621453, 630947564 }, Constants.MinFacebookDate, DateTime.MaxValue, 0, null);
  72. Assert.IsNotNull(actual);
  73. foreach (var post in actual.posts.stream_post)
  74. {
  75. Assert.IsTrue(post.source_id == 665621453 || post.source_id == 630947564);
  76. }
  77. }
  78. /// <summary>
  79. ///A test for getTest
  80. ///</summary>
  81. [TestMethod()]
  82. public void getTest3()
  83. {
  84. var actual = _api.Stream.Get(0, null, Constants.MinFacebookDate, DateTime.MaxValue, 0, "fl_26568837591");
  85. Assert.IsNotNull(actual);
  86. }
  87. /// <summary>
  88. ///A test for getFilters
  89. ///</summary>
  90. [TestMethod()]
  91. public void getFiltersTest()
  92. {
  93. var actual = _api.Stream.GetFilters(0);
  94. Assert.IsNotNull(actual);
  95. }
  96. /// <summary>
  97. ///A test for addComment
  98. ///</summary>
  99. [TestMethod()]
  100. public void addCommentTest()
  101. {
  102. var actual = _api.Stream.Get(0, new List<long>() { Constants.FBSamples_UserId }, Constants.MinFacebookDate, DateTime.MaxValue, 0, null);
  103. Assert.IsNotNull(actual);
  104. var actual2 = _api.Stream.AddComment(actual.posts.stream_post[0].post_id, "Testing stream.AddComment");
  105. Assert.IsTrue(!string.IsNullOrEmpty(actual2));
  106. }
  107. /// <summary>
  108. ///A test for addLike
  109. ///</summary>
  110. [TestMethod()]
  111. public void addLikeTest()
  112. {
  113. var actual = _api.Stream.Get(0, new List<long>() { Constants.FBSamples_UserId }, Constants.MinFacebookDate, DateTime.MaxValue, 0, null);
  114. Assert.IsNotNull(actual);
  115. var actual2 = _api.Stream.AddLike(actual.posts.stream_post[0].post_id);
  116. Assert.IsTrue(actual2);
  117. }
  118. /// <summary>
  119. ///A test for getComments
  120. ///</summary>
  121. [TestMethod()]
  122. public void getCommentsTest()
  123. {
  124. var actual = _api.Stream.Get(0, new List<long>() { Constants.FBSamples_UserId }, Constants.MinFacebookDate, DateTime.MaxValue, 0, null);
  125. Assert.IsNotNull(actual);
  126. var actual2 = _api.Stream.GetComments(actual.posts.stream_post[0].post_id);
  127. Assert.IsNotNull(actual2);
  128. }
  129. /// <summary>
  130. ///A test for getComments
  131. ///</summary>
  132. [TestMethod()]
  133. public void publishTest()
  134. {
  135. var actual = _api.Stream.Publish("testing stream.publish");
  136. Assert.IsNotNull(actual);
  137. }
  138. /// <summary>
  139. ///A test for getComments
  140. ///</summary>
  141. [TestMethod()]
  142. public void publishTest2()
  143. {
  144. attachment attachment = new attachment();
  145. attachment.caption = "www.icanhascheezburger.com";
  146. attachment.name = "I am bursting with joy";
  147. attachment.href = "http://icanhascheezburger.com/2009/04/22/funny-pictures-bursting-with-joy/";
  148. attachment.description = "a funny looking cat";
  149. attachment.properties = new List<attachment_property>()
  150. {
  151. new attachment_property
  152. {
  153. name = "category",
  154. value = new attachment_property_value
  155. {
  156. href = "http://www.icanhascheezburger.com/category/humor",
  157. text = "humor"
  158. }
  159. },
  160. new attachment_property
  161. {
  162. name = "ratings",
  163. value = new attachment_property_value { text = "5 stars" }
  164. }
  165. };
  166. attachment.media = new List<attachment_media>(){new attachment_media_image()
  167. {
  168. src = "http://icanhascheezburger.files.wordpress.com/2009/03/funny-pictures-your-cat-is-bursting-with-joy1.jpg",
  169. href = "http://icanhascheezburger.com/2009/04/22/funny-pictures-bursting-with-joy/"
  170. }};
  171. var actual = _api.Stream.Publish("testing stream.publish with image attachment", attachment, null, null, 0);
  172. Assert.IsNotNull(actual);
  173. }
  174. /// <summary>
  175. ///A test for getComments
  176. ///</summary>
  177. [TestMethod()]
  178. public void publishTest3()
  179. {
  180. attachment attachment = new attachment();
  181. attachment.caption = "www.icanhascheezburger.com";
  182. attachment.name = "I am bursting with joy";
  183. attachment.href = "http://icanhascheezburger.com/2009/04/22/funny-pictures-bursting-with-joy/";
  184. attachment.description = "a funny looking cat";
  185. attachment.properties = new List<attachment_property>()
  186. {
  187. new attachment_property
  188. {
  189. name = "category",
  190. value = new attachment_property_value
  191. {
  192. href = "http://www.icanhascheezburger.com/category/humor",
  193. text = "humor"
  194. }
  195. },
  196. new attachment_property
  197. {
  198. name = "ratings",
  199. value = new attachment_property_value { text = "5 stars" }
  200. }
  201. };
  202. attachment.media = new List<attachment_media>(){new attachment_media_image()
  203. {
  204. src = "http://icanhascheezburger.files.wordpress.com/2009/03/funny-pictures-your-cat-is-bursting-with-joy1.jpg",
  205. href = "http://icanhascheezburger.com/2009/04/22/funny-pictures-bursting-with-joy/"
  206. }};
  207. var link = new action_link();
  208. link.href= "http://mine.icanhascheezburger.com/default.aspx?tiid=1192742&recap=1#step2";
  209. link.text = "Recaption this";
  210. var links = new List<action_link>(){link};
  211. var actual = _api.Stream.Publish("testing stream.publish with image attachment", attachment, links, null, 0);
  212. Assert.IsNotNull(actual);
  213. }
  214. [TestMethod()]
  215. public void publishTest4()
  216. {
  217. attachment attachment = new attachment();
  218. attachment.caption = "www.youtube.com";
  219. attachment.name = "ninja cat";
  220. attachment.href = "http://www.youtube.com/watch?v=muLIPWjks_M";
  221. attachment.description = "a sneaky cat";
  222. attachment.properties = new List<attachment_property>()
  223. {
  224. new attachment_property
  225. {
  226. name = "category",
  227. value = new attachment_property_value
  228. {
  229. href = "http://www.youtube.com/browse?s=mp&t=t&c=15",
  230. text = "humor"
  231. }
  232. },
  233. new attachment_property
  234. {
  235. name = "ratings",
  236. value = new attachment_property_value { text = "5 stars" }
  237. }
  238. };
  239. attachment.media = new List<attachment_media>(){new attachment_media_video()
  240. {
  241. video_src = "http://www.youtube.com/v/fzzjgBAaWZw&hl=en&fs=1",
  242. preview_img="http://img.youtube.com/vi/muLIPWjks_M/default.jpg?h=100&w=200&sigh=__wsYqEz4uZUOvBIb8g-wljxpfc3Q=",
  243. video_link = "http://www.youtube.com/watch?v=muLIPWjks_M",
  244. video_title = "ninja cat"
  245. }};
  246. var link = new action_link();
  247. link.href = "http://www.youtube.com/my_videos_upload";
  248. link.text = "Upload a video";
  249. var links = new List<action_link>() { link };
  250. var actual = _api.Stream.Publish("Watch this video!", attachment, links, null, 0);
  251. Assert.IsNotNull(actual);
  252. }
  253. /// <summary>
  254. ///A test for remove
  255. ///</summary>
  256. [TestMethod()]
  257. public void removeTest()
  258. {
  259. var actual = _api.Stream.Publish("testing stream.publish");
  260. Assert.IsNotNull(actual);
  261. var actual2 = _api.Stream.Remove(actual);
  262. Assert.IsTrue(actual2);
  263. }
  264. /// <summary>
  265. ///A test for removeComment
  266. ///</summary>
  267. [TestMethod()]
  268. public void removeCommentTest()
  269. {
  270. var actual = _api.Stream.Publish("testing stream.publish");
  271. Assert.IsNotNull(actual);
  272. var actual2 = _api.Stream.AddComment(actual, "test comment to be removed");
  273. var actual3 = _api.Stream.RemoveComment(actual2);
  274. Assert.IsTrue(actual3);
  275. }
  276. /// <summary>
  277. ///A test for removeComment
  278. ///</summary>
  279. [TestMethod()]
  280. public void removeLikeTest()
  281. {
  282. var actual = _api.Stream.Publish("testing stream.publish");
  283. Assert.IsNotNull(actual);
  284. var actual2 = _api.Stream.AddLike(actual);
  285. var actual3 = _api.Stream.RemoveLike(actual);
  286. Assert.IsTrue(actual3);
  287. }
  288. }
  289. }