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.

107 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. namespace Shentun.Peis
  19. {
  20. public class GuideTypeManagerTest : PeisDomainTestBase
  21. {
  22. private readonly IRepository<GuideType, char> _repository;
  23. private readonly GuideTypeManager _manager;
  24. //private readonly IDbContextProvider<PeisDbContext> _dbContextProvider;
  25. private readonly ITestOutputHelper _output;
  26. private readonly IRepository<ItemType, Guid> _itemTypeRepository;
  27. private readonly IUnitOfWorkManager _unitOfWorkManager;
  28. public GuideTypeManagerTest( ITestOutputHelper output)
  29. {
  30. _output = output;
  31. //_dbContextProvider = GetRequiredService<IDbContextProvider<PeisDbContext>>();
  32. //_dbContextProvider = dbContextProvider;
  33. //_repository = Substitute.For<IRepository<GuideType,Guid>>();
  34. _repository = GetRequiredService<IRepository<GuideType, char>>();
  35. _itemTypeRepository = GetRequiredService<IRepository<ItemType, Guid>>();
  36. _manager = GetRequiredService<GuideTypeManager>();
  37. _unitOfWorkManager = GetRequiredService<IUnitOfWorkManager>();
  38. }
  39. [Fact]
  40. public async Task Should_Set_CanAdd()
  41. {
  42. var createEntity = new GuideType();
  43. createEntity.DisplayName = "normal";
  44. var item = await _manager.CreateAsync(createEntity);
  45. item = await _repository.InsertAsync(item,true);
  46. if(item != null)
  47. {
  48. Console.WriteLine(item.Id.ToString());
  49. }
  50. }
  51. [Fact]
  52. public async Task Should_Set_CanAdd_Sync()
  53. {
  54. var createEntity = new GuideType();
  55. createEntity.DisplayName = "normal";
  56. var item = await _manager.CreateAsync(createEntity);
  57. item = _repository.InsertAsync(item, true).Result;
  58. Console.WriteLine(item.Id.ToString());
  59. }
  60. [Fact]
  61. public async Task GetListAsync()
  62. {
  63. var items = await _repository.GetListAsync();
  64. items.ForEach(o =>
  65. {
  66. _output.WriteLine(o.DisplayName.ToString());
  67. });
  68. }
  69. [Fact]
  70. [UnitOfWork]
  71. public virtual async Task CheckAndDeleteAsync()
  72. {
  73. try
  74. {
  75. using (var uow = _unitOfWorkManager.Begin())
  76. {
  77. var entity = await _repository.GetAsync('0');
  78. await _manager.CheckAndDeleteAsync(entity);
  79. }
  80. }
  81. catch (Exception ex)
  82. {
  83. _output.WriteLine(ex.Message);
  84. }
  85. }
  86. [Fact]
  87. public async Task TestDataBase()
  88. {
  89. //var db = await _dbContextProvider.GetDbContextAsync();
  90. //var items = db.Users.ToList();
  91. //items.ForEach(o =>
  92. //{
  93. // Console.WriteLine(o.Id.ToString());
  94. //});
  95. }
  96. }
  97. }