Skip to content

Commit 48c6d9d

Browse files
committed
Added explicit cache tests and remove unused logic in delete
1 parent b4ee5b2 commit 48c6d9d

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

LinkDotNet.Blog.Infrastructure/Persistence/CachedRepository.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ public async ValueTask StoreAsync(T entity)
6464
public async ValueTask DeleteAsync(string id)
6565
{
6666
ResetCache();
67-
memoryCache.Remove(id);
6867
await repository.DeleteAsync(id);
6968
}
7069

LinkDotNet.Blog.IntegrationTests/Infrastructure/Persistence/CachedRepositoryTests.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,36 @@ public async Task ShouldNotCacheWhenDifferentQueries()
3030
allWithTag2.Count.Should().Be(1);
3131
allWithTag2.Single().Tags.Single().Content.Should().Be("tag 2");
3232
}
33+
34+
[Fact]
35+
public async Task ShouldResetOnDelete()
36+
{
37+
var bp1 = new BlogPostBuilder().WithTitle("1").Build();
38+
var bp2 = new BlogPostBuilder().WithTitle("2").Build();
39+
var sut = new CachedRepository<BlogPost>(Repository, new MemoryCache(new MemoryCacheOptions()));
40+
await sut.StoreAsync(bp1);
41+
await sut.StoreAsync(bp2);
42+
await sut.GetAllAsync();
43+
await sut.DeleteAsync(bp1.Id);
44+
45+
var db = await sut.GetAllAsync();
46+
47+
db.Single().Title.Should().Be("2");
48+
}
49+
50+
[Fact]
51+
public async Task ShouldResetOnSave()
52+
{
53+
var bp1 = new BlogPostBuilder().WithTitle("1").Build();
54+
var bp2 = new BlogPostBuilder().WithTitle("2").Build();
55+
var sut = new CachedRepository<BlogPost>(Repository, new MemoryCache(new MemoryCacheOptions()));
56+
await sut.StoreAsync(bp1);
57+
await sut.GetAllAsync();
58+
bp1.Update(bp2);
59+
await sut.StoreAsync(bp1);
60+
61+
var db = await sut.GetAllAsync();
62+
63+
db.Single().Title.Should().Be("2");
64+
}
3365
}

LinkDotNet.Blog.UnitTests/Web/Pages/Admin/SitemapTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ public void ShouldDisplaySitemap()
4040
var sitemap = new SitemapUrlSet
4141
{
4242
Urls = new List<SitemapUrl>
43-
{
44-
new() { Location = "loc", LastModified = "Now" },
45-
},
43+
{
44+
new() { Location = "loc", LastModified = "Now" },
45+
},
4646
};
4747
sitemapMock.Setup(s => s.CreateSitemapAsync())
4848
.ReturnsAsync(sitemap);
@@ -65,9 +65,9 @@ public void ShouldShowLoadingWhenGenerating()
6565
var sitemap = new SitemapUrlSet
6666
{
6767
Urls = new List<SitemapUrl>
68-
{
69-
new() { Location = "loc", LastModified = "Now" },
70-
},
68+
{
69+
new() { Location = "loc", LastModified = "Now" },
70+
},
7171
};
7272
sitemapMock.Setup(s => s.CreateSitemapAsync())
7373
.Returns(async () =>

0 commit comments

Comments
 (0)