MediaUploadTest.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System;
  2. using JCSoft.WX.Framework.Models.ApiRequests;
  3. using JCSoft.WX.Framework.Models.ApiResponses;
  4. using Xunit;
  5. using JCSoft.WX.Framework.Models;
  6. namespace FrameworkCoreTest
  7. {
  8. public class MediaUploadTest : MockPostApiBaseTest<MediaUploadRequest, MediaUploadResponse>
  9. {
  10. [Fact]
  11. public void MediaUploadReallyTest()
  12. {
  13. var response = mock_client.Object.Execute(Request);
  14. if (response.IsError)
  15. Console.WriteLine(response.ToString());
  16. Console.WriteLine(response.MediaId);
  17. }
  18. [Fact]
  19. public void MockMediaUploadTest()
  20. {
  21. IsMock = true;
  22. MockSetup(false);
  23. var response = mock_client.Object.Execute(Request);
  24. Assert.Equal("MEDIA_ID", response.MediaId);
  25. }
  26. [Fact]
  27. public void MockMediaUploadErrorTest()
  28. {
  29. IsMock = true;
  30. MockSetup(true);
  31. var response = mock_client.Object.Execute(Request);
  32. Assert.Equal(true, response.IsError);
  33. }
  34. protected override MediaUploadRequest InitRequestObject()
  35. {
  36. return new MediaUploadRequest
  37. {
  38. AccessToken = GetCurrentToken(),
  39. FilePath = @"C:\123.amr",
  40. MediaType = MediaType.Voice
  41. };
  42. }
  43. protected override string GetReturnResult(bool errResult)
  44. {
  45. if (errResult)
  46. return s_errmsg;
  47. return "{\"type\":\"Image\",\"media_id\":\"MEDIA_ID\",\"created_at\":123456789}";
  48. }
  49. }
  50. }