Skip to content

Commit

Permalink
Added Tests for delete
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdotnet committed Jul 7, 2021
1 parent 315d179 commit f721769
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
2 changes: 2 additions & 0 deletions LinkDotNet.Infrastructure/Persistence/Sql/BlogPostContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public BlogPostContext(DbContextOptions options)

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

public DbSet<Tag> Tags { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<BlogPost>()
Expand Down

0 comments on commit f721769

Please sign in to comment.