From f721769fdcf4a1a2a34e9b0205530226a0e42a21 Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Wed, 7 Jul 2021 11:16:05 +0200 Subject: [PATCH] Added Tests for delete --- .../Persistence/Sql/SqlRepositoryTests.cs | 12 ++++++++++++ .../Persistence/InMemory/InMemoryRepositoryTests.cs | 11 +++++++++++ .../Persistence/Sql/BlogPostContext.cs | 2 ++ 3 files changed, 25 insertions(+) diff --git a/LinkDotNet.Blog.IntegrationTests/Infrastructure/Persistence/Sql/SqlRepositoryTests.cs b/LinkDotNet.Blog.IntegrationTests/Infrastructure/Persistence/Sql/SqlRepositoryTests.cs index fa6f5cf8..c3733412 100644 --- a/LinkDotNet.Blog.IntegrationTests/Infrastructure/Persistence/Sql/SqlRepositoryTests.cs +++ b/LinkDotNet.Blog.IntegrationTests/Infrastructure/Persistence/Sql/SqlRepositoryTests.cs @@ -104,5 +104,17 @@ public async Task ShouldFilterAndOrder() retrievedPosts[0].Id.Should().Be(olderPost.Id); retrievedPosts[1].Id.Should().Be(newerPost.Id); } + + [Fact] + public async Task ShouldDelete() + { + var blogPost = new BlogPostBuilder().Build(); + await BlogPostRepository.StoreAsync(blogPost); + + await BlogPostRepository.DeleteAsync(blogPost.Id); + + (await DbContext.BlogPosts.AsNoTracking().AnyAsync(b => b.Id == blogPost.Id)).Should().BeFalse(); + (await DbContext.Tags.AsNoTracking().AnyAsync(t => t.Id == blogPost.Id)).Should().BeFalse(); + } } } \ No newline at end of file diff --git a/LinkDotNet.Blog.UnitTests/Infrastructure/Persistence/InMemory/InMemoryRepositoryTests.cs b/LinkDotNet.Blog.UnitTests/Infrastructure/Persistence/InMemory/InMemoryRepositoryTests.cs index 8fbcbfcf..19aa403f 100644 --- a/LinkDotNet.Blog.UnitTests/Infrastructure/Persistence/InMemory/InMemoryRepositoryTests.cs +++ b/LinkDotNet.Blog.UnitTests/Infrastructure/Persistence/InMemory/InMemoryRepositoryTests.cs @@ -61,5 +61,16 @@ public async Task ShouldFilterAndOrder() retrievedPosts[0].Id.Should().Be(olderPost.Id); retrievedPosts[1].Id.Should().Be(newerPost.Id); } + + [Fact] + public async Task ShouldDelete() + { + var blogPost = new BlogPostBuilder().Build(); + await sut.StoreAsync(blogPost); + + await sut.DeleteAsync(blogPost.Id); + + (await sut.GetByIdAsync(blogPost.Id)).Should().BeNull(); + } } } \ No newline at end of file diff --git a/LinkDotNet.Infrastructure/Persistence/Sql/BlogPostContext.cs b/LinkDotNet.Infrastructure/Persistence/Sql/BlogPostContext.cs index af75db5b..5f0e887b 100644 --- a/LinkDotNet.Infrastructure/Persistence/Sql/BlogPostContext.cs +++ b/LinkDotNet.Infrastructure/Persistence/Sql/BlogPostContext.cs @@ -13,6 +13,8 @@ public BlogPostContext(DbContextOptions options) public DbSet BlogPosts { get; set; } + public DbSet Tags { get; set; } + protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity()