diff --git a/src/Umbraco.Core/Extensions/UdiGetterExtensions.cs b/src/Umbraco.Core/Extensions/UdiGetterExtensions.cs
index e4b11ccb6cec..66c5002604a3 100644
--- a/src/Umbraco.Core/Extensions/UdiGetterExtensions.cs
+++ b/src/Umbraco.Core/Extensions/UdiGetterExtensions.cs
@@ -8,7 +8,7 @@
namespace Umbraco.Extensions;
///
-/// Provides extension methods that return udis for Umbraco entities.
+/// Provides extension methods that return UDIs for Umbraco entities.
///
public static class UdiGetterExtensions
{
@@ -19,11 +19,29 @@ public static class UdiGetterExtensions
///
/// The entity identifier of the entity.
///
- public static GuidUdi GetUdi(this ITemplate entity)
+ public static Udi GetUdi(this IEntity entity)
{
ArgumentNullException.ThrowIfNull(entity);
- return new GuidUdi(Constants.UdiEntityType.Template, entity.Key).EnsureClosed();
+ return entity switch
+ {
+ // Concrete types
+ EntityContainer container => container.GetUdi(),
+ Script script => script.GetUdi(),
+ Stylesheet stylesheet => stylesheet.GetUdi(),
+ // Interfaces
+ IContentBase contentBase => contentBase.GetUdi(),
+ IContentTypeComposition contentTypeComposition => contentTypeComposition.GetUdi(),
+ IDataType dataType => dataType.GetUdi(),
+ IDictionaryItem dictionaryItem => dictionaryItem.GetUdi(),
+ ILanguage language => language.GetUdi(),
+ IMemberGroup memberGroup => memberGroup.GetUdi(),
+ IPartialView partialView => partialView.GetUdi(),
+ IRelationType relationType => relationType.GetUdi(),
+ ITemplate template => template.GetUdi(),
+ IWebhook webhook => webhook.GetUdi(),
+ _ => throw new NotSupportedException($"Entity type {entity.GetType().FullName} is not supported."),
+ };
}
///
@@ -33,11 +51,33 @@ public static GuidUdi GetUdi(this ITemplate entity)
///
/// The entity identifier of the entity.
///
- public static GuidUdi GetUdi(this IContentType entity)
+ public static GuidUdi GetUdi(this EntityContainer entity)
{
ArgumentNullException.ThrowIfNull(entity);
- return new GuidUdi(Constants.UdiEntityType.DocumentType, entity.Key).EnsureClosed();
+ string entityType;
+ if (entity.ContainedObjectType == Constants.ObjectTypes.DataType)
+ {
+ entityType = Constants.UdiEntityType.DataTypeContainer;
+ }
+ else if (entity.ContainedObjectType == Constants.ObjectTypes.DocumentType)
+ {
+ entityType = Constants.UdiEntityType.DocumentTypeContainer;
+ }
+ else if (entity.ContainedObjectType == Constants.ObjectTypes.MediaType)
+ {
+ entityType = Constants.UdiEntityType.MediaTypeContainer;
+ }
+ else if (entity.ContainedObjectType == Constants.ObjectTypes.DocumentBlueprint)
+ {
+ entityType = Constants.UdiEntityType.DocumentBlueprintContainer;
+ }
+ else
+ {
+ throw new NotSupportedException($"Contained object type {entity.ContainedObjectType} is not supported.");
+ }
+
+ return new GuidUdi(entityType, entity.Key).EnsureClosed();
}
///
@@ -47,11 +87,11 @@ public static GuidUdi GetUdi(this IContentType entity)
///
/// The entity identifier of the entity.
///
- public static GuidUdi GetUdi(this IMediaType entity)
+ public static StringUdi GetUdi(this Script entity)
{
ArgumentNullException.ThrowIfNull(entity);
- return new GuidUdi(Constants.UdiEntityType.MediaType, entity.Key).EnsureClosed();
+ return GetUdiFromPath(Constants.UdiEntityType.Script, entity.Path);
}
///
@@ -61,11 +101,11 @@ public static GuidUdi GetUdi(this IMediaType entity)
///
/// The entity identifier of the entity.
///
- public static GuidUdi GetUdi(this IMemberType entity)
+ public static StringUdi GetUdi(this Stylesheet entity)
{
ArgumentNullException.ThrowIfNull(entity);
- return new GuidUdi(Constants.UdiEntityType.MemberType, entity.Key).EnsureClosed();
+ return GetUdiFromPath(Constants.UdiEntityType.Stylesheet, entity.Path);
}
///
@@ -75,11 +115,17 @@ public static GuidUdi GetUdi(this IMemberType entity)
///
/// The entity identifier of the entity.
///
- public static GuidUdi GetUdi(this IMemberGroup entity)
+ public static GuidUdi GetUdi(this IContentBase entity)
{
ArgumentNullException.ThrowIfNull(entity);
- return new GuidUdi(Constants.UdiEntityType.MemberGroup, entity.Key).EnsureClosed();
+ return entity switch
+ {
+ IContent content => content.GetUdi(),
+ IMedia media => media.GetUdi(),
+ IMember member => member.GetUdi(),
+ _ => throw new NotSupportedException($"Content base type {entity.GetType().FullName} is not supported."),
+ };
}
///
@@ -89,17 +135,11 @@ public static GuidUdi GetUdi(this IMemberGroup entity)
///
/// The entity identifier of the entity.
///
- public static GuidUdi GetUdi(this IContentTypeComposition entity)
+ public static GuidUdi GetUdi(this IContent entity)
{
ArgumentNullException.ThrowIfNull(entity);
- string entityType = entity switch
- {
- IContentType => Constants.UdiEntityType.DocumentType,
- IMediaType => Constants.UdiEntityType.MediaType,
- IMemberType => Constants.UdiEntityType.MemberType,
- _ => throw new NotSupportedException(string.Format("Composition type {0} is not supported.", entity.GetType().FullName)),
- };
+ string entityType = entity.Blueprint ? Constants.UdiEntityType.DocumentBlueprint : Constants.UdiEntityType.Document;
return new GuidUdi(entityType, entity.Key).EnsureClosed();
}
@@ -111,11 +151,11 @@ public static GuidUdi GetUdi(this IContentTypeComposition entity)
///
/// The entity identifier of the entity.
///
- public static GuidUdi GetUdi(this IDataType entity)
+ public static GuidUdi GetUdi(this IMedia entity)
{
ArgumentNullException.ThrowIfNull(entity);
- return new GuidUdi(Constants.UdiEntityType.DataType, entity.Key).EnsureClosed();
+ return new GuidUdi(Constants.UdiEntityType.Media, entity.Key).EnsureClosed();
}
///
@@ -125,33 +165,11 @@ public static GuidUdi GetUdi(this IDataType entity)
///
/// The entity identifier of the entity.
///
- public static GuidUdi GetUdi(this EntityContainer entity)
+ public static GuidUdi GetUdi(this IMember entity)
{
ArgumentNullException.ThrowIfNull(entity);
- string entityType;
- if (entity.ContainedObjectType == Constants.ObjectTypes.DataType)
- {
- entityType = Constants.UdiEntityType.DataTypeContainer;
- }
- else if (entity.ContainedObjectType == Constants.ObjectTypes.DocumentType)
- {
- entityType = Constants.UdiEntityType.DocumentTypeContainer;
- }
- else if (entity.ContainedObjectType == Constants.ObjectTypes.MediaType)
- {
- entityType = Constants.UdiEntityType.MediaTypeContainer;
- }
- else if (entity.ContainedObjectType == Constants.ObjectTypes.DocumentBlueprint)
- {
- entityType = Constants.UdiEntityType.DocumentBlueprintContainer;
- }
- else
- {
- throw new NotSupportedException(string.Format("Contained object type {0} is not supported.", entity.ContainedObjectType));
- }
-
- return new GuidUdi(entityType, entity.Key).EnsureClosed();
+ return new GuidUdi(Constants.UdiEntityType.Member, entity.Key).EnsureClosed();
}
///
@@ -161,11 +179,17 @@ public static GuidUdi GetUdi(this EntityContainer entity)
///
/// The entity identifier of the entity.
///
- public static GuidUdi GetUdi(this IMedia entity)
+ public static GuidUdi GetUdi(this IContentTypeComposition entity)
{
ArgumentNullException.ThrowIfNull(entity);
- return new GuidUdi(Constants.UdiEntityType.Media, entity.Key).EnsureClosed();
+ return entity switch
+ {
+ IContentType contentType => contentType.GetUdi(),
+ IMediaType mediaType => mediaType.GetUdi(),
+ IMemberType memberType => memberType.GetUdi(),
+ _ => throw new NotSupportedException($"Composition type {entity.GetType().FullName} is not supported."),
+ };
}
///
@@ -175,13 +199,11 @@ public static GuidUdi GetUdi(this IMedia entity)
///
/// The entity identifier of the entity.
///
- public static GuidUdi GetUdi(this IContent entity)
+ public static GuidUdi GetUdi(this IContentType entity)
{
ArgumentNullException.ThrowIfNull(entity);
- string entityType = entity.Blueprint ? Constants.UdiEntityType.DocumentBlueprint : Constants.UdiEntityType.Document;
-
- return new GuidUdi(entityType, entity.Key).EnsureClosed();
+ return new GuidUdi(Constants.UdiEntityType.DocumentType, entity.Key).EnsureClosed();
}
///
@@ -191,11 +213,11 @@ public static GuidUdi GetUdi(this IContent entity)
///
/// The entity identifier of the entity.
///
- public static GuidUdi GetUdi(this IMember entity)
+ public static GuidUdi GetUdi(this IMediaType entity)
{
ArgumentNullException.ThrowIfNull(entity);
- return new GuidUdi(Constants.UdiEntityType.Member, entity.Key).EnsureClosed();
+ return new GuidUdi(Constants.UdiEntityType.MediaType, entity.Key).EnsureClosed();
}
///
@@ -205,11 +227,11 @@ public static GuidUdi GetUdi(this IMember entity)
///
/// The entity identifier of the entity.
///
- public static StringUdi GetUdi(this Stylesheet entity)
+ public static GuidUdi GetUdi(this IMemberType entity)
{
ArgumentNullException.ThrowIfNull(entity);
- return GetUdiFromPath(Constants.UdiEntityType.Stylesheet, entity.Path);
+ return new GuidUdi(Constants.UdiEntityType.MemberType, entity.Key).EnsureClosed();
}
///
@@ -219,26 +241,25 @@ public static StringUdi GetUdi(this Stylesheet entity)
///
/// The entity identifier of the entity.
///
- public static StringUdi GetUdi(this Script entity)
+ public static GuidUdi GetUdi(this IDataType entity)
{
ArgumentNullException.ThrowIfNull(entity);
- return GetUdiFromPath(Constants.UdiEntityType.Script, entity.Path);
+ return new GuidUdi(Constants.UdiEntityType.DataType, entity.Key).EnsureClosed();
}
///
- /// Gets the UDI from a path.
+ /// Gets the entity identifier of the entity.
///
- /// The type of the entity.
- /// The path.
+ /// The entity.
///
/// The entity identifier of the entity.
///
- private static StringUdi GetUdiFromPath(string entityType, string path)
+ public static GuidUdi GetUdi(this IDictionaryItem entity)
{
- string id = path.TrimStart(Constants.CharArrays.ForwardSlash).Replace("\\", "/");
+ ArgumentNullException.ThrowIfNull(entity);
- return new StringUdi(entityType, id).EnsureClosed();
+ return new GuidUdi(Constants.UdiEntityType.DictionaryItem, entity.Key).EnsureClosed();
}
///
@@ -248,11 +269,11 @@ private static StringUdi GetUdiFromPath(string entityType, string path)
///
/// The entity identifier of the entity.
///
- public static GuidUdi GetUdi(this IDictionaryItem entity)
+ public static StringUdi GetUdi(this ILanguage entity)
{
ArgumentNullException.ThrowIfNull(entity);
- return new GuidUdi(Constants.UdiEntityType.DictionaryItem, entity.Key).EnsureClosed();
+ return new StringUdi(Constants.UdiEntityType.Language, entity.IsoCode).EnsureClosed();
}
///
@@ -262,11 +283,11 @@ public static GuidUdi GetUdi(this IDictionaryItem entity)
///
/// The entity identifier of the entity.
///
- public static StringUdi GetUdi(this IPartialView entity)
+ public static GuidUdi GetUdi(this IMemberGroup entity)
{
ArgumentNullException.ThrowIfNull(entity);
- return GetUdiFromPath(Constants.UdiEntityType.PartialView, entity.Path);
+ return new GuidUdi(Constants.UdiEntityType.MemberGroup, entity.Key).EnsureClosed();
}
///
@@ -276,19 +297,11 @@ public static StringUdi GetUdi(this IPartialView entity)
///
/// The entity identifier of the entity.
///
- public static GuidUdi GetUdi(this IContentBase entity)
+ public static StringUdi GetUdi(this IPartialView entity)
{
ArgumentNullException.ThrowIfNull(entity);
- string type = entity switch
- {
- IContent => Constants.UdiEntityType.Document,
- IMedia => Constants.UdiEntityType.Media,
- IMember => Constants.UdiEntityType.Member,
- _ => throw new NotSupportedException(string.Format("Content base type {0} is not supported.", entity.GetType().FullName)),
- };
-
- return new GuidUdi(type, entity.Key).EnsureClosed();
+ return GetUdiFromPath(Constants.UdiEntityType.PartialView, entity.Path);
}
///
@@ -312,11 +325,11 @@ public static GuidUdi GetUdi(this IRelationType entity)
///
/// The entity identifier of the entity.
///
- public static GuidUdi GetUdi(this IWebhook entity)
+ public static GuidUdi GetUdi(this ITemplate entity)
{
ArgumentNullException.ThrowIfNull(entity);
- return new GuidUdi(Constants.UdiEntityType.Webhook, entity.Key).EnsureClosed();
+ return new GuidUdi(Constants.UdiEntityType.Template, entity.Key).EnsureClosed();
}
///
@@ -326,50 +339,25 @@ public static GuidUdi GetUdi(this IWebhook entity)
///
/// The entity identifier of the entity.
///
- public static StringUdi GetUdi(this ILanguage entity)
+ public static GuidUdi GetUdi(this IWebhook entity)
{
ArgumentNullException.ThrowIfNull(entity);
- return new StringUdi(Constants.UdiEntityType.Language, entity.IsoCode).EnsureClosed();
+ return new GuidUdi(Constants.UdiEntityType.Webhook, entity.Key).EnsureClosed();
}
///
- /// Gets the entity identifier of the entity.
+ /// Gets the UDI from a path.
///
- /// The entity.
+ /// The type of the entity.
+ /// The path.
///
/// The entity identifier of the entity.
///
- public static Udi GetUdi(this IEntity entity)
+ private static StringUdi GetUdiFromPath(string entityType, string path)
{
- ArgumentNullException.ThrowIfNull(entity);
+ string id = path.TrimStart(Constants.CharArrays.ForwardSlash).Replace("\\", "/");
- return entity switch
- {
- // Concrete types
- EntityContainer container => container.GetUdi(),
- Stylesheet stylesheet => stylesheet.GetUdi(),
- Script script => script.GetUdi(),
- // Content types
- IContentType contentType => contentType.GetUdi(),
- IMediaType mediaType => mediaType.GetUdi(),
- IMemberType memberType => memberType.GetUdi(),
- IContentTypeComposition contentTypeComposition => contentTypeComposition.GetUdi(),
- // Content
- IContent content => content.GetUdi(),
- IMedia media => media.GetUdi(),
- IMember member => member.GetUdi(),
- IContentBase contentBase => contentBase.GetUdi(),
- // Other
- IDataType dataTypeComposition => dataTypeComposition.GetUdi(),
- IDictionaryItem dictionaryItem => dictionaryItem.GetUdi(),
- ILanguage language => language.GetUdi(),
- IMemberGroup memberGroup => memberGroup.GetUdi(),
- IPartialView partialView => partialView.GetUdi(),
- IRelationType relationType => relationType.GetUdi(),
- ITemplate template => template.GetUdi(),
- IWebhook webhook => webhook.GetUdi(),
- _ => throw new NotSupportedException(string.Format("Entity type {0} is not supported.", entity.GetType().FullName)),
- };
+ return new StringUdi(entityType, id).EnsureClosed();
}
}
diff --git a/tests/Umbraco.Tests.Common/Builders/ContentBuilder.cs b/tests/Umbraco.Tests.Common/Builders/ContentBuilder.cs
index 05cc4b80ddad..53c2f50f10f9 100644
--- a/tests/Umbraco.Tests.Common/Builders/ContentBuilder.cs
+++ b/tests/Umbraco.Tests.Common/Builders/ContentBuilder.cs
@@ -53,6 +53,7 @@ public class ContentBuilder
private int? _sortOrder;
private bool? _trashed;
private DateTime? _updateDate;
+ private bool? _blueprint;
private int? _versionId;
DateTime? IWithCreateDateBuilder.CreateDate
@@ -145,6 +146,13 @@ string IWithPropertyValues.PropertyValuesSegment
set => _updateDate = value;
}
+ public ContentBuilder WithBlueprint(bool blueprint)
+ {
+ _blueprint = blueprint;
+
+ return this;
+ }
+
public ContentBuilder WithVersionId(int versionId)
{
_versionId = versionId;
@@ -217,6 +225,7 @@ public override Content Build()
{
var id = _id ?? 0;
var versionId = _versionId ?? 0;
+ var blueprint = _blueprint ?? false;
var key = _key ?? Guid.NewGuid();
var parentId = _parentId ?? -1;
var parent = _parent;
@@ -253,6 +262,7 @@ public override Content Build()
content.Id = id;
content.VersionId = versionId;
+ content.Blueprint = blueprint;
content.Key = key;
content.CreateDate = createDate;
content.UpdateDate = updateDate;
diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Extensions/UdiGetterExtensionsTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Extensions/UdiGetterExtensionsTests.cs
index b5da0a4f2fb3..f5a5e79234c4 100644
--- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Extensions/UdiGetterExtensionsTests.cs
+++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Extensions/UdiGetterExtensionsTests.cs
@@ -3,6 +3,7 @@
using NUnit.Framework;
using Umbraco.Cms.Core;
+using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.Entities;
using Umbraco.Cms.Tests.Common.Builders;
using Umbraco.Cms.Tests.Common.Builders.Extensions;
@@ -13,15 +14,22 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Extensions;
[TestFixture]
public class UdiGetterExtensionsTests
{
- [TestCase("style.css", "umb://stylesheet/style.css")]
- [TestCase("editor\\style.css", "umb://stylesheet/editor/style.css")]
- [TestCase("editor/style.css", "umb://stylesheet/editor/style.css")]
- public void GetUdiForStylesheet(string path, string expected)
+ [TestCase(Constants.ObjectTypes.Strings.DataType, "6ad82c70-685c-4e04-9b36-d81bd779d16f", "umb://data-type-container/6ad82c70685c4e049b36d81bd779d16f")]
+ [TestCase(Constants.ObjectTypes.Strings.DocumentType, "6ad82c70-685c-4e04-9b36-d81bd779d16f", "umb://document-type-container/6ad82c70685c4e049b36d81bd779d16f")]
+ [TestCase(Constants.ObjectTypes.Strings.MediaType, "6ad82c70-685c-4e04-9b36-d81bd779d16f", "umb://media-type-container/6ad82c70685c4e049b36d81bd779d16f")]
+ [TestCase(Constants.ObjectTypes.Strings.DocumentBlueprint, "6ad82c70-685c-4e04-9b36-d81bd779d16f", "umb://document-blueprint-container/6ad82c70685c4e049b36d81bd779d16f")]
+ public void GetUdiForEntityContainer(Guid containedObjectType, Guid key, string expected)
{
- var builder = new StylesheetBuilder();
- var stylesheet = builder.WithPath(path).Build();
- var result = stylesheet.GetUdi();
- Assert.AreEqual(expected, result.ToString());
+ EntityContainer entity = new EntityContainer(containedObjectType)
+ {
+ Key = key
+ };
+
+ Udi udi = entity.GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
+
+ udi = ((IEntity)entity).GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
}
[TestCase("script.js", "umb://script/script.js")]
@@ -29,10 +37,195 @@ public void GetUdiForStylesheet(string path, string expected)
[TestCase("editor/script.js", "umb://script/editor/script.js")]
public void GetUdiForScript(string path, string expected)
{
- var builder = new ScriptBuilder();
- var script = builder.WithPath(path).Build();
- var result = script.GetUdi();
- Assert.AreEqual(expected, result.ToString());
+ Script entity = new ScriptBuilder()
+ .WithPath(path)
+ .Build();
+
+ Udi udi = entity.GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
+
+ udi = ((IEntity)entity).GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
+ }
+
+ [TestCase("style.css", "umb://stylesheet/style.css")]
+ [TestCase("editor\\style.css", "umb://stylesheet/editor/style.css")]
+ [TestCase("editor/style.css", "umb://stylesheet/editor/style.css")]
+ public void GetUdiForStylesheet(string path, string expected)
+ {
+ Stylesheet entity = new StylesheetBuilder()
+ .WithPath(path)
+ .Build();
+
+ Udi udi = entity.GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
+
+ udi = ((IEntity)entity).GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
+ }
+
+ [TestCase("6ad82c70-685c-4e04-9b36-d81bd779d16f", false, "umb://document/6ad82c70685c4e049b36d81bd779d16f")]
+ [TestCase("6ad82c70-685c-4e04-9b36-d81bd779d16f", true, "umb://document-blueprint/6ad82c70685c4e049b36d81bd779d16f")]
+ public void GetUdiForContent(Guid key, bool blueprint, string expected)
+ {
+ Content entity = new ContentBuilder()
+ .WithKey(key)
+ .WithBlueprint(blueprint)
+ .WithContentType(ContentTypeBuilder.CreateBasicContentType())
+ .Build();
+
+ Udi udi = entity.GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
+
+ udi = ((IContentBase)entity).GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
+
+ udi = ((IEntity)entity).GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
+ }
+
+ [TestCase("6ad82c70-685c-4e04-9b36-d81bd779d16f", "umb://media/6ad82c70685c4e049b36d81bd779d16f")]
+ public void GetUdiForMedia(Guid key, string expected)
+ {
+ Media entity = new MediaBuilder()
+ .WithKey(key)
+ .WithMediaType(MediaTypeBuilder.CreateImageMediaType())
+ .Build();
+
+ Udi udi = entity.GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
+
+ udi = ((IContentBase)entity).GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
+
+ udi = ((IEntity)entity).GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
+ }
+
+ [TestCase("6ad82c70-685c-4e04-9b36-d81bd779d16f", "umb://member/6ad82c70685c4e049b36d81bd779d16f")]
+ public void GetUdiForMember(Guid key, string expected)
+ {
+ Member entity = new MemberBuilder()
+ .WithKey(key)
+ .WithMemberType(MemberTypeBuilder.CreateSimpleMemberType())
+ .Build();
+
+ Udi udi = entity.GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
+
+ udi = ((IContentBase)entity).GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
+
+ udi = ((IEntity)entity).GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
+ }
+
+ [TestCase("6ad82c70-685c-4e04-9b36-d81bd779d16f", "umb://document-type/6ad82c70685c4e049b36d81bd779d16f")]
+ public void GetUdiForContentType(Guid key, string expected)
+ {
+ IContentType entity = new ContentTypeBuilder()
+ .WithKey(key)
+ .Build();
+
+ Udi udi = entity.GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
+
+ udi = ((IContentTypeComposition)entity).GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
+
+ udi = ((IEntity)entity).GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
+ }
+
+ [TestCase("6ad82c70-685c-4e04-9b36-d81bd779d16f", "umb://media-type/6ad82c70685c4e049b36d81bd779d16f")]
+ public void GetUdiForMediaType(Guid key, string expected)
+ {
+ IMediaType entity = new MediaTypeBuilder()
+ .WithKey(key)
+ .Build();
+
+ Udi udi = entity.GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
+
+ udi = ((IContentTypeComposition)entity).GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
+
+ udi = ((IEntity)entity).GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
+ }
+
+ [TestCase("6ad82c70-685c-4e04-9b36-d81bd779d16f", "umb://member-type/6ad82c70685c4e049b36d81bd779d16f")]
+ public void GetUdiForMemberType(Guid key, string expected)
+ {
+ IMemberType entity = new MemberTypeBuilder()
+ .WithKey(key)
+ .Build();
+
+ Udi udi = entity.GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
+
+ udi = ((IContentTypeComposition)entity).GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
+
+ udi = ((IEntity)entity).GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
+ }
+
+ [TestCase("6ad82c70-685c-4e04-9b36-d81bd779d16f", "umb://data-type/6ad82c70685c4e049b36d81bd779d16f")]
+ public void GetUdiForDataType(Guid key, string expected)
+ {
+ DataType entity = new DataTypeBuilder()
+ .WithKey(key)
+ .Build();
+
+ Udi udi = entity.GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
+
+ udi = ((IEntity)entity).GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
+ }
+
+ [TestCase("6ad82c70-685c-4e04-9b36-d81bd779d16f", "umb://dictionary-item/6ad82c70685c4e049b36d81bd779d16f")]
+ public void GetUdiForDictionaryItem(Guid key, string expected)
+ {
+ DictionaryItem entity = new DictionaryItemBuilder()
+ .WithKey(key)
+ .Build();
+
+ Udi udi = entity.GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
+
+ udi = ((IEntity)entity).GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
+ }
+
+ [TestCase("en-US", "umb://language/en-US")]
+ [TestCase("en", "umb://language/en")]
+ public void GetUdiForLanguage(string isoCode, string expected)
+ {
+ ILanguage entity = new LanguageBuilder()
+ .WithCultureInfo(isoCode)
+ .Build();
+
+ Udi udi = entity.GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
+
+ udi = ((IEntity)entity).GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
+ }
+
+ [TestCase("6ad82c70-685c-4e04-9b36-d81bd779d16f", "umb://member-group/6ad82c70685c4e049b36d81bd779d16f")]
+ public void GetUdiForMemberGroup(Guid key, string expected)
+ {
+ MemberGroup entity = new MemberGroupBuilder()
+ .WithKey(key)
+ .Build();
+
+ Udi udi = entity.GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
+
+ udi = ((IEntity)entity).GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
}
[TestCase("test.cshtml", "umb://partial-view/test.cshtml")]
@@ -40,26 +233,53 @@ public void GetUdiForScript(string path, string expected)
[TestCase("editor/test.cshtml", "umb://partial-view/editor/test.cshtml")]
public void GetUdiForPartialView(string path, string expected)
{
- var builder = new PartialViewBuilder();
- var partialView = builder
+ IPartialView entity = new PartialViewBuilder()
.WithPath(path)
.Build();
- var result = partialView.GetUdi();
- Assert.AreEqual(expected, result.ToString());
+
+ Udi udi = entity.GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
+ }
+
+ [TestCase("6ad82c70-685c-4e04-9b36-d81bd779d16f", "umb://relation-type/6ad82c70685c4e049b36d81bd779d16f")]
+ public void GetUdiForRelationType(Guid key, string expected)
+ {
+ IRelationTypeWithIsDependency entity = new RelationTypeBuilder()
+ .WithKey(key)
+ .Build();
+
+ Udi udi = entity.GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
+
+ udi = ((IEntity)entity).GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
+ }
+
+ [TestCase("6ad82c70-685c-4e04-9b36-d81bd779d16f", "umb://template/6ad82c70685c4e049b36d81bd779d16f")]
+ public void GetUdiForTemplate(Guid key, string expected)
+ {
+ ITemplate entity = new TemplateBuilder()
+ .WithKey(key)
+ .Build();
+
+ Udi udi = entity.GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
+
+ udi = ((IEntity)entity).GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
}
[TestCase("6ad82c70-685c-4e04-9b36-d81bd779d16f", "umb://webhook/6ad82c70685c4e049b36d81bd779d16f")]
- public void GetUdiForWebhook(string key, string expected)
+ public void GetUdiForWebhook(Guid key, string expected)
{
- var builder = new WebhookBuilder();
- var webhook = builder
- .WithKey(Guid.Parse(key))
+ Webhook entity = new WebhookBuilder()
+ .WithKey(key)
.Build();
- Udi result = webhook.GetUdi();
- Assert.AreEqual(expected, result.ToString());
+ Udi udi = entity.GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
- result = ((IEntity)webhook).GetUdi();
- Assert.AreEqual(expected, result.ToString());
+ udi = ((IEntity)entity).GetUdi();
+ Assert.AreEqual(expected, udi.ToString());
}
}