Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrating tests that depend on Published Cache from the old test project #11242

Merged
merged 44 commits into from
Oct 19, 2021

Conversation

Shazwazza
Copy link
Contributor

@Shazwazza Shazwazza commented Oct 1, 2021

There are many tests that weren't ported to netcore due to their reliance on the published cache infrastructure. These tests primarily relied on the old XML cache implementation. These changes make it possible to translate the old XML structures into the 'nucache' Published Cache layer. This is all done in the Unit Tests project because it doesn't rely on integration tests, databases, etc...

The way this works is fairly simple:

  • There is a TestNuCacheContentService which is an implementation of INuCacheContentService used to populate nucache. This just takes a collection of ContentNodeKit just like what would happen on startup when we create collections of these from either reading from the bplustree file or from the db.
  • For the old XML based tests, there's an adapter: PublishedContentXmlAdapter.GetContentNodeKits. This gets passed some XML and it outputs IEnumerable<ContentNodeKit>. It also outputs a collection of ContentType and DataType that correspond with the XML data. These outputs are then also used to initialize the cache. An example of using this:
            // get some legacy xml
            string xml = GetXml();
            
            // generate some kits
            IEnumerable<ContentNodeKit> kits = PublishedContentXmlAdapter.GetContentNodeKits(
                xml,
                TestHelper.ShortStringHelper,
                out ContentType[] contentTypes,
                out DataType[] dataTypes).ToList();
    
            // initialize the cache with this data (this method is on the base class)
            InitializedCache(kits, contentTypes, dataTypes: dataTypes);
    
            // get the published snapshot (this is on the base class and initializes IPublishedSnapshotAccessor too)
            var snapshot = GetPublishedSnapshot();
    
            // now you can query content/media
            var content = snapshot.Content.GetById(123);
  • For tests that are not based on the legacy XML and if you just want to use nucache, there are some new builders:
    • ContentDataBuilder creates ContentData to be used to populate a ContentNodeKit for nucache. This builder will dynamically update any ContentType passed to the Build method based on the data being created in the builder. This helps save some code by not having to manually define all corresponding property types on the ContentType. This also allows for building up variant content data (the XML translator above does not support variant data because the Xml didn't support it).
          var contentType1 = new ContentType(ShortStringHelper, -1);
      
          ContentData item1Data = new ContentDataBuilder()
              .WithName("Content 1")
              .WithProperties(new PropertyDataBuilder()
                  .WithPropertyData("welcomeText", "Welcome")
                  .WithPropertyData("welcomeText", "Welcome", "en-US")
                  .WithPropertyData("welcomeText", "Willkommen", "de")
                  .WithPropertyData("welcomeText", "Welkom", "nl")
                  .WithPropertyData("welcomeText2", "Welcome")
                  .WithPropertyData("welcomeText2", "Welcome", "en-US")
                  .WithPropertyData("noprop", "xxx")
                  .Build())
              // build with a dynamically created content type
              .Build(ShortStringHelper, propertyDataTypes, contentType1, "ContentType1");
    • ContentNodeKitBuilder: builds a ContentNodeKit for use with nucache. It has a bunch of methods but for the most part it's simpler to use the helper method: ContentNodeKitBuilder.CreateWithContent which gets passed ContentData previously built. The data passed to the Path will dynamically set things like ParentId and Level, though those can be explicitly passed in too. Example (there's lots of examples in this PR):
           ContentNodeKit item1 = ContentNodeKitBuilder.CreateWithContent(
               contentType1.Id,
               1, "-1,1",
               draftData: item1Data,
               publishedData: item1Data);

Completed:

  • Delete all old tests, test files, etc... from the old test project that are no longer relevant or have been migrated
  • Migrates new v8 tests to the v9 test projects, there were several that weren't migrated after v8 - v9 merges
  • Fixes issue for ChildrenAsTable since that was broken
  • Removes old dead/test code
  • Migrates almost all published cache + routing tests

Breaking changes

These need reviewing but mostly it's just that we had models that should be immutable and based on ctor injection but they weren't. Now they are, but this means binary breaking changes, though some of these may be internal which would be ok. It would be simple to unbreak them by just making the properties mutable again and having an empty ctor overload. But these models should really be immutable in future versions!

TODO

There's only a few more tests to port over:

  • MediaUrlProviderTests
  • ScopedNuCacheTests - might be tricky, not really sure
  • AuthenticationControllerTests

With a little work the builder pattern for ContentNodeKit could probably be simplified further to make creating a nucache data source even easier.

Important!

I had to revert changes from #10845 for SiteDomainMapper + UrlProviderExtensions.

The changes in that PR break functionality and diverge from what is happening in v8. I've made a comment about this here: #10845 (comment)
I'm unsure if other parts of that PR break functionality but the SiteMapperChanges there break several of the tests that have been ported over such as nested domain tests, etc...

IMO I think the whole PR #10845 should be reverted and then re-investigated and also based on v8 because we haven't changed the logic there so if there's a bug, it will in theory also be in v8. And then whatever is fixed must be covered by these tests.

This PR

Next steps

Whenever migrating from v8 -> v9 make sure that you look at any new tests that have been written in the old test project, they will need to be manually moved.

@Shazwazza Shazwazza marked this pull request as ready for review October 1, 2021 18:26
@Shazwazza Shazwazza requested a review from bergmania October 1, 2021 18:26
…rl-collision' into v9/task/published-cache-tests
…ache-tests

# Conflicts:
#	src/Umbraco.Tests.UnitTests/Umbraco.Core/Collections/StackQueueTests.cs
#	src/Umbraco.Tests.UnitTests/Umbraco.Core/Routing/ContentFinderByAliasWithDomainsTests.cs
#	src/Umbraco.Tests.UnitTests/Umbraco.Core/Routing/ContentFinderByUrlWithDomainsTests.cs
#	src/Umbraco.Tests.UnitTests/Umbraco.Core/Routing/DomainsAndCulturesTests.cs
#	src/Umbraco.Tests.UnitTests/Umbraco.Core/Routing/UrlRoutingTestBase.cs
#	src/Umbraco.Tests.UnitTests/Umbraco.Core/Routing/UrlsProviderWithDomainsTests.cs
#	src/Umbraco.Tests.UnitTests/Umbraco.Core/Routing/UrlsWithNestedDomains.cs
#	src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/PublishedCache/ContentSerializationTests.cs
#	src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/PublishedCache/PublishedContentTests.cs
#	src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/PublishedCache/PublishedSnapshotServiceCollectionTests.cs
#	src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/PublishedCache/UrlRoutesTests.cs
#	src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Serialization/AutoInterningStringConverterTests.cs
#	src/Umbraco.Tests/Collections/StackQueueTests.cs
#	src/Umbraco.Tests/PublishedContent/ContentSerializationTests.cs
#	src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs
#	src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs
#	src/Umbraco.Tests/Routing/ContentFinderByAliasTests.cs
#	src/Umbraco.Tests/Routing/ContentFinderByAliasWithDomainsTests.cs
#	src/Umbraco.Tests/Routing/ContentFinderByUrlWithDomainsTests.cs
#	src/Umbraco.Tests/Routing/DomainsAndCulturesTests.cs
#	src/Umbraco.Tests/Routing/UrlRoutesTests.cs
#	src/Umbraco.Tests/Routing/UrlsProviderWithDomainsTests.cs
#	src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs
#	src/Umbraco.Tests/Serialization/AutoInterningStringConverterTests.cs
#	tests/Umbraco.Tests.Common/TestHelpers/PublishedContent/AutoPublishedContentType.cs
#	tests/Umbraco.Tests.Common/TestHelpers/PublishedContent/ContentType2.cs
#	tests/Umbraco.Tests.Common/TestHelpers/PublishedContent/ContentType2Sub.cs
#	tests/Umbraco.Tests.Common/TestHelpers/PublishedContent/InternalPublishedPropertyWithLanguageVariants.cs
#	tests/Umbraco.Tests.Common/TestHelpers/PublishedContent/PublishedContentStrong1.cs
#	tests/Umbraco.Tests.Common/TestHelpers/PublishedContent/PublishedContentStrong1Sub.cs
#	tests/Umbraco.Tests.Common/TestHelpers/PublishedContent/PublishedContentStrong2.cs
#	tests/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs
#	tests/Umbraco.Tests/Cache/PublishedCache/PublishedMediaCacheTests.cs
#	tests/Umbraco.Tests/Collections/StackQueueTests.cs
#	tests/Umbraco.Tests/Issues/U9560.cs
#	tests/Umbraco.Tests/LegacyXmlPublishedCache/ContentXmlDto.cs
#	tests/Umbraco.Tests/LegacyXmlPublishedCache/DictionaryPublishedContent.cs
#	tests/Umbraco.Tests/LegacyXmlPublishedCache/DomainCache.cs
#	tests/Umbraco.Tests/LegacyXmlPublishedCache/LegacyBackgroundTask/BackgroundTaskRunner.cs
#	tests/Umbraco.Tests/LegacyXmlPublishedCache/LegacyBackgroundTask/BackgroundTaskRunnerOptions.cs
#	tests/Umbraco.Tests/LegacyXmlPublishedCache/LegacyBackgroundTask/IBackgroundTask.cs
#	tests/Umbraco.Tests/LegacyXmlPublishedCache/LegacyBackgroundTask/IBackgroundTaskRunner.cs
#	tests/Umbraco.Tests/LegacyXmlPublishedCache/LegacyBackgroundTask/ILatchedBackgroundTask.cs
#	tests/Umbraco.Tests/LegacyXmlPublishedCache/LegacyBackgroundTask/LatchedBackgroundTaskBase.cs
#	tests/Umbraco.Tests/LegacyXmlPublishedCache/LegacyBackgroundTask/TaskEventArgs.cs
#	tests/Umbraco.Tests/LegacyXmlPublishedCache/LegacyBackgroundTask/ThreadingTaskImmutable.cs
#	tests/Umbraco.Tests/LegacyXmlPublishedCache/PreviewContent.cs
#	tests/Umbraco.Tests/LegacyXmlPublishedCache/PreviewXmlDto.cs
#	tests/Umbraco.Tests/LegacyXmlPublishedCache/PublishedContentCache.cs
#	tests/Umbraco.Tests/LegacyXmlPublishedCache/PublishedMediaCache.cs
#	tests/Umbraco.Tests/LegacyXmlPublishedCache/PublishedMember.cs
#	tests/Umbraco.Tests/LegacyXmlPublishedCache/PublishedMemberCache.cs
#	tests/Umbraco.Tests/LegacyXmlPublishedCache/PublishedSnapshot.cs
#	tests/Umbraco.Tests/LegacyXmlPublishedCache/RoutesCache.cs
#	tests/Umbraco.Tests/LegacyXmlPublishedCache/SafeXmlReaderWriter.cs
#	tests/Umbraco.Tests/LegacyXmlPublishedCache/UmbracoContextCache.cs
#	tests/Umbraco.Tests/LegacyXmlPublishedCache/XmlPublishedContent.cs
#	tests/Umbraco.Tests/LegacyXmlPublishedCache/XmlPublishedProperty.cs
#	tests/Umbraco.Tests/LegacyXmlPublishedCache/XmlPublishedSnapshotService.cs
#	tests/Umbraco.Tests/LegacyXmlPublishedCache/XmlStore.cs
#	tests/Umbraco.Tests/LegacyXmlPublishedCache/XmlStoreFilePersister.cs
#	tests/Umbraco.Tests/Models/ContentXmlTest.cs
#	tests/Umbraco.Tests/Models/MediaXmlTest.cs
#	tests/Umbraco.Tests/Persistence/FaultHandling/ConnectionRetryTest.cs
#	tests/Umbraco.Tests/Persistence/Mappers/MapperTestBase.cs
#	tests/Umbraco.Tests/Persistence/NPocoTests/PetaPocoCachesTest.cs
#	tests/Umbraco.Tests/Persistence/Querying/ContentTypeSqlMappingTests.cs
#	tests/Umbraco.Tests/Plugins/PluginManagerTests.cs
#	tests/Umbraco.Tests/PublishedContent/ContentSerializationTests.cs
#	tests/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs
#	tests/Umbraco.Tests/PublishedContent/NuCacheTests.cs
#	tests/Umbraco.Tests/PublishedContent/PublishedContentDataTableTests.cs
#	tests/Umbraco.Tests/PublishedContent/PublishedContentExtensionTests.cs
#	tests/Umbraco.Tests/PublishedContent/PublishedContentLanguageVariantTests.cs
#	tests/Umbraco.Tests/PublishedContent/PublishedContentMoreTests.cs
#	tests/Umbraco.Tests/PublishedContent/PublishedContentSnapshotTestBase.cs
#	tests/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs
#	tests/Umbraco.Tests/PublishedContent/PublishedContentTests.cs
#	tests/Umbraco.Tests/PublishedContent/PublishedMediaTests.cs
#	tests/Umbraco.Tests/PublishedContent/PublishedRouterTests.cs
#	tests/Umbraco.Tests/PublishedContent/RootNodeTests.cs
#	tests/Umbraco.Tests/PublishedContent/SolidPublishedSnapshot.cs
#	tests/Umbraco.Tests/PublishedContent/StronglyTypedModels/Home.cs
#	tests/Umbraco.Tests/Routing/ContentFinderByAliasTests.cs
#	tests/Umbraco.Tests/Routing/ContentFinderByAliasWithDomainsTests.cs
#	tests/Umbraco.Tests/Routing/ContentFinderByIdTests.cs
#	tests/Umbraco.Tests/Routing/ContentFinderByPageIdQueryTests.cs
#	tests/Umbraco.Tests/Routing/ContentFinderByUrlAndTemplateTests.cs
#	tests/Umbraco.Tests/Routing/ContentFinderByUrlTests.cs
#	tests/Umbraco.Tests/Routing/ContentFinderByUrlWithDomainsTests.cs
#	tests/Umbraco.Tests/Routing/DomainsAndCulturesTests.cs
#	tests/Umbraco.Tests/Routing/GetContentUrlsTests.cs
#	tests/Umbraco.Tests/Routing/RouteTestExtensions.cs
#	tests/Umbraco.Tests/Routing/RoutesCacheTests.cs
#	tests/Umbraco.Tests/Routing/UrlProviderWithHideTopLevelNodeFromPathTests.cs
#	tests/Umbraco.Tests/Routing/UrlProviderWithoutHideTopLevelNodeFromPathTests.cs
#	tests/Umbraco.Tests/Routing/UrlRoutesTests.cs
#	tests/Umbraco.Tests/Routing/UrlRoutingTestBase.cs
#	tests/Umbraco.Tests/Routing/UrlsProviderWithDomainsTests.cs
#	tests/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs
#	tests/Umbraco.Tests/Scoping/PassThroughEventDispatcherTests.cs
#	tests/Umbraco.Tests/Scoping/ScopedXmlTests.cs
#	tests/Umbraco.Tests/Serialization/AutoInterningStringConverterTests.cs
#	tests/Umbraco.Tests/Services/Importing/Dictionary-Package.xml
#	tests/Umbraco.Tests/Services/TestWithSomeContentBase.cs
#	tests/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs
#	tests/Umbraco.Tests/TestHelpers/BaseWebTest.cs
#	tests/Umbraco.Tests/TestHelpers/ControllerTesting/AuthenticateEverythingExtensions.cs
#	tests/Umbraco.Tests/TestHelpers/ControllerTesting/AuthenticateEverythingMiddleware.cs
#	tests/Umbraco.Tests/TestHelpers/ControllerTesting/SpecificAssemblyResolver.cs
#	tests/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivator.cs
#	tests/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs
#	tests/Umbraco.Tests/TestHelpers/ControllerTesting/TestStartup.cs
#	tests/Umbraco.Tests/TestHelpers/ControllerTesting/TraceExceptionLogger.cs
#	tests/Umbraco.Tests/TestHelpers/Entities/MockedContent.cs
#	tests/Umbraco.Tests/TestHelpers/Entities/MockedContentTypes.cs
#	tests/Umbraco.Tests/TestHelpers/Entities/MockedEntity.cs
#	tests/Umbraco.Tests/TestHelpers/Entities/MockedMedia.cs
#	tests/Umbraco.Tests/TestHelpers/Entities/MockedMember.cs
#	tests/Umbraco.Tests/TestHelpers/Entities/MockedPropertyTypes.cs
#	tests/Umbraco.Tests/TestHelpers/Entities/MockedUser.cs
#	tests/Umbraco.Tests/TestHelpers/Entities/MockedUserGroup.cs
#	tests/Umbraco.Tests/TestHelpers/FakeHttpContextFactory.cs
#	tests/Umbraco.Tests/TestHelpers/Stubs/TestControllerFactory.cs
#	tests/Umbraco.Tests/TestHelpers/Stubs/TestExamineManager.cs
#	tests/Umbraco.Tests/TestHelpers/Stubs/TestLastChanceFinder.cs
#	tests/Umbraco.Tests/TestHelpers/Stubs/TestUserPasswordConfig.cs
#	tests/Umbraco.Tests/TestHelpers/TestHelper.cs
#	tests/Umbraco.Tests/TestHelpers/TestObjects-Mocks.cs
#	tests/Umbraco.Tests/TestHelpers/TestObjects.cs
#	tests/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs
#	tests/Umbraco.Tests/Testing/Objects/Accessors/NoHttpContextAccessor.cs
#	tests/Umbraco.Tests/Testing/Objects/TestDataSource.cs
#	tests/Umbraco.Tests/Testing/UmbracoTestBase.cs
#	tests/Umbraco.Tests/Web/HttpCookieExtensionsTests.cs
#	tests/Umbraco.Tests/Web/Mvc/ViewDataDictionaryExtensionTests.cs
#	tests/Umbraco.Tests/masterpages/site1/template2.master
@bergmania bergmania merged commit c77dc5d into v9/dev Oct 19, 2021
@bergmania bergmania deleted the v9/task/published-cache-tests branch October 19, 2021 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants