Merge remote-tracking branch 'origin/v13/dev' into v15/merge-from-13
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
// Copyright (c) Umbraco.
|
||||
// See LICENSE for more details.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core.Configuration.Models;
|
||||
@@ -118,6 +116,102 @@ namespace Umbraco.Cms.Web.Common.PublishedModels
|
||||
Assert.AreEqual(expected.ClearLf(), gen);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateSimpleType_WithoutVersion()
|
||||
{
|
||||
// Umbraco returns nice, pascal-cased names.
|
||||
var type1 = new TypeModel
|
||||
{
|
||||
Id = 1,
|
||||
Alias = "type1",
|
||||
ClrName = "Type1",
|
||||
Name = "type1Name",
|
||||
ParentId = 0,
|
||||
BaseType = null,
|
||||
ItemType = TypeModel.ItemTypes.Content,
|
||||
};
|
||||
type1.Properties.Add(new PropertyModel
|
||||
{
|
||||
Alias = "prop1",
|
||||
ClrName = "Prop1",
|
||||
Name = "prop1Name",
|
||||
ModelClrType = typeof(string),
|
||||
});
|
||||
|
||||
TypeModel[] types = { type1 };
|
||||
|
||||
var modelsBuilderConfig = new ModelsBuilderSettings { IncludeVersionNumberInGeneratedModels = false };
|
||||
var builder = new TextBuilder(modelsBuilderConfig, types);
|
||||
|
||||
var sb = new StringBuilder();
|
||||
builder.Generate(sb, builder.GetModelsToGenerate().First());
|
||||
var gen = sb.ToString();
|
||||
|
||||
var expected = @"//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
//
|
||||
// Umbraco.ModelsBuilder.Embedded
|
||||
//
|
||||
// Changes to this file will be lost if the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Linq.Expressions;
|
||||
using Umbraco.Cms.Core.Models.PublishedContent;
|
||||
using Umbraco.Cms.Core.PublishedCache;
|
||||
using Umbraco.Cms.Infrastructure.ModelsBuilder;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Extensions;
|
||||
|
||||
namespace Umbraco.Cms.Web.Common.PublishedModels
|
||||
{
|
||||
/// <summary>type1Name</summary>
|
||||
[PublishedModel(""type1"")]
|
||||
public partial class Type1 : PublishedContentModel
|
||||
{
|
||||
// helpers
|
||||
#pragma warning disable 0109 // new is redundant
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """")]
|
||||
public new const string ModelTypeAlias = ""type1"";
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """")]
|
||||
public new const PublishedItemType ModelItemType = PublishedItemType.Content;
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """")]
|
||||
[return: global::System.Diagnostics.CodeAnalysis.MaybeNull]
|
||||
public new static IPublishedContentType GetModelContentType(IPublishedSnapshotAccessor publishedSnapshotAccessor)
|
||||
=> PublishedModelUtility.GetModelContentType(publishedSnapshotAccessor, ModelItemType, ModelTypeAlias);
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """")]
|
||||
[return: global::System.Diagnostics.CodeAnalysis.MaybeNull]
|
||||
public static IPublishedPropertyType GetModelPropertyType<TValue>(IPublishedSnapshotAccessor publishedSnapshotAccessor, Expression<Func<Type1, TValue>> selector)
|
||||
=> PublishedModelUtility.GetModelPropertyType(GetModelContentType(publishedSnapshotAccessor), selector);
|
||||
#pragma warning restore 0109
|
||||
|
||||
private IPublishedValueFallback _publishedValueFallback;
|
||||
|
||||
// ctor
|
||||
public Type1(IPublishedContent content, IPublishedValueFallback publishedValueFallback)
|
||||
: base(content, publishedValueFallback)
|
||||
{
|
||||
_publishedValueFallback = publishedValueFallback;
|
||||
}
|
||||
|
||||
// properties
|
||||
|
||||
///<summary>
|
||||
/// prop1Name
|
||||
///</summary>
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """")]
|
||||
[global::System.Diagnostics.CodeAnalysis.MaybeNull]
|
||||
[ImplementPropertyType(""prop1"")]
|
||||
public virtual string Prop1 => this.Value<string>(_publishedValueFallback, ""prop1"");
|
||||
}
|
||||
}
|
||||
";
|
||||
Console.WriteLine(gen);
|
||||
Assert.AreEqual(expected.ClearLf(), gen);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateSimpleType_Ambiguous_Issue()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user