mirror of https://github.com/abpframework/abp.git
committed by
GitHub
7 changed files with 106 additions and 6 deletions
@ -1,9 +1,49 @@ |
|||||
using Volo.Abp.TestApp.Testing; |
using System; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using Shouldly; |
||||
|
using Volo.Abp.Domain.Repositories; |
||||
|
using Volo.Abp.TestApp; |
||||
|
using Volo.Abp.TestApp.Domain; |
||||
|
using Volo.Abp.TestApp.Testing; |
||||
|
using Volo.Abp.Uow; |
||||
|
using Xunit; |
||||
|
|
||||
namespace Volo.Abp.EntityFrameworkCore.DataFiltering |
namespace Volo.Abp.EntityFrameworkCore.DataFiltering |
||||
{ |
{ |
||||
|
/// <summary>
|
||||
|
/// This is just to test the cascade delete behavior of EF Core's navigation properties.
|
||||
|
/// Soft delete is usually only used in the aggregate root entity instead <see cref="Book" />.
|
||||
|
/// </summary>
|
||||
public class SoftDelete_Tests : SoftDelete_Tests<AbpEntityFrameworkCoreTestModule> |
public class SoftDelete_Tests : SoftDelete_Tests<AbpEntityFrameworkCoreTestModule> |
||||
{ |
{ |
||||
|
[Fact] |
||||
|
public async Task Navigation_Properties_Cascade_Delete_Test() |
||||
|
{ |
||||
|
var authorRepository = GetRequiredService<IRepository<Author, Guid>>(); |
||||
|
var authorId = Guid.NewGuid(); |
||||
|
|
||||
|
var author = new Author(authorId, "tom"); |
||||
|
author.Books.Add(new Book(authorId, Guid.NewGuid(), "asp net core")); |
||||
|
author.Books.Add(new Book(authorId, Guid.NewGuid(),"c#")); |
||||
|
await authorRepository.InsertAsync(author); |
||||
|
|
||||
|
await WithUnitOfWorkAsync(async () => |
||||
|
{ |
||||
|
var author = await authorRepository.GetAsync(authorId); |
||||
|
author.Books.ShouldNotBeEmpty(); |
||||
|
author.Books.Count.ShouldBe(2); |
||||
|
|
||||
|
author.Books.Clear(); |
||||
|
await authorRepository.UpdateAsync(author); |
||||
|
}); |
||||
|
|
||||
|
using (DataFilter.Disable<ISoftDelete>()) |
||||
|
{ |
||||
|
author = await authorRepository.GetAsync(authorId); |
||||
|
author.Books.ShouldNotBeEmpty(); |
||||
|
author.Books.ShouldAllBe(x => x.IsDeleted); |
||||
|
} |
||||
|
} |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,25 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using Volo.Abp.Domain.Entities; |
||||
|
|
||||
|
namespace Volo.Abp.TestApp.Domain |
||||
|
{ |
||||
|
public class Author : AggregateRoot<Guid> |
||||
|
{ |
||||
|
public string Name { get; set; } |
||||
|
|
||||
|
public ICollection<Book> Books { get; set; } |
||||
|
|
||||
|
private Author() |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public Author(Guid id, string name) |
||||
|
: base(id) |
||||
|
{ |
||||
|
Name = name; |
||||
|
Books = new List<Book>(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,27 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using Volo.Abp.Domain.Entities; |
||||
|
|
||||
|
namespace Volo.Abp.TestApp.Domain |
||||
|
{ |
||||
|
public class Book : Entity<Guid>, ISoftDelete |
||||
|
{ |
||||
|
public Guid AuthorId { get; set; } |
||||
|
|
||||
|
public string Title { get; set; } |
||||
|
|
||||
|
private Book() |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public Book(Guid authorId, Guid id, string title) |
||||
|
{ |
||||
|
Id = id; |
||||
|
AuthorId = authorId; |
||||
|
Title = title; |
||||
|
} |
||||
|
|
||||
|
public bool IsDeleted { get; set; } |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue