1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- using System.Linq;
- using VCommon.VEntityFrameworkCore.Tests.Efc;
- using VCommon.VEntityFrameworkCore.Tests.Entities;
- using VCommon.VEntityFrameworkCore.Tests.Repo;
- using Xunit;
- using Xunit.Abstractions;
- namespace VCommon.VEntityFrameworkCore.Tests
- {
- public class RepoTest
- {
- private readonly ITestOutputHelper _output;
- public RepoTest(ITestOutputHelper output)
- {
- _output = output;
- using var ctx = new TestDbContext(_output);
- //seeding
- if (!ctx.TestEntities.Any(p => p.Name == "Deleted"))
- {
- ctx.TestEntities.Add(new TestEntity
- {
- Name = "Deleted",
- IsAbolish = true,
- IsEnable = true,
- });
- }
- ctx.SaveChanges();
- if (!ctx.TestEntities.Any(p => p.Name == "Disabled"))
- {
- ctx.TestEntities.Add(new TestEntity
- {
- Name = "Disabled",
- IsAbolish = false,
- IsEnable = false,
- });
- }
- ctx.SaveChanges();
- if (!ctx.TestEntities.Any(p => p.Name == "Normal"))
- {
- ctx.TestEntities.Add(new TestEntity
- {
- Name = "Normal",
- IsAbolish = false,
- IsEnable = true,
- });
- }
- ctx.SaveChanges();
- }
- [Fact]
- public void FilterTest()
- {
- var repo = new TestRepository<TestEntity>(_output);
- Assert.Equal(1, repo.QueryNoTracking().Count());
- repo.DisableFilter(VEfDataFilters.Passive);
- Assert.Equal(2, repo.QueryNoTracking().Count());
- repo.DisableFilter(VEfDataFilters.SoftDelete);
- Assert.Equal(3, repo.QueryNoTracking().Count());
- }
- }
- }
|