Skip to content

Updating Tags in a blog post doesn't update #101

Closed
@linkdotnet

Description

@linkdotnet

When updating a blog post and changing the tags, after change those tags are not visible in the overview page nor in the search (for tags).

Root-Cause

When entering the update blog post page, the blog post is retrieved from the cache rather than the underlying repository.
That leads to the problem, that the children are not tracked anymore and therefore don't get updated.

Test to reproduce

[Fact]
public async Task GivenBlogPostWithTags_WhenLoadingAndDeleting_ThenShouldBeUpdated()
{
    var bp = new BlogPostBuilder().WithTags("tag 1").Build();
    var sut = new CachedRepository<BlogPost>(Repository, new MemoryCache(new MemoryCacheOptions()));
    await sut.StoreAsync(bp);
    var updateBp = new BlogPostBuilder().WithTags("tag 2").Build();
    var bpFromCache = await sut.GetByIdAsync(bp.Id);
    bpFromCache.Update(updateBp);
    await sut.StoreAsync(bpFromCache);

    var bpFromDb = await sut.GetByIdAsync(bp.Id);

    bpFromDb.Tags.Single().Content.Should().Be("tag 2");
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-sqlbugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions