Umbraco-CMS
Umbraco-CMS copied to clipboard
Integration tests not working with certain data types
Which exact Umbraco version are you using? For example: 9.0.1 - don't just write v9
9.1+
Bug summary
Trying to get integration tests working with the code example listed here: https://our.umbraco.com/Documentation/Implementation/Integration-Testing/, but it keeps on throwing errors. (Stacktrace attached on the bottom).
I did figure out why this is happening. The Umbraco logic that is causing this is here: https://github.com/umbraco/Umbraco-CMS/blob/v9/contrib/tests/Umbraco.Tests.Integration/DependencyInjection/UmbracoBuilderExtensions.cs#L72. I think this is some extension method for the tests in the Umbraco source code, but this will not work outside of that.
And because some data type editors calls .Localize, it'll also call that piece of code resulting in an error about not being able to find the /src. (https://github.com/umbraco/Umbraco-CMS/blob/v9/contrib/src/Umbraco.Infrastructure/PropertyEditors/ValueListConfigurationEditor.cs#L26).
System.IO.DirectoryNotFoundException : Could not find a part of the path 'D:\Projects\Test.Website\Test.Tests.Integration\bin\Debug\net5.0\src'.
at System.IO.Enumeration.FileSystemEnumerator`1.CreateDirectoryHandle(String path, Boolean ignoreNotFound)
at System.IO.Enumeration.FileSystemEnumerator`1.Init()
at System.IO.Enumeration.FileSystemEnumerator`1..ctor(String directory, Boolean isNormalized, EnumerationOptions options)
at System.IO.Enumeration.FileSystemEnumerable`1..ctor(String directory, FindTransform transform, EnumerationOptions options, Boolean isNormalized)
at System.IO.Enumeration.FileSystemEnumerableFactory.DirectoryInfos(String directory, String expression, EnumerationOptions options, Boolean isNormalized)
at System.IO.DirectoryInfo.InternalEnumerateInfos(String path, String searchPattern, SearchTarget searchTarget, EnumerationOptions options)
at System.IO.DirectoryInfo.GetDirectories(String searchPattern, EnumerationOptions enumerationOptions)
at System.IO.DirectoryInfo.GetDirectories(String searchPattern, SearchOption searchOption)
at Umbraco.Cms.Tests.Integration.DependencyInjection.UmbracoBuilderExtensions.<>c__DisplayClass1_0.<GetLocalizedTextService>b__0()
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
at Umbraco.Cms.Core.Services.Implement.LocalizedTextService.<>c__DisplayClass8_0.<.ctor>b__0()
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
at Umbraco.Cms.Core.Services.Implement.LocalizedTextService.get__dictionarySource()
at Umbraco.Cms.Core.Services.Implement.LocalizedTextService.GetFromDictionarySource(CultureInfo culture, String area, String key, IDictionary`2 tokens)
at Umbraco.Cms.Core.Services.Implement.LocalizedTextService.Localize(String area, String alias, CultureInfo culture, IDictionary`2 tokens)
at Umbraco.Extensions.LocalizedTextServiceExtensions.Localize(ILocalizedTextService manager, String area, String alias)
at Umbraco.Cms.Core.PropertyEditors.ValueListConfigurationEditor..ctor(ILocalizedTextService textService, IIOHelper ioHelper)
at Umbraco.Cms.Core.PropertyEditors.RadioButtonsPropertyEditor.CreateConfigurationEditor()
at Umbraco.Cms.Core.PropertyEditors.DataEditor.GetConfigurationEditor()
at Umbraco.Cms.Core.Models.DataType..ctor(IDataEditor editor, IConfigurationEditorJsonSerializer serializer, Int32 parentId)
at Umbraco.Cms.Infrastructure.Persistence.Factories.DataTypeFactory.BuildEntity(DataTypeDto dto, PropertyEditorCollection editors, ILogger`1 logger, IConfigurationEditorJsonSerializer serializer)
at Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement.DataTypeRepository.<PerformGetByQuery>b__6_0(DataTypeDto x)
at System.Linq.Enumerable.SelectListIterator`2.ToArray()
at Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement.DataTypeRepository.PerformGetByQuery(IQuery`1 query)
at Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement.EntityRepositoryBase`2.Get(IQuery`1 query)
at Umbraco.Cms.Core.Services.Implement.DataTypeService.GetDataType(Guid id)
at Umbraco.Cms.Infrastructure.Packaging.PackageDataInstallation.ImportDataTypes(IReadOnlyCollection`1 dataTypeElements, Int32 userId, IEnumerable`1& entityContainersInstalled)
at Umbraco.Cms.Infrastructure.Packaging.PackageDataInstallation.InstallPackageData(CompiledPackage compiledPackage, Int32 userId)
at Umbraco.Cms.Infrastructure.Packaging.PackageInstallation.InstallPackageData(CompiledPackage compiledPackage, Int32 userId, PackageDefinition& packageDefinition)
at Umbraco.Cms.Core.Services.Implement.PackagingService.InstallCompiledPackageData(XDocument packageXml, Int32 userId)
at Test.Tests.Integration.Tests.Tests.MySetup() in D:\Projects\Test.Website\Test.Tests.Integration\Tests\UnitTest1.cs:line 20
-----
One or more child tests had errors
Exception doesn't have a stacktrace
Start test 1: Ensure_No_Content_After_Doctype_Is_Deleted Failed
Specifics
Happens with the following data types:
- checkbox list
- dropdown
- dropdown multiple
- radiobox
Steps to reproduce
Follow the instructions in the blogpost Include checkbox or any of the other data types listed above
Expected result / actual result
System should not crash.
Ideally, localization should just use the default when the files aren't used and have the Umbraco specific tests override the access to the translation files. But maybe there is a better way of fixing this. This is probably also an issue on any other part in the integration tests that is using the .Localize function.
Thanks @patrickdemooij9 - not sure what you're trying to do, do you have some code sample of what you're trying to get working?
This code doesn't seem to be meant for v9 by the way, did you mean to use it in v8?
Hi @nul800sebastiaan, this is indeed meant for v9 (although it does say v8 in the documentation, but I assume that is an error). We followed the instructions of this video (https://www.youtube.com/watch?v=02mxZRIX2es).
This is the class we have:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Packaging;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Tests.Common.Testing;
using Umbraco.Cms.Tests.Integration.Testing;
namespace Nominow.Tests.Integration
{
[TestFixture]
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
public class Test : UmbracoIntegrationTest
{
[SetUp]
public void MySetup()
{
var xml = PackageMigrationResource.GetEmbeddedPackageDataManifest(this.GetType());
var packagingService = GetRequiredService<IPackagingService>();
packagingService.InstallCompiledPackageData(xml);
}
[Test]
public void Ensure_No_Content_After_Doctype_Is_Deleted()
{
var contentTypeService = GetRequiredService<IContentTypeService>();
var contentTypes = contentTypeService.GetAll();
Assert.AreEqual(true, contentTypes.Count() > 0);
foreach (var contentType in contentTypes)
{
if (contentType.ParentId == Constants.System.Root)
{
contentTypeService.Delete(contentType);
}
}
var contentService = GetRequiredService<IContentService>();
var contents = contentService.GetRootContent();
Assert.AreEqual(0, contents.Count());
Assert.AreEqual(0, contentTypeService.GetAll().Count());
}
}
}
I can't include the package.xml here because Github doesn't support it, so I changed it to a .txt file. You'll just have to rename it to an .xml file for testing. package.txt
We can also jump into a call on discord if that is easier!
I did figure out why this is happening. The Umbraco logic that is causing this is here: https://github.com/umbraco/Umbraco-CMS/blob/v9/contrib/tests/Umbraco.Tests.Integration/DependencyInjection/UmbracoBuilderExtensions.cs#L72. I think this is some extension method for the tests in the Umbraco source code, but this will not work outside of that.
Registering LocalizedTextService again using that code but with a valid path gets past the localized text service issue. Perhaps the integration test package could embed the localization files and have an option to look at a directory.
This issue persists in umbraco 11+
This issue persists in umbraco 12+
Would you believe it persists in 13+? 🙈