From 038b155aeabb28896f61467eb190eca49a9f3c1d Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 17 Jan 2017 14:42:30 +1100 Subject: [PATCH] Fixes constants and internalsvisibleto --- src/Umbraco.Core/Constants-Conventions.cs | 118 +----------------- .../Constants-DeployEntityType.cs | 2 +- src/Umbraco.Core/Constants-DeploySelector.cs | 2 +- src/Umbraco.Core/Properties/AssemblyInfo.cs | 7 +- src/Umbraco.Core/Udi.cs | 8 +- src/Umbraco.Core/UdiGetterExtensions.cs | 50 ++++---- src/Umbraco.Tests/UdiTests.cs | 40 +++--- src/Umbraco.Web/Properties/AssemblyInfo.cs | 3 + 8 files changed, 60 insertions(+), 170 deletions(-) diff --git a/src/Umbraco.Core/Constants-Conventions.cs b/src/Umbraco.Core/Constants-Conventions.cs index d6c4003fcf..2e3d652d7e 100644 --- a/src/Umbraco.Core/Constants-Conventions.cs +++ b/src/Umbraco.Core/Constants-Conventions.cs @@ -4,123 +4,7 @@ using Umbraco.Core.Models; namespace Umbraco.Core { - /// - /// Defines well-known entity types. - /// - /// Well-known entity types are those that Deploy already knows about, - /// but entity types are strings and so can be extended beyond what is defined here. - internal static class DeployEntityType - { - // guid entity types - - public const string AnyGuid = "any-guid"; // that one is for tests - - public const string Document = "document"; - public const string Media = "media"; - public const string Member = "member"; - - public const string DictionaryItem = "dictionary-item"; - public const string Macro = "macro"; - public const string Template = "template"; - - public const string DocumentType = "document-type"; - public const string DocumentTypeContainer = "document-type-container"; - public const string MediaType = "media-type"; - public const string MediaTypeContainer = "media-type-container"; - public const string DataType = "data-type"; - public const string DataTypeContainer = "data-type-container"; - public const string MemberType = "member-type"; - public const string MemberGroup = "member-group"; - - public const string RelationType = "relation-type"; - - // string entity types - - public const string AnyString = "any-string"; // that one is for tests - - public const string MediaFile = "media-file"; - public const string TemplateFile = "template-file"; - public const string Script = "script"; - public const string Stylesheet = "stylesheet"; - public const string PartialView = "partial-view"; - public const string PartialViewMacro = "partial-view-macro"; - public const string Xslt = "xslt"; - - public static string FromUmbracoObjectType(UmbracoObjectTypes umbracoObjectType) - { - switch (umbracoObjectType) - { - case UmbracoObjectTypes.Document: - return Document; - case UmbracoObjectTypes.Media: - return Media; - case UmbracoObjectTypes.Member: - return Member; - case UmbracoObjectTypes.Template: - return Template; - case UmbracoObjectTypes.DocumentType: - return DocumentType; - case UmbracoObjectTypes.DocumentTypeContainer: - return DocumentTypeContainer; - case UmbracoObjectTypes.MediaType: - return MediaType; - case UmbracoObjectTypes.MediaTypeContainer: - return MediaTypeContainer; - case UmbracoObjectTypes.DataType: - return DataType; - case UmbracoObjectTypes.DataTypeContainer: - return DataTypeContainer; - case UmbracoObjectTypes.MemberType: - return MemberType; - case UmbracoObjectTypes.MemberGroup: - return MemberGroup; - case UmbracoObjectTypes.Stylesheet: - return Stylesheet; - case UmbracoObjectTypes.RelationType: - return RelationType; - } - throw new NotSupportedException(string.Format("UmbracoObjectType \"{0}\" does not have a matching EntityType.", umbracoObjectType)); - } - - public static UmbracoObjectTypes ToUmbracoObjectType(string entityType) - { - switch (entityType) - { - case Document: - return UmbracoObjectTypes.Document; - case Media: - return UmbracoObjectTypes.Media; - case Member: - return UmbracoObjectTypes.Member; - case Template: - return UmbracoObjectTypes.Template; - case DocumentType: - return UmbracoObjectTypes.DocumentType; - case DocumentTypeContainer: - return UmbracoObjectTypes.DocumentTypeContainer; - case MediaType: - return UmbracoObjectTypes.MediaType; - case MediaTypeContainer: - return UmbracoObjectTypes.MediaTypeContainer; - case DataType: - return UmbracoObjectTypes.DataType; - case DataTypeContainer: - return UmbracoObjectTypes.DataTypeContainer; - case MemberType: - return UmbracoObjectTypes.MemberType; - case MemberGroup: - return UmbracoObjectTypes.MemberGroup; - case Stylesheet: - return UmbracoObjectTypes.Stylesheet; - case RelationType: - return UmbracoObjectTypes.RelationType; - } - throw new NotSupportedException( - string.Format("EntityType \"{0}\" does not have a matching UmbracoObjectType.", entityType)); - } - } - - + public static partial class Constants { /// diff --git a/src/Umbraco.Core/Constants-DeployEntityType.cs b/src/Umbraco.Core/Constants-DeployEntityType.cs index 2c0ea81be3..f622661dff 100644 --- a/src/Umbraco.Core/Constants-DeployEntityType.cs +++ b/src/Umbraco.Core/Constants-DeployEntityType.cs @@ -13,7 +13,7 @@ namespace Umbraco.Core /// /// Well-known entity types are those that Deploy already knows about, /// but entity types are strings and so can be extended beyond what is defined here. - internal static class DeployEntityType + public static class DeployEntityType { // guid entity types diff --git a/src/Umbraco.Core/Constants-DeploySelector.cs b/src/Umbraco.Core/Constants-DeploySelector.cs index b2415fb37f..b7b45fd666 100644 --- a/src/Umbraco.Core/Constants-DeploySelector.cs +++ b/src/Umbraco.Core/Constants-DeploySelector.cs @@ -9,7 +9,7 @@ namespace Umbraco.Core /// /// Contains the valid selector values. /// - internal static class DeploySelector + public static class DeploySelector { public const string This = "this"; public const string ThisAndChildren = "this-and-children"; diff --git a/src/Umbraco.Core/Properties/AssemblyInfo.cs b/src/Umbraco.Core/Properties/AssemblyInfo.cs index dbc1ab6c93..a74ebb8fec 100644 --- a/src/Umbraco.Core/Properties/AssemblyInfo.cs +++ b/src/Umbraco.Core/Properties/AssemblyInfo.cs @@ -29,7 +29,7 @@ using System.Security.Permissions; [assembly: InternalsVisibleTo("umbraco.webservices")] [assembly: InternalsVisibleTo("umbraco.datalayer")] [assembly: InternalsVisibleTo("umbraco.MacroEngines")] - +[assembly: InternalsVisibleTo("umbraco.providers")] [assembly: InternalsVisibleTo("umbraco.editorControls")] [assembly: InternalsVisibleTo("Umbraco.Tests")] [assembly: InternalsVisibleTo("Umbraco.Tests.Benchmarks")] @@ -42,7 +42,10 @@ using System.Security.Permissions; [assembly: InternalsVisibleTo("Umbraco.VisualStudio")] [assembly: InternalsVisibleTo("Umbraco.Courier.Core")] [assembly: InternalsVisibleTo("Umbraco.Courier.Persistence")] -[assembly: InternalsVisibleTo("umbraco.providers")] + +[assembly: InternalsVisibleTo("Umbraco.Deploy")] +[assembly: InternalsVisibleTo("Umbraco.Deploy.UI")] +[assembly: InternalsVisibleTo("Umbraco.Deploy.Cloud")] //allow this to be mocked in our unit tests [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] \ No newline at end of file diff --git a/src/Umbraco.Core/Udi.cs b/src/Umbraco.Core/Udi.cs index aef0fc9274..95bd9f90b1 100644 --- a/src/Umbraco.Core/Udi.cs +++ b/src/Umbraco.Core/Udi.cs @@ -44,12 +44,12 @@ namespace Umbraco.Core static Udi() { // for tests etc. - UdiTypes[DeployEntityType.AnyGuid] = UdiType.GuidUdi; - UdiTypes[DeployEntityType.AnyString] = UdiType.StringUdi; + UdiTypes[Constants.DeployEntityType.AnyGuid] = UdiType.GuidUdi; + UdiTypes[Constants.DeployEntityType.AnyString] = UdiType.StringUdi; // we don't have connectors for these... - UdiTypes[DeployEntityType.Member] = UdiType.GuidUdi; - UdiTypes[DeployEntityType.MemberGroup] = UdiType.GuidUdi; + UdiTypes[Constants.DeployEntityType.Member] = UdiType.GuidUdi; + UdiTypes[Constants.DeployEntityType.MemberGroup] = UdiType.GuidUdi; // fixme - or inject from...? // there is no way we can get the "registered" service connectors, as registration diff --git a/src/Umbraco.Core/UdiGetterExtensions.cs b/src/Umbraco.Core/UdiGetterExtensions.cs index aebb8873a6..d10f730aef 100644 --- a/src/Umbraco.Core/UdiGetterExtensions.cs +++ b/src/Umbraco.Core/UdiGetterExtensions.cs @@ -17,7 +17,7 @@ namespace Umbraco.Core public static GuidUdi GetUdi(this ITemplate entity) { if (entity == null) throw new ArgumentNullException("entity"); - return new GuidUdi(DeployEntityType.Template, entity.Key).EnsureClosed(); + return new GuidUdi(Constants.DeployEntityType.Template, entity.Key).EnsureClosed(); } /// @@ -28,7 +28,7 @@ namespace Umbraco.Core public static GuidUdi GetUdi(this IContentType entity) { if (entity == null) throw new ArgumentNullException("entity"); - return new GuidUdi(DeployEntityType.DocumentType, entity.Key).EnsureClosed(); + return new GuidUdi(Constants.DeployEntityType.DocumentType, entity.Key).EnsureClosed(); } /// @@ -39,7 +39,7 @@ namespace Umbraco.Core public static GuidUdi GetUdi(this IMediaType entity) { if (entity == null) throw new ArgumentNullException("entity"); - return new GuidUdi(DeployEntityType.MediaType, entity.Key).EnsureClosed(); + return new GuidUdi(Constants.DeployEntityType.MediaType, entity.Key).EnsureClosed(); } /// @@ -50,7 +50,7 @@ namespace Umbraco.Core public static GuidUdi GetUdi(this IMemberType entity) { if (entity == null) throw new ArgumentNullException("entity"); - return new GuidUdi(DeployEntityType.MemberType, entity.Key).EnsureClosed(); + return new GuidUdi(Constants.DeployEntityType.MemberType, entity.Key).EnsureClosed(); } /// @@ -61,7 +61,7 @@ namespace Umbraco.Core public static GuidUdi GetUdi(this IMemberGroup entity) { if (entity == null) throw new ArgumentNullException("entity"); - return new GuidUdi(DeployEntityType.MemberGroup, entity.Key).EnsureClosed(); + return new GuidUdi(Constants.DeployEntityType.MemberGroup, entity.Key).EnsureClosed(); } /// @@ -74,9 +74,9 @@ namespace Umbraco.Core if (entity == null) throw new ArgumentNullException("entity"); string type; - if (entity is IContentType) type = DeployEntityType.DocumentType; - else if (entity is IMediaType) type = DeployEntityType.MediaType; - else if (entity is IMemberType) type = DeployEntityType.MemberType; + if (entity is IContentType) type = Constants.DeployEntityType.DocumentType; + else if (entity is IMediaType) type = Constants.DeployEntityType.MediaType; + else if (entity is IMemberType) type = Constants.DeployEntityType.MemberType; else throw new NotSupportedException(string.Format("Composition type {0} is not supported.", entity.GetType().FullName)); return new GuidUdi(type, entity.Key).EnsureClosed(); } @@ -89,7 +89,7 @@ namespace Umbraco.Core public static GuidUdi GetUdi(this IDataTypeDefinition entity) { if (entity == null) throw new ArgumentNullException("entity"); - return new GuidUdi(DeployEntityType.DataType, entity.Key).EnsureClosed(); + return new GuidUdi(Constants.DeployEntityType.DataType, entity.Key).EnsureClosed(); } /// @@ -103,11 +103,11 @@ namespace Umbraco.Core string entityType; if (entity.ContainedObjectType == Constants.ObjectTypes.DataTypeGuid) - entityType = DeployEntityType.DataTypeContainer; + entityType = Constants.DeployEntityType.DataTypeContainer; else if (entity.ContainedObjectType == Constants.ObjectTypes.DocumentTypeGuid) - entityType = DeployEntityType.DocumentTypeContainer; + entityType = Constants.DeployEntityType.DocumentTypeContainer; else if (entity.ContainedObjectType == Constants.ObjectTypes.MediaTypeGuid) - entityType = DeployEntityType.MediaTypeContainer; + entityType = Constants.DeployEntityType.MediaTypeContainer; else throw new NotSupportedException(string.Format("Contained object type {0} is not supported.", entity.ContainedObjectType)); return new GuidUdi(entityType, entity.Key).EnsureClosed(); @@ -121,7 +121,7 @@ namespace Umbraco.Core public static GuidUdi GetUdi(this IMedia entity) { if (entity == null) throw new ArgumentNullException("entity"); - return new GuidUdi(DeployEntityType.Media, entity.Key).EnsureClosed(); + return new GuidUdi(Constants.DeployEntityType.Media, entity.Key).EnsureClosed(); } /// @@ -132,7 +132,7 @@ namespace Umbraco.Core public static GuidUdi GetUdi(this IContent entity) { if (entity == null) throw new ArgumentNullException("entity"); - return new GuidUdi(DeployEntityType.Document, entity.Key).EnsureClosed(); + return new GuidUdi(Constants.DeployEntityType.Document, entity.Key).EnsureClosed(); } /// @@ -143,7 +143,7 @@ namespace Umbraco.Core public static GuidUdi GetUdi(this IMember entity) { if (entity == null) throw new ArgumentNullException("entity"); - return new GuidUdi(DeployEntityType.Member, entity.Key).EnsureClosed(); + return new GuidUdi(Constants.DeployEntityType.Member, entity.Key).EnsureClosed(); } /// @@ -154,7 +154,7 @@ namespace Umbraco.Core public static StringUdi GetUdi(this Stylesheet entity) { if (entity == null) throw new ArgumentNullException("entity"); - return new StringUdi(DeployEntityType.Stylesheet, entity.Path.TrimStart('/')).EnsureClosed(); + return new StringUdi(Constants.DeployEntityType.Stylesheet, entity.Path.TrimStart('/')).EnsureClosed(); } /// @@ -165,7 +165,7 @@ namespace Umbraco.Core public static StringUdi GetUdi(this Script entity) { if (entity == null) throw new ArgumentNullException("entity"); - return new StringUdi(DeployEntityType.Script, entity.Path.TrimStart('/')).EnsureClosed(); + return new StringUdi(Constants.DeployEntityType.Script, entity.Path.TrimStart('/')).EnsureClosed(); } /// @@ -176,7 +176,7 @@ namespace Umbraco.Core public static GuidUdi GetUdi(this IDictionaryItem entity) { if (entity == null) throw new ArgumentNullException("entity"); - return new GuidUdi(DeployEntityType.DictionaryItem, entity.Key).EnsureClosed(); + return new GuidUdi(Constants.DeployEntityType.DictionaryItem, entity.Key).EnsureClosed(); } /// @@ -187,7 +187,7 @@ namespace Umbraco.Core public static GuidUdi GetUdi(this IMacro entity) { if (entity == null) throw new ArgumentNullException("entity"); - return new GuidUdi(DeployEntityType.Macro, entity.Key).EnsureClosed(); + return new GuidUdi(Constants.DeployEntityType.Macro, entity.Key).EnsureClosed(); } /// @@ -198,7 +198,7 @@ namespace Umbraco.Core public static StringUdi GetUdi(this IPartialView entity) { if (entity == null) throw new ArgumentNullException("entity"); - return new StringUdi(DeployEntityType.PartialView, entity.Path.TrimStart('/')).EnsureClosed(); + return new StringUdi(Constants.DeployEntityType.PartialView, entity.Path.TrimStart('/')).EnsureClosed(); } /// @@ -209,7 +209,7 @@ namespace Umbraco.Core public static StringUdi GetUdi(this IXsltFile entity) { if (entity == null) throw new ArgumentNullException("entity"); - return new StringUdi(DeployEntityType.Xslt, entity.Path.TrimStart('/')).EnsureClosed(); + return new StringUdi(Constants.DeployEntityType.Xslt, entity.Path.TrimStart('/')).EnsureClosed(); } /// @@ -222,9 +222,9 @@ namespace Umbraco.Core if (entity == null) throw new ArgumentNullException("entity"); string type; - if (entity is IContent) type = DeployEntityType.Document; - else if (entity is IMedia) type = DeployEntityType.Media; - else if (entity is IMember) type = DeployEntityType.Member; + if (entity is IContent) type = Constants.DeployEntityType.Document; + else if (entity is IMedia) type = Constants.DeployEntityType.Media; + else if (entity is IMember) type = Constants.DeployEntityType.Member; else throw new NotSupportedException(string.Format("ContentBase type {0} is not supported.", entity.GetType().FullName)); return new GuidUdi(type, entity.Key).EnsureClosed(); } @@ -237,7 +237,7 @@ namespace Umbraco.Core public static GuidUdi GetUdi(this IRelationType entity) { if (entity == null) throw new ArgumentNullException("entity"); - return new GuidUdi(DeployEntityType.RelationType, entity.Key).EnsureClosed(); + return new GuidUdi(Constants.DeployEntityType.RelationType, entity.Key).EnsureClosed(); } /// diff --git a/src/Umbraco.Tests/UdiTests.cs b/src/Umbraco.Tests/UdiTests.cs index 2587e245aa..1a7b30a770 100644 --- a/src/Umbraco.Tests/UdiTests.cs +++ b/src/Umbraco.Tests/UdiTests.cs @@ -13,41 +13,41 @@ namespace Umbraco.Tests [Test] public void StringEntityCtorTest() { - var udi = new StringUdi(DeployEntityType.AnyString, "test-id"); - Assert.AreEqual(DeployEntityType.AnyString, udi.EntityType); + var udi = new StringUdi(Constants.DeployEntityType.AnyString, "test-id"); + Assert.AreEqual(Constants.DeployEntityType.AnyString, udi.EntityType); Assert.AreEqual("test-id", udi.Id); - Assert.AreEqual("umb://" + DeployEntityType.AnyString + "/test-id", udi.ToString()); + Assert.AreEqual("umb://" + Constants.DeployEntityType.AnyString + "/test-id", udi.ToString()); } [Test] public void StringEntityParseTest() { - var udi = Udi.Parse("umb://" + DeployEntityType.AnyString + "/test-id"); - Assert.AreEqual(DeployEntityType.AnyString, udi.EntityType); + var udi = Udi.Parse("umb://" + Constants.DeployEntityType.AnyString + "/test-id"); + Assert.AreEqual(Constants.DeployEntityType.AnyString, udi.EntityType); Assert.IsInstanceOf(udi); var stringEntityId = udi as StringUdi; Assert.IsNotNull(stringEntityId); Assert.AreEqual("test-id", stringEntityId.Id); - Assert.AreEqual("umb://" + DeployEntityType.AnyString + "/test-id", udi.ToString()); + Assert.AreEqual("umb://" + Constants.DeployEntityType.AnyString + "/test-id", udi.ToString()); } [Test] public void GuidEntityCtorTest() { var guid = Guid.NewGuid(); - var udi = new GuidUdi(DeployEntityType.AnyGuid, guid); - Assert.AreEqual(DeployEntityType.AnyGuid, udi.EntityType); + var udi = new GuidUdi(Constants.DeployEntityType.AnyGuid, guid); + Assert.AreEqual(Constants.DeployEntityType.AnyGuid, udi.EntityType); Assert.AreEqual(guid, udi.Guid); - Assert.AreEqual("umb://" + DeployEntityType.AnyGuid + "/" + guid.ToString("N"), udi.ToString()); + Assert.AreEqual("umb://" + Constants.DeployEntityType.AnyGuid + "/" + guid.ToString("N"), udi.ToString()); } [Test] public void GuidEntityParseTest() { var guid = Guid.NewGuid(); - var s = "umb://" + DeployEntityType.AnyGuid + "/" + guid.ToString("N"); + var s = "umb://" + Constants.DeployEntityType.AnyGuid + "/" + guid.ToString("N"); var udi = Udi.Parse(s); - Assert.AreEqual(DeployEntityType.AnyGuid, udi.EntityType); + Assert.AreEqual(Constants.DeployEntityType.AnyGuid, udi.EntityType); Assert.IsInstanceOf(udi); var gudi = udi as GuidUdi; Assert.IsNotNull(gudi); @@ -82,9 +82,9 @@ namespace Umbraco.Tests var guid1 = Guid.NewGuid(); var entities = new[] { - new GuidUdi(DeployEntityType.AnyGuid, guid1), - new GuidUdi(DeployEntityType.AnyGuid, guid1), - new GuidUdi(DeployEntityType.AnyGuid, guid1), + new GuidUdi(Constants.DeployEntityType.AnyGuid, guid1), + new GuidUdi(Constants.DeployEntityType.AnyGuid, guid1), + new GuidUdi(Constants.DeployEntityType.AnyGuid, guid1), }; Assert.AreEqual(1, entities.Distinct().Count()); } @@ -93,12 +93,12 @@ namespace Umbraco.Tests public void CreateTest() { var guid = Guid.NewGuid(); - var udi = Udi.Create(DeployEntityType.AnyGuid, guid); - Assert.AreEqual(DeployEntityType.AnyGuid, udi.EntityType); + var udi = Udi.Create(Constants.DeployEntityType.AnyGuid, guid); + Assert.AreEqual(Constants.DeployEntityType.AnyGuid, udi.EntityType); Assert.AreEqual(guid, ((GuidUdi)udi).Guid); - Assert.Throws(() => Udi.Create(DeployEntityType.AnyString, guid)); - Assert.Throws(() => Udi.Create(DeployEntityType.AnyGuid, "foo")); + Assert.Throws(() => Udi.Create(Constants.DeployEntityType.AnyString, guid)); + Assert.Throws(() => Udi.Create(Constants.DeployEntityType.AnyGuid, "foo")); Assert.Throws(() => Udi.Create("barf", "foo")); } @@ -134,12 +134,12 @@ namespace Umbraco.Tests var guid = Guid.NewGuid(); - var udi = new GuidUdi(DeployEntityType.AnyGuid, guid); + var udi = new GuidUdi(Constants.DeployEntityType.AnyGuid, guid); var json = JsonConvert.SerializeObject(udi, settings); Assert.AreEqual(string.Format("\"umb://any-guid/{0:N}\"", guid), json); var dudi = JsonConvert.DeserializeObject(json, settings); - Assert.AreEqual(DeployEntityType.AnyGuid, dudi.EntityType); + Assert.AreEqual(Constants.DeployEntityType.AnyGuid, dudi.EntityType); Assert.AreEqual(guid, ((GuidUdi)dudi).Guid); var range = new UdiRange(udi, Constants.DeploySelector.ChildrenOfThis); diff --git a/src/Umbraco.Web/Properties/AssemblyInfo.cs b/src/Umbraco.Web/Properties/AssemblyInfo.cs index 89499b833e..7b30b1f4b3 100644 --- a/src/Umbraco.Web/Properties/AssemblyInfo.cs +++ b/src/Umbraco.Web/Properties/AssemblyInfo.cs @@ -34,6 +34,9 @@ using System.Security; [assembly: InternalsVisibleTo("Concorde.Sync")] [assembly: InternalsVisibleTo("Umbraco.Courier.Core")] [assembly: InternalsVisibleTo("Umbraco.Courier.Persistence")] +[assembly: InternalsVisibleTo("Umbraco.Deploy")] +[assembly: InternalsVisibleTo("Umbraco.Deploy.UI")] +[assembly: InternalsVisibleTo("Umbraco.Deploy.Cloud")] [assembly: InternalsVisibleTo("Umbraco.VisualStudio")] [assembly: InternalsVisibleTo("Umbraco.ModelsBuilder")] [assembly: InternalsVisibleTo("Umbraco.ModelsBuilder.AspNet")]