RepoTest.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System.Linq;
  2. using VCommon.VEntityFrameworkCore.Tests.Efc;
  3. using VCommon.VEntityFrameworkCore.Tests.Entities;
  4. using VCommon.VEntityFrameworkCore.Tests.Repo;
  5. using Xunit;
  6. using Xunit.Abstractions;
  7. namespace VCommon.VEntityFrameworkCore.Tests
  8. {
  9. public class RepoTest
  10. {
  11. private readonly ITestOutputHelper _output;
  12. public RepoTest(ITestOutputHelper output)
  13. {
  14. _output = output;
  15. using var ctx = new TestDbContext(_output);
  16. //seeding
  17. if (!ctx.TestEntities.Any(p => p.Name == "Deleted"))
  18. {
  19. ctx.TestEntities.Add(new TestEntity
  20. {
  21. Name = "Deleted",
  22. IsAbolish = true,
  23. IsEnable = true,
  24. });
  25. }
  26. ctx.SaveChanges();
  27. if (!ctx.TestEntities.Any(p => p.Name == "Disabled"))
  28. {
  29. ctx.TestEntities.Add(new TestEntity
  30. {
  31. Name = "Disabled",
  32. IsAbolish = false,
  33. IsEnable = false,
  34. });
  35. }
  36. ctx.SaveChanges();
  37. if (!ctx.TestEntities.Any(p => p.Name == "Normal"))
  38. {
  39. ctx.TestEntities.Add(new TestEntity
  40. {
  41. Name = "Normal",
  42. IsAbolish = false,
  43. IsEnable = true,
  44. });
  45. }
  46. ctx.SaveChanges();
  47. }
  48. [Fact]
  49. public void FilterTest()
  50. {
  51. var repo = new TestRepository<TestEntity>(_output);
  52. Assert.Equal(1, repo.QueryNoTracking().Count());
  53. repo.DisableFilter(VEfDataFilters.Passive);
  54. Assert.Equal(2, repo.QueryNoTracking().Count());
  55. repo.DisableFilter(VEfDataFilters.SoftDelete);
  56. Assert.Equal(3, repo.QueryNoTracking().Count());
  57. }
  58. }
  59. }