1
0

ApiControllerTest.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using Admin.Core.Common.Input;
  2. using Admin.Core.Model.Admin;
  3. using Admin.Core.Service.Admin.Api.Input;
  4. using Admin.Core.Service.Admin.Api.Output;
  5. using System.Collections.Generic;
  6. using System.Net;
  7. using System.Threading.Tasks;
  8. using Xunit;
  9. namespace Admin.Core.Tests.Controller.Admin
  10. {
  11. public class ApiControllerTest : BaseControllerTest
  12. {
  13. public ApiControllerTest() : base()
  14. {
  15. }
  16. [Fact]
  17. public async Task Get()
  18. {
  19. var res = await GetResult<ResultDto<ApiGetOutput>>("/api/admin/api/get?id=161227167658053");
  20. Assert.True(res.Success);
  21. }
  22. [Fact]
  23. public async Task GetList()
  24. {
  25. var res = await GetResult<ResultDto<List<ApiListOutput>>>("/api/admin/api/getlist?key=接口管理");
  26. Assert.True(res.Success);
  27. }
  28. [Fact]
  29. public async Task GetPage()
  30. {
  31. var input = new PageInput<ApiEntity>
  32. {
  33. CurrentPage = 1,
  34. PageSize = 20,
  35. Filter = new ApiEntity
  36. {
  37. Label = "接口管理"
  38. }
  39. };
  40. await Login();
  41. var res = await Client.PostAsync($"/api/admin/api/getpage", GetHttpContent(input));
  42. Assert.Equal(HttpStatusCode.Forbidden, res.StatusCode);
  43. }
  44. [Fact]
  45. public async Task Add()
  46. {
  47. var input = new ApiAddInput
  48. {
  49. Label = "新接口",
  50. Path = "/api/admin/api/newapi",
  51. HttpMethods = "post"
  52. };
  53. var res = await PostResult($"/api/admin/api/add", input);
  54. Assert.True(res.Success);
  55. }
  56. [Fact]
  57. public async Task Update()
  58. {
  59. var output = await GetResult<ResultDto<ApiGetOutput>>("/api/admin/api/get?id=161227167658053");
  60. var res = await PutResult($"/api/admin/api/update", output.Data);
  61. Assert.True(res.Success);
  62. }
  63. [Fact]
  64. public async Task Delete()
  65. {
  66. var res = await DeleteResult($"/api/admin/api/softdelete?{ToParams(new { id = 191182807191621 })}");
  67. Assert.True(res.Success);
  68. }
  69. }
  70. }