OrchardCMS / OrchardCore

Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
https://orchardcore.net
BSD 3-Clause "New" or "Revised" License
7.22k stars 2.34k forks source link

Indexing Providers: Unit Tests #15601

Open Skrypt opened 3 months ago

Skrypt commented 3 months ago

The Lucene unit tests are not covering all use cases. We are missing unit tests for the LuceneIndexingContentHandler and all the events that are possible.

  1. Create a content item.
  2. Publish a content item.
  3. Save a draft of a content item.
  4. Remove a content items.

The "index latest" option of a Lucene index needs also to be unit tested against all these events.

Piedone commented 3 months ago

How about the same for Elasticsearch?

hyzx86 commented 2 months ago

It looks like we can't test the Created function alone In my tests, they are not even saved to the database.

    await contentManager.CreateAsync(firstContent);
    var contentFromDb = await contentManager.GetAsync(firstContent.ContentItemId);
    Assert.NotNull(contentFromDb);
hishamco commented 2 months ago

Why?

hyzx86 commented 2 months ago

You can try this PR~~

https://github.com/OrchardCMS/OrchardCore/pull/13721/files#r1587500147

Comment part of the code, cannot pass

hyzx86 commented 2 months ago

We have to create content like this

                await contentManager.UpdateValidateAndCreateAsync(firstContent, VersionOptions.Draft);
                await contentManager.PublishAsync(firstContent);
                var contentFromDb = await contentManager.GetAsync(firstContent.ContentItemId);
                Assert.NotNull(contentFromDb);
hishamco commented 2 months ago

I will have a look if I have a time

hyzx86 commented 2 months ago

Without calling PublishAsync, we wouldn't even be able to find it from the database image

hishamco commented 2 months ago

This is a unit test, right? no database interaction

hyzx86 commented 2 months ago

Indeed in unit testing, The test context is BlogContext, which should use the Sqlite database. If I call PublishAsync, then this object can be retrieved from the database