Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Doug Moore 48 posts 103 karma points c-trib
    Oct 06, 2021 @ 14:24
    Doug Moore
    0

    How to test content cache

    I have a solution for https://github.com/umbraco/Umbraco-CMS/issues/11074, but I would like to write a test for it. The issue I am having is figuring out how to test the Url based on the content cache. I am looking at Umbraco.Tests/Published/PropertyCacheLevelTests.cs as an example, but I'm not sure that is the right place. None of the service providers seem to give access to IPublishedContent or UrlProvder.

    I am still digging, but thought I might get a quicker answer here

  • Doug Moore 48 posts 103 karma points c-trib
    Oct 06, 2021 @ 14:51
    Doug Moore
    0

    I am instead looking at \Umbraco.Tests\PublishedContent\NuCacheTests.cs, which seems to be much more analogous to what I am trying to do.

    However, when the snapshot service creates a snapshot, the publishedContent.Name is null, when I would expect it to be It Works1!. Clearly I am missing something.

    The underlying publishedcontent.ContentData.Name is the value I expect publishedContent.Name to be.

  • Doug Moore 48 posts 103 karma points c-trib
    Oct 06, 2021 @ 16:17
    Doug Moore
    0

    OK, I got beyond this. I needed to create content that did not have a culture variant.

    Now I am trying to figure out how to simulate a cache rebuild. Because the test does not use a database, using _snapshotService.Rebuild() has null references.

  • Doug Moore 48 posts 103 karma points c-trib
    Oct 06, 2021 @ 16:34
    Doug Moore
    0

    Addendum, I actually just needed to do

    _contentType.Variations = ContentVariation.Nothing;
            _propertyType.Variations = ContentVariation.Nothing;
    

    before creating the snapshot, rather than creating a separate init(). I still have the problem of testing rebuild()

  • Doug Moore 48 posts 103 karma points c-trib
    Oct 06, 2021 @ 17:25
    Doug Moore
    0

    I am going to stop posting every 20 minutes on this. I may submit a PR with the change and see what happens. This really feels like something that should have a test, but the change is in \Umbraco.Web\PublishedCache\NuCache\PublishedSnapshotService.cs#GetDto. This is a private method that is only called from methods that make calls to the database. I am not aware of a way to perform that test, but if there is a way, I would love to learn how to write it.

  • Doug Moore 48 posts 103 karma points c-trib
    Oct 06, 2021 @ 18:28
    Doug Moore
    0

    I came across TestWithDatabaseBase and I am looking at that.

  • Doug Moore 48 posts 103 karma points c-trib
    Oct 06, 2021 @ 20:19
    Doug Moore
    0

    I seem to have gotten what I was looking for! I will try to remember to come back here and link my commit when it goes in.

    And once I got the test working.. I discovered a failure I didn't account for!

  • Doug Moore 48 posts 103 karma points c-trib
    Oct 08, 2021 @ 12:57
    Doug Moore
    100

    The commit that contains the code I used for using an actual database for testing: https://github.com/umbraco/Umbraco-CMS/pull/11313/commits/d309f118d1e827dc2247cc9c8d6ffd0d285161c1

Please Sign in or register to post replies

Write your reply to:

Draft