Version -alpha.30 with ModelsBuilder -alpha.13

This commit is contained in:
Stephan
2017-10-26 11:25:01 +02:00
parent edc5b398bd
commit 2305426dda
13 changed files with 91 additions and 30 deletions

View File

@@ -175,7 +175,7 @@
/p:WebProjectOutputDir="$($this.BuildTemp)\WebApp\\" `
/p:Verbosity=minimal `
/t:Clean`;Rebuild `
/tv:"$($ubuild.BuildEnv.VisualStudio.ToolsVersion)" `
/tv:"$($this.BuildEnv.VisualStudio.ToolsVersion)" `
/p:UmbracoBuild=True `
> $log
@@ -193,7 +193,7 @@
/p:WebProjectOutputDir="$($this.BuildTemp)\WebApp\\" `
/p:Verbosity=minimal `
/t:Rebuild `
/tv:"$($ubuild.BuildEnv.VisualStudio.ToolsVersion)" `
/tv:"$($this.BuildEnv.VisualStudio.ToolsVersion)" `
/p:UmbracoBuild=True `
> $log7
@@ -252,7 +252,7 @@
/p:OutDir="$($this.BuildTemp)\tests\\" `
/p:Verbosity=minimal `
/t:Build `
/tv:"$($ubuild.BuildEnv.VisualStudio.ToolsVersion)" `
/tv:"$($this.BuildEnv.VisualStudio.ToolsVersion)" `
/p:UmbracoBuild=True `
/p:NugetPackages="$($this.SolutionRoot)\src\packages" `
> $log

View File

@@ -17,4 +17,4 @@ using System.Resources;
// these are FYI and changed automatically
[assembly: AssemblyFileVersion("8.0.0")]
[assembly: AssemblyInformationalVersion("8.0.0-alpha.29")]
[assembly: AssemblyInformationalVersion("8.0.0-alpha.30")]

View File

@@ -21,7 +21,7 @@ namespace Umbraco.Core.Configuration
/// <summary>
/// Gets the version comment of the executing code (eg "beta").
/// </summary>
public static string CurrentComment => "alpha.29";
public static string CurrentComment => "alpha.30";
/// <summary>
/// Gets the assembly version of Umbraco.Code.dll.

View File

@@ -74,6 +74,39 @@ namespace Umbraco.Core.Models.PublishedContent
return def.MakeGenericType(args);
}
/// <summary>
/// Gets the actual Clr type name by replacing model types, if any.
/// </summary>
/// <param name="type">The type.</param>
/// <param name="map">The model types map.</param>
/// <returns>The actual Clr type name.</returns>
public static string MapToName(Type type, Dictionary<string, string> map)
{
if (type is ModelType modelType)
{
if (map.TryGetValue(modelType.ContentTypeAlias, out var actualTypeName))
return actualTypeName;
throw new InvalidOperationException($"Don't know how to map ModelType with content type alias \"{modelType.ContentTypeAlias}\".");
}
if (type is ModelTypeArrayType arrayType)
{
if (map.TryGetValue(arrayType.ContentTypeAlias, out var actualTypeName))
return actualTypeName + "[]";
throw new InvalidOperationException($"Don't know how to map ModelType with content type alias \"{arrayType.ContentTypeAlias}\".");
}
if (type.IsGenericType == false)
return type.FullName;
var def = type.GetGenericTypeDefinition();
if (def == null)
throw new InvalidOperationException("panic");
var args = type.GetGenericArguments().Select(x => MapToName(x, map)).ToArray();
var defFullName = def.FullName.Substring(0, def.FullName.IndexOf('`'));
return defFullName + "<" + string.Join(", ", args) + ">";
}
/// <summary>
/// Gets a value indicating whether two <see cref="Type"/> instances are equal.
/// </summary>
@@ -229,12 +262,10 @@ namespace Umbraco.Core.Models.PublishedContent
public override Guid GUID { get; } = Guid.NewGuid();
/// <inheritdoc />
//public override Module Module => throw new NotSupportedException();
public override Module Module => GetType().Module;
public override Module Module => GetType().Module; // hackish but FullName requires something
/// <inheritdoc />
//public override Assembly Assembly => throw new NotSupportedException();
public override Assembly Assembly => GetType().Assembly;
public override Assembly Assembly => GetType().Assembly; // hackish but FullName requires something
/// <inheritdoc />
public override string FullName => Name;
@@ -354,8 +385,8 @@ namespace Umbraco.Core.Models.PublishedContent
public override string Name { get; }
public override Guid GUID { get; } = Guid.NewGuid();
public override Module Module => throw new NotSupportedException();
public override Assembly Assembly => throw new NotSupportedException();
public override Module Module =>GetType().Module; // hackish but FullName requires something
public override Assembly Assembly => GetType().Assembly; // hackish but FullName requires something
public override string FullName => Name;
public override string Namespace => string.Empty;
public override string AssemblyQualifiedName => Name;

View File

@@ -10,14 +10,14 @@ namespace Umbraco.Core.Models.PublishedContent
/// <remarks>By default, the name of the class is assumed to be the content type alias. The
/// <c>PublishedContentModelAttribute</c> can be used to indicate a different alias.</remarks>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
public sealed class PublishedContentModelAttribute : Attribute
public sealed class PublishedModelAttribute : Attribute
{
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="PublishedContentModelAttribute" /> class with a content type alias.
/// Initializes a new instance of the <see cref="PublishedModelAttribute" /> class with a content type alias.
/// </summary>
/// <param name="contentTypeAlias">The content type alias.</param>
public PublishedContentModelAttribute(string contentTypeAlias)
public PublishedModelAttribute(string contentTypeAlias)
{
if (string.IsNullOrWhiteSpace(contentTypeAlias)) throw new ArgumentNullOrEmptyException(nameof(contentTypeAlias));
ContentTypeAlias = contentTypeAlias;

View File

@@ -64,7 +64,7 @@ namespace Umbraco.Core.Models.PublishedContent
if (constructor == null)
throw new InvalidOperationException($"Type {type.FullName} is missing a public constructor with one argument of type, or implementing, IPublishedElement.");
var attribute = type.GetCustomAttribute<PublishedContentModelAttribute>(false);
var attribute = type.GetCustomAttribute<PublishedModelAttribute>(false);
var typeName = attribute == null ? type.Name : attribute.ContentTypeAlias;
if (modelInfos.TryGetValue(typeName, out var modelInfo))

View File

@@ -10,7 +10,7 @@ namespace Umbraco.Tests.Facade
{
#region Published models
[PublishedContentModel("element1")]
[PublishedModel("element1")]
public class TestElementModel1 : PublishedElementModel
{
public TestElementModel1(IPublishedElement content)
@@ -20,7 +20,7 @@ namespace Umbraco.Tests.Facade
public string Prop1 => this.Value<string>("prop1");
}
[PublishedContentModel("element2")]
[PublishedModel("element2")]
public class TestElementModel2 : PublishedElementModel
{
public TestElementModel2(IPublishedElement content)
@@ -30,7 +30,7 @@ namespace Umbraco.Tests.Facade
public IEnumerable<TestContentModel1> Prop2 => this.Value<IEnumerable<TestContentModel1>>("prop2");
}
[PublishedContentModel("content1")]
[PublishedModel("content1")]
public class TestContentModel1 : PublishedContentModel
{
public TestContentModel1(IPublishedContent content)
@@ -40,7 +40,7 @@ namespace Umbraco.Tests.Facade
public string Prop1 => this.Value<string>("prop1");
}
[PublishedContentModel("content2")]
[PublishedModel("content2")]
public class TestContentModel2 : PublishedContentModel
{
public TestContentModel2(IPublishedContent content)

View File

@@ -33,6 +33,39 @@ namespace Umbraco.Tests.Facade
Assert.AreEqual("System.Collections.Generic.IEnumerable`1[{alias1}[*]]", typeof(IEnumerable<>).MakeGenericType(ModelType.For("alias1").MakeArrayType()).ToString());
}
[Test]
public void TypeToStringTests()
{
var type = typeof(int);
Assert.AreEqual("System.Int32", type.ToString());
Assert.AreEqual("System.Int32[]", type.MakeArrayType().ToString());
Assert.AreEqual("System.Collections.Generic.IEnumerable`1[System.Int32[]]", typeof(IEnumerable<>).MakeGenericType(type.MakeArrayType()).ToString());
}
[Test]
public void ModelTypeFullNameTests()
{
Assert.AreEqual("{alias1}", ModelType.For("alias1").FullName);
Type type = ModelType.For("alias1");
Assert.AreEqual("{alias1}", type.FullName);
// there's an "*" there because the arrays are not true SZArray - but that changes when we map
Assert.AreEqual("{alias1}[*]", ModelType.For("alias1").MakeArrayType().FullName);
// note the inner assembly qualified name
Assert.AreEqual("System.Collections.Generic.IEnumerable`1[[{alias1}[*], Umbraco.Core, Version=8.0.0.0, Culture=neutral, PublicKeyToken=null]]", typeof(IEnumerable<>).MakeGenericType(ModelType.For("alias1").MakeArrayType()).FullName);
}
[Test]
public void TypeFullNameTests()
{
var type = typeof(int);
Assert.AreEqual("System.Int32", type.FullName);
Assert.AreEqual("System.Int32[]", type.MakeArrayType().FullName);
// note the inner assembly qualified name
Assert.AreEqual("System.Collections.Generic.IEnumerable`1[[System.Int32[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]", typeof(IEnumerable<>).MakeGenericType(type.MakeArrayType()).FullName);
}
[Test]
public void ModelTypeMapTests()
{

View File

@@ -32,9 +32,6 @@ namespace Umbraco.Tests.Facade
var profiler = Mock.Of<IProfiler>();
var proflog = new ProfilingLogger(logger, profiler);
var container = new ServiceContainer();
container.ConfigureUmbracoCore();
var dataTypeService = new Mock<IDataTypeService>();
// mocked dataservice returns nested content preValues
@@ -47,14 +44,14 @@ namespace Umbraco.Tests.Facade
{
{ "minItems", new PreValue("1") },
{ "maxItems", new PreValue("1") },
{ "contentTypes", new PreValue("contentN1") }
{ "contentTypes", new PreValue("[{\"ncAlias\":\"contentN1\",\"ncTabAlias\":\"\",\"nameTemplate\":\"\"}]") }
});
if (id == 2)
return new PreValueCollection(new Dictionary<string, PreValue>
{
{ "minItems", new PreValue("1") },
{ "maxItems", new PreValue("99") },
{ "contentTypes", new PreValue("contentN1") }
{ "contentTypes", new PreValue("[{\"ncAlias\":\"contentN1\",\"ncTabAlias\":\"\",\"nameTemplate\":\"\"}]") }
});
return null;
});
@@ -115,7 +112,7 @@ namespace Umbraco.Tests.Facade
PropertyEditorCollection editors = null;
editors = new PropertyEditorCollection(new PropertyEditor[]
{
new NestedContentPropertyEditor(Mock.Of<ILogger>(), new Lazy<PropertyEditorCollection>(() => editors))
new NestedContentPropertyEditor(Mock.Of<ILogger>(), new Lazy<PropertyEditorCollection>(() => editors))
});
var source = new DataTypeConfigurationSource(dataTypeService.Object, editors);

View File

@@ -259,7 +259,7 @@ namespace Umbraco.Tests.PublishedContent
public object XPathValue { get; set; }
}
[PublishedContentModel("ContentType2")]
[PublishedModel("ContentType2")]
internal class ContentType2 : PublishedContentModel
{
#region Plumbing
@@ -273,7 +273,7 @@ namespace Umbraco.Tests.PublishedContent
public int Prop1 => this.Value<int>("prop1");
}
[PublishedContentModel("ContentType2Sub")]
[PublishedModel("ContentType2Sub")]
internal class ContentType2Sub : ContentType2
{
#region Plumbing

View File

@@ -190,7 +190,7 @@ namespace Umbraco.Tests.PublishedContent
}
}
[PublishedContentModel("Home")]
[PublishedModel("Home")]
internal class Home : PublishedContentModel
{
public Home(IPublishedContent content)

View File

@@ -152,7 +152,7 @@
<Private>True</Private>
</Reference>
<Reference Include="Umbraco.ModelsBuilder, Version=8.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Umbraco.ModelsBuilder.8.0.0-alpha.11\lib\Umbraco.ModelsBuilder.dll</HintPath>
<HintPath>..\packages\Umbraco.ModelsBuilder.8.0.0-alpha.13\lib\Umbraco.ModelsBuilder.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>

View File

@@ -81,5 +81,5 @@
<package id="System.Xml.XmlDocument" version="4.3.0" targetFramework="net461" />
<package id="System.Xml.XPath" version="4.3.0" targetFramework="net461" />
<package id="System.Xml.XPath.XDocument" version="4.3.0" targetFramework="net461" />
<package id="Umbraco.ModelsBuilder" version="8.0.0-alpha.12" targetFramework="net461" />
<package id="Umbraco.ModelsBuilder" version="8.0.0-alpha.13" targetFramework="net461" />
</packages>