Add UDI support for relation, user and user-group entity types (#17490)
* Add GetUdi() extension methods for IUser and IUserGroup * Add GetUdi() extension methods for IRelation * Move GetUdi() extension methods for Script and Stylesheet to interface types * Register relation, user and user-group as known UDI types * Obsolete UdiParserServiceConnectors * Use IScript and IStylesheet types in tests * Fix UdiTests after obsoleting UdiParserServiceConnectors
This commit is contained in:
@@ -293,42 +293,5 @@ public class UdiTests
|
||||
Assert.IsFalse(UdiParser.TryParse("umb://foo/A87F65C8D6B94E868F6949BA92C93045", true, out udi));
|
||||
Assert.AreEqual(Constants.UdiEntityType.Unknown, udi.EntityType);
|
||||
Assert.AreEqual("Umbraco.Cms.Core.UnknownTypeUdi", udi.GetType().FullName);
|
||||
|
||||
// scanned
|
||||
UdiParserServiceConnectors
|
||||
.RegisterServiceConnector<
|
||||
FooConnector>(); // this is the equivalent of scanning but we'll just manually register this one
|
||||
Assert.IsTrue(UdiParser.TryParse("umb://foo/A87F65C8D6B94E868F6949BA92C93045", out udi));
|
||||
Assert.IsInstanceOf<GuidUdi>(udi);
|
||||
|
||||
// known
|
||||
Assert.IsTrue(UdiParser.TryParse("umb://foo/A87F65C8D6B94E868F6949BA92C93045", true, out udi));
|
||||
Assert.IsInstanceOf<GuidUdi>(udi);
|
||||
|
||||
// can get method for Deploy compatibility
|
||||
var method = typeof(UdiParser).GetMethod("Parse", BindingFlags.Static | BindingFlags.Public, null, new[] { typeof(string), typeof(bool) }, null);
|
||||
Assert.IsNotNull(method);
|
||||
}
|
||||
|
||||
[UdiDefinition("foo", UdiType.GuidUdi)]
|
||||
public class FooConnector : IServiceConnector
|
||||
{
|
||||
public Task<IArtifact?> GetArtifactAsync(Udi udi, IContextCache contextCache, CancellationToken cancellationToken = default) => throw new NotImplementedException();
|
||||
|
||||
public Task<IArtifact> GetArtifactAsync(object entity, IContextCache contextCache, CancellationToken cancellationToken = default) => throw new NotImplementedException();
|
||||
|
||||
public Task<ArtifactDeployState> ProcessInitAsync(IArtifact artifact, IDeployContext context, CancellationToken cancellationToken = default) => throw new NotImplementedException();
|
||||
|
||||
public Task ProcessAsync(ArtifactDeployState state, IDeployContext context, int pass,
|
||||
CancellationToken cancellationToken = default) =>
|
||||
throw new NotImplementedException();
|
||||
|
||||
public IAsyncEnumerable<Udi> ExpandRangeAsync(UdiRange range, CancellationToken cancellationToken = default) => throw new NotImplementedException();
|
||||
|
||||
public Task<NamedUdiRange> GetRangeAsync(Udi udi, string selector, CancellationToken cancellationToken = default) => throw new NotImplementedException();
|
||||
|
||||
public Task<NamedUdiRange> GetRangeAsync(string entityType, string sid, string selector, CancellationToken cancellationToken = default) => throw new NotImplementedException();
|
||||
|
||||
public bool Compare(IArtifact? art1, IArtifact? art2, ICollection<Difference>? differences = null) => throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using NUnit.Framework;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Models.Entities;
|
||||
using Umbraco.Cms.Core.Models.Membership;
|
||||
using Umbraco.Cms.Tests.Common.Builders;
|
||||
using Umbraco.Cms.Tests.Common.Builders.Extensions;
|
||||
using Umbraco.Extensions;
|
||||
@@ -32,38 +33,6 @@ public class UdiGetterExtensionsTests
|
||||
Assert.AreEqual(expected, udi.ToString());
|
||||
}
|
||||
|
||||
[TestCase("script.js", "umb://script/script.js")]
|
||||
[TestCase("editor\\script.js", "umb://script/editor/script.js")]
|
||||
[TestCase("editor/script.js", "umb://script/editor/script.js")]
|
||||
public void GetUdiForScript(string path, string expected)
|
||||
{
|
||||
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)
|
||||
@@ -241,6 +210,21 @@ public class UdiGetterExtensionsTests
|
||||
Assert.AreEqual(expected, udi.ToString());
|
||||
}
|
||||
|
||||
[TestCase("6ad82c70-685c-4e04-9b36-d81bd779d16f", "umb://relation/6ad82c70685c4e049b36d81bd779d16f")]
|
||||
public void GetUdiForRelation(Guid key, string expected)
|
||||
{
|
||||
IRelation entity = new RelationBuilder()
|
||||
.WithKey(key)
|
||||
.AddRelationType().Done()
|
||||
.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://relation-type/6ad82c70685c4e049b36d81bd779d16f")]
|
||||
public void GetUdiForRelationType(Guid key, string expected)
|
||||
{
|
||||
@@ -255,6 +239,38 @@ public class UdiGetterExtensionsTests
|
||||
Assert.AreEqual(expected, udi.ToString());
|
||||
}
|
||||
|
||||
[TestCase("script.js", "umb://script/script.js")]
|
||||
[TestCase("editor\\script.js", "umb://script/editor/script.js")]
|
||||
[TestCase("editor/script.js", "umb://script/editor/script.js")]
|
||||
public void GetUdiForScript(string path, string expected)
|
||||
{
|
||||
IScript 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)
|
||||
{
|
||||
IStylesheet 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", "umb://template/6ad82c70685c4e049b36d81bd779d16f")]
|
||||
public void GetUdiForTemplate(Guid key, string expected)
|
||||
{
|
||||
@@ -269,6 +285,34 @@ public class UdiGetterExtensionsTests
|
||||
Assert.AreEqual(expected, udi.ToString());
|
||||
}
|
||||
|
||||
[TestCase("6ad82c70-685c-4e04-9b36-d81bd779d16f", "umb://user/6ad82c70685c4e049b36d81bd779d16f")]
|
||||
public void GetUdiForUser(Guid key, string expected)
|
||||
{
|
||||
IUser entity = new UserBuilder()
|
||||
.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://user-group/6ad82c70685c4e049b36d81bd779d16f")]
|
||||
public void GetUdiForUserGroup(Guid key, string expected)
|
||||
{
|
||||
IUserGroup entity = new UserGroupBuilder()
|
||||
.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(Guid key, string expected)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user