ApiControllerTest.cs 1.9 KB

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