You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
3.5 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
  1. using Microsoft.EntityFrameworkCore;
  2. using Shentun.Peis.GuideTypes;
  3. using Shentun.Peis.Models;
  4. using Shouldly;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using Volo.Abp.Application.Dtos;
  11. using Volo.Abp.Domain.Repositories;
  12. using Volo.Abp.Uow;
  13. using Xunit;
  14. using Xunit.Abstractions;
  15. namespace Shentun.Peis
  16. {
  17. public class GuideTypeAppServiceTest: PeisApplicationTestBase
  18. {
  19. private readonly IRepository<GuideType, Guid> _repository;
  20. private readonly GuideTypeAppService _guideTypeAppService;
  21. private readonly ITestOutputHelper _output;
  22. private readonly IUnitOfWorkManager _unitOfWorkManager;
  23. public GuideTypeAppServiceTest(ITestOutputHelper testOutputHelper)
  24. {
  25. _output = testOutputHelper;
  26. _unitOfWorkManager = GetRequiredService<IUnitOfWorkManager>();
  27. _repository = GetRequiredService<IRepository<GuideType, Guid>>();
  28. _guideTypeAppService = GetRequiredService<GuideTypeAppService>();
  29. }
  30. [Fact]
  31. public async Task GetQueryListAsync()
  32. {
  33. using (var uow = _unitOfWorkManager.Begin())
  34. {
  35. IQueryable<GuideType> queryable = await _repository.GetQueryableAsync();
  36. var itemTypes = (from item in queryable
  37. select item).ToList();
  38. foreach (var item in itemTypes)
  39. {
  40. _output.WriteLine(item.DisplayName);
  41. }
  42. await uow.CompleteAsync();
  43. }
  44. }
  45. [Fact]
  46. public async Task GetListAsync()
  47. {
  48. PagedAndSortedResultRequestDto qc = new PagedAndSortedResultRequestDto()
  49. {
  50. Sorting = "displayorder"
  51. };
  52. var result = await _guideTypeAppService.GetListAsync(qc);
  53. _output.WriteLine(result.TotalCount.ToString());
  54. foreach (var item in result.Items)
  55. {
  56. Console.WriteLine(item.DisplayName);
  57. _output.WriteLine(item.DisplayName);
  58. }
  59. }
  60. [Fact]
  61. public async Task GetList()
  62. {
  63. PagedAndSortedResultRequestDto qc = new PagedAndSortedResultRequestDto() {
  64. Sorting = "displayorder"};
  65. var result = await _guideTypeAppService.GetListAsync(qc);
  66. result.TotalCount.ShouldBeGreaterThanOrEqualTo(4);
  67. Console.WriteLine(result.TotalCount);
  68. _output.WriteLine(result.TotalCount.ToString());
  69. foreach (var item in result.Items)
  70. {
  71. Console.WriteLine(item.DisplayName);
  72. _output.WriteLine(item.DisplayName);
  73. }
  74. }
  75. [Fact]
  76. public async Task Create()
  77. {
  78. var result = await _guideTypeAppService.CreateAsync(new CreateGuideTypeDto()
  79. {
  80. DisplayName = "Foo",
  81. });
  82. _output.WriteLine(result.Id.ToString());
  83. }
  84. [Fact]
  85. public async Task DeleteAsync()
  86. {
  87. try
  88. {
  89. using (var uow = _unitOfWorkManager.Begin())
  90. {
  91. await _guideTypeAppService.DeleteAsync(new Guid("3a0d6c49-cecf-19d9-0f4b-0923a28a3889"));
  92. _output.WriteLine("删除成功");
  93. }
  94. }
  95. catch (Exception ex)
  96. {
  97. _output.WriteLine(ex.Message);
  98. }
  99. }
  100. }
  101. }