MediaUploadNewsTest.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System;
  2. using System.Collections.Generic;
  3. using JCSoft.WX.Framework.Models.ApiResponses;
  4. using JCSoft.WX.Framework.Models.ApiRequests;
  5. using Xunit;
  6. using JCSoft.WX.Framework.Models;
  7. namespace FrameworkCoreTest
  8. {
  9. public class MediaUploadNewsTest : MockPostApiBaseTest<MediaUploadNewsRequest, MediaUploadNewsResponse>
  10. {
  11. [Fact]
  12. public void MockMediaUploadNewsTest()
  13. {
  14. MockSetup(false);
  15. var response = mock_client.Object.Execute(Request);
  16. Assert.Equal("news", response.Type);
  17. Assert.Equal(1391857799, response.CreatedAt);
  18. }
  19. [Fact]
  20. public void MockMediaUploadNewsErrorTest()
  21. {
  22. MockSetup(true);
  23. var response = mock_client.Object.Execute(Request);
  24. Assert.Equal(true, response.IsError);
  25. Console.WriteLine(response);
  26. }
  27. protected override MediaUploadNewsRequest InitRequestObject()
  28. {
  29. return new MediaUploadNewsRequest
  30. {
  31. AccessToken = "123",
  32. Articles = new List<ArticleMessage>()
  33. {
  34. new ArticleMessage{
  35. ThumbMediaId = "image1",
  36. Author = "jamesying",
  37. Title = "test news 1",
  38. Url= "newsurl1",
  39. Content = "content1",
  40. Description = "discription1"
  41. },
  42. new ArticleMessage{
  43. ThumbMediaId = "image2",
  44. Author = "jamesying",
  45. Title = "test news 2",
  46. Url= "newsurl2",
  47. Content = "content2",
  48. Description = "discription2"
  49. }
  50. }
  51. };
  52. }
  53. protected override string GetReturnResult(bool errResult)
  54. {
  55. if (errResult)
  56. return "{\"errcode\":40018,\"errmsg\":\"invalid button name size\"}";
  57. return @"{
  58. ""type"":""news"",
  59. ""media_id"":""CsEf3ldqkAYJAU6EJeIkStVDSvffUJ54vqbThMgplD-VJXXof6ctX5fI6-aYyUiQ"",
  60. ""created_at"":1391857799
  61. }";
  62. }
  63. }
  64. }