Skip to content

add CheckSameNameExpression for special situations.

Compare
Choose a tag to compare
@maliming maliming released this 21 Mar 07:07
· 29 commits to master since this release
[Fact]
public async Task CheckSameNameExpression_Test()
{
	var uowManager = LocalIocManager.Resolve<IUnitOfWorkManager>();

	using (var uow = uowManager.Begin()) {
		var repository = LocalIocManager.Resolve<IRepository<Region, long>>();
		var config = new GeneralTreeConfiguration<Region, long>
		{
			CheckSameNameExpression = (regionThis, regionCheck) =>
				regionThis.SomeForeignKey == regionCheck.SomeForeignKey
		};

		var manager =
			new GeneralTreeManager<Region, long>(repository, config);

		//Act
		await manager.CreateAsync(new Region
		{
			Name = "beijing",
			SomeForeignKey = 1
		});
		uowManager.Current.SaveChanges();

		//Act
		await manager.CreateAsync(new Region
		{
			Name = "beijing",
			SomeForeignKey = 2
		});
		uowManager.Current.SaveChanges();

		//Assert
		var beijing1 = repository.FirstOrDefault(x => x.Name == "beijing" && x.SomeForeignKey == 1);
		beijing1.ShouldNotBeNull();

		var beijing2 = repository.FirstOrDefault(x => x.Name == "beijing" && x.SomeForeignKey == 2);
		beijing2.ShouldNotBeNull();

		uow.Complete();
	}
}