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.

108 lines
3.4 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
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 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
2 years ago
2 years ago
3 years ago
  1. using NSubstitute;
  2. using Shentun.Peis.EntityFrameworkCore;
  3. using Shentun.Peis.GuidTypes;
  4. using Shentun.Peis.ItemTypes;
  5. using Shentun.Peis.Models;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Security.Cryptography;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using Volo.Abp;
  13. using Volo.Abp.Domain.Repositories;
  14. using Volo.Abp.Uow;
  15. using Volo.Abp.Linq;
  16. using Xunit;
  17. using Xunit.Abstractions;
  18. using TencentCloud.Tci.V20190318.Models;
  19. namespace Shentun.Peis
  20. {
  21. public class GuideTypeManagerTest : PeisDomainTestBase
  22. {
  23. private readonly IRepository<GuideType, char> _repository;
  24. private readonly GuideTypeManager _manager;
  25. //private readonly IDbContextProvider<PeisDbContext> _dbContextProvider;
  26. private readonly ITestOutputHelper _output;
  27. private readonly IRepository<ItemType, Guid> _itemTypeRepository;
  28. private readonly IUnitOfWorkManager _unitOfWorkManager;
  29. public GuideTypeManagerTest( ITestOutputHelper output)
  30. {
  31. _output = output;
  32. //_dbContextProvider = GetRequiredService<IDbContextProvider<PeisDbContext>>();
  33. //_dbContextProvider = dbContextProvider;
  34. //_repository = Substitute.For<IRepository<GuideType,Guid>>();
  35. _repository = GetRequiredService<IRepository<GuideType, char>>();
  36. _itemTypeRepository = GetRequiredService<IRepository<ItemType, Guid>>();
  37. _manager = GetRequiredService<GuideTypeManager>();
  38. _unitOfWorkManager = GetRequiredService<IUnitOfWorkManager>();
  39. }
  40. [Fact]
  41. public async Task Should_Set_CanAdd()
  42. {
  43. var createEntity = new GuideType();
  44. createEntity.DisplayName = "normal";
  45. var item = await _manager.CreateAsync(createEntity);
  46. item = await _repository.InsertAsync(item,true);
  47. if(item != null)
  48. {
  49. Console.WriteLine(item.Id.ToString());
  50. }
  51. }
  52. [Fact]
  53. public async Task Should_Set_CanAdd_Sync()
  54. {
  55. var createEntity = new GuideType();
  56. createEntity.DisplayName = "normal";
  57. var item = await _manager.CreateAsync(createEntity);
  58. item = _repository.InsertAsync(item, true).Result;
  59. Console.WriteLine(item.Id.ToString());
  60. }
  61. [Fact]
  62. public async Task GetListAsync()
  63. {
  64. var items = await _repository.GetListAsync();
  65. items.ForEach(o =>
  66. {
  67. _output.WriteLine(o.DisplayName.ToString());
  68. });
  69. }
  70. [Fact]
  71. [UnitOfWork]
  72. public virtual async Task CheckAndDeleteAsync()
  73. {
  74. try
  75. {
  76. using (var uow = _unitOfWorkManager.Begin())
  77. {
  78. var entity = await _repository.GetAsync('0');
  79. await _manager.CheckAndDeleteAsync(entity);
  80. }
  81. }
  82. catch (Exception ex)
  83. {
  84. _output.WriteLine(ex.Message);
  85. }
  86. }
  87. [Fact]
  88. public async Task TestDataBase()
  89. {
  90. //var db = await _dbContextProvider.GetDbContextAsync();
  91. //var items = db.Users.ToList();
  92. //items.ForEach(o =>
  93. //{
  94. // Console.WriteLine(o.Id.ToString());
  95. //});
  96. }
  97. }
  98. }