Skip to content

Commit f721769

Browse files
committed
Added Tests for delete
1 parent 315d179 commit f721769

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

LinkDotNet.Blog.IntegrationTests/Infrastructure/Persistence/Sql/SqlRepositoryTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,17 @@ public async Task ShouldFilterAndOrder()
104104
retrievedPosts[0].Id.Should().Be(olderPost.Id);
105105
retrievedPosts[1].Id.Should().Be(newerPost.Id);
106106
}
107+
108+
[Fact]
109+
public async Task ShouldDelete()
110+
{
111+
var blogPost = new BlogPostBuilder().Build();
112+
await BlogPostRepository.StoreAsync(blogPost);
113+
114+
await BlogPostRepository.DeleteAsync(blogPost.Id);
115+
116+
(await DbContext.BlogPosts.AsNoTracking().AnyAsync(b => b.Id == blogPost.Id)).Should().BeFalse();
117+
(await DbContext.Tags.AsNoTracking().AnyAsync(t => t.Id == blogPost.Id)).Should().BeFalse();
118+
}
107119
}
108120
}

LinkDotNet.Blog.UnitTests/Infrastructure/Persistence/InMemory/InMemoryRepositoryTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,16 @@ public async Task ShouldFilterAndOrder()
6161
retrievedPosts[0].Id.Should().Be(olderPost.Id);
6262
retrievedPosts[1].Id.Should().Be(newerPost.Id);
6363
}
64+
65+
[Fact]
66+
public async Task ShouldDelete()
67+
{
68+
var blogPost = new BlogPostBuilder().Build();
69+
await sut.StoreAsync(blogPost);
70+
71+
await sut.DeleteAsync(blogPost.Id);
72+
73+
(await sut.GetByIdAsync(blogPost.Id)).Should().BeNull();
74+
}
6475
}
6576
}

LinkDotNet.Infrastructure/Persistence/Sql/BlogPostContext.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public BlogPostContext(DbContextOptions options)
1313

1414
public DbSet<BlogPost> BlogPosts { get; set; }
1515

16+
public DbSet<Tag> Tags { get; set; }
17+
1618
protected override void OnModelCreating(ModelBuilder modelBuilder)
1719
{
1820
modelBuilder.Entity<BlogPost>()

0 commit comments

Comments
 (0)