Skip to content

Commit bf0da79

Browse files
author
Stephan
committed
Target Umbraco 8.1 with IPublishedContent changes
1 parent bca7cf2 commit bf0da79

File tree

10 files changed

+87
-15
lines changed

10 files changed

+87
-15
lines changed

src/SolutionInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@
3232
[assembly: AssemblyVersion("8.0.0")]
3333

3434
// ... good to have a build number ...
35-
[assembly: AssemblyFileVersion("8.0.5")]
35+
[assembly: AssemblyFileVersion("8.1.0")]
3636

3737
// NuGet Package
3838
// Note: could not release "1.8.0" because it was depending on pre-release NuGet packages
3939
// for Roslyn, so had to release 1.8.0-final... starting with 2.1.3 Roslyn has a released
4040
// 1.0 version, so now we can release "2.1.3" without the "-final" extension.
41-
[assembly: AssemblyInformationalVersion("8.0.5")]
41+
[assembly: AssemblyInformationalVersion("8.1.0")]
4242
// Do not remove this line.

src/Umbraco.ModelsBuilder.Api/Umbraco.ModelsBuilder.Api.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
</ItemGroup>
5555
<ItemGroup>
5656
<PackageReference Include="UmbracoCms.Web">
57-
<Version>8.0.1</Version>
57+
<Version>8.1.0-zb.7</Version>
5858
</PackageReference>
5959
</ItemGroup>
6060
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

src/Umbraco.ModelsBuilder.CustomTool/source.extension.vsixmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
33
<Metadata>
4-
<Identity Id="F5C32FC3-6672-4665-803D-6C5D2CAC556A" Version="8.0.5.190617001" Language="en-US" Publisher="ZpqrtBnk" />
4+
<Identity Id="F5C32FC3-6672-4665-803D-6C5D2CAC556A" Version="8.1.0.190626003" Language="en-US" Publisher="ZpqrtBnk" />
55
<DisplayName>Umbraco ModelsBuilder Custom Tool</DisplayName>
66
<Description xml:space="preserve">Umbraco Visual Studio Custom Tool for generating strongly typed IPublishedContent models.</Description>
77
<MoreInfo>https://github.com/zpqrtbnk/Zbu.ModelsBuilder</MoreInfo>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using NUnit.Framework;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using Umbraco.Core.Composing;
9+
using Umbraco.ModelsBuilder.Building;
10+
using Umbraco.ModelsBuilder.Configuration;
11+
12+
namespace Umbraco.ModelsBuilder.Tests
13+
{
14+
[TestFixture]
15+
public class BuilderCompilerTests
16+
{
17+
private string _tempDir;
18+
19+
[SetUp]
20+
public void Setup()
21+
{
22+
_tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
23+
Directory.CreateDirectory(_tempDir);
24+
25+
Current.Reset();
26+
Current.UnlockConfigs();
27+
Current.Configs.Add(() => new Config());
28+
}
29+
30+
[TearDown]
31+
public void TearDown()
32+
{
33+
if (_tempDir != null && Directory.Exists(_tempDir))
34+
Directory.Delete(_tempDir, true);
35+
}
36+
37+
[Test]
38+
public void CanCompile()
39+
{
40+
var type1 = new TypeModel
41+
{
42+
Id = 1,
43+
Alias = "type1",
44+
ClrName = "Type1",
45+
ParentId = 0,
46+
BaseType = null,
47+
ItemType = TypeModel.ItemTypes.Content,
48+
};
49+
50+
var types = new[] { type1 };
51+
52+
var code = new Dictionary<string, string>();
53+
54+
var parseResult = new CodeParser().Parse(code);
55+
var builder = new TextBuilder(types, parseResult);
56+
var btypes = builder.TypeModels;
57+
var btype0 = btypes[0];
58+
59+
var sb = new StringBuilder();
60+
builder.Generate(sb, btype0);
61+
62+
var text = sb.ToString();
63+
64+
var compiler = new Compiler();
65+
compiler.Compile("Whatever", new Dictionary<string, string> { { "code", text } }, _tempDir);
66+
Assert.IsTrue(File.Exists(Path.Combine(_tempDir, "Whatever.dll")));
67+
}
68+
}
69+
}

src/Umbraco.ModelsBuilder.Tests/SampleGeneratedCode.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,9 @@ public partial class DebugTextBuilder : PublishedContentModel
191191
#pragma warning disable 0109 // new is redundant
192192
public new const string ModelTypeAlias = "debugTextBuilder";
193193
public new const PublishedItemType ModelItemType = PublishedItemType.Content;
194-
public new static PublishedContentType GetModelContentType()
194+
public new static IPublishedContentType GetModelContentType()
195195
=> PublishedModelUtility.GetModelContentType(ModelItemType, ModelTypeAlias);
196-
public static PublishedPropertyType GetModelPropertyType<TValue>(Expression<Func<DebugTextBuilder, TValue>> selector)
196+
public static IPublishedPropertyType GetModelPropertyType<TValue>(Expression<Func<DebugTextBuilder, TValue>> selector)
197197
=> PublishedModelUtility.GetModelPropertyType(GetModelContentType(), selector);
198198
#pragma warning restore 0109
199199

src/Umbraco.ModelsBuilder.Tests/TestElements.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public PublishedProperty(string alias, object sourceValue)
2121

2222
public object SourceValue { get; }
2323

24-
public PublishedPropertyType PropertyType => throw new NotImplementedException();
24+
public IPublishedPropertyType PropertyType => throw new NotImplementedException();
2525

2626
bool IPublishedProperty.HasValue(string culture, string segment) => SourceValue != null;
2727

@@ -44,15 +44,17 @@ public class PublishedContent : IPublishedContent
4444
{
4545
private readonly PublishedProperty[] _properties;
4646

47-
public PublishedContent(PublishedContentType contentType, PublishedProperty[] properties)
47+
public PublishedContent(IPublishedContentType contentType, PublishedProperty[] properties)
4848
{
4949
ContentType = contentType;
5050
_properties = properties;
5151
}
5252

5353
public IEnumerable<IPublishedContent> Children => throw new NotImplementedException();
5454

55-
public PublishedContentType ContentType { get; }
55+
public IEnumerable<IPublishedContent> ChildrenForAllCultures => throw new NotImplementedException();
56+
57+
public IPublishedContentType ContentType { get; }
5658

5759
public DateTime CreateDate => throw new NotImplementedException();
5860

src/Umbraco.ModelsBuilder.Tests/Umbraco.ModelsBuilder.Tests.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<Version>3.12.0</Version>
3939
</PackageReference>
4040
<PackageReference Include="UmbracoCms.Web">
41-
<Version>8.0.1</Version>
41+
<Version>8.1.0-zb.7</Version>
4242
</PackageReference>
4343
</ItemGroup>
4444
<ItemGroup>
@@ -47,6 +47,7 @@
4747
</Compile>
4848
<Compile Include="ApiTests.cs" />
4949
<Compile Include="AppDomainTests.cs" />
50+
<Compile Include="BuilderCompilerTests.cs" />
5051
<Compile Include="BuilderTests.cs" />
5152
<Compile Include="ApiVersionTests.cs" />
5253
<Compile Include="CompilerTests.cs" />

src/Umbraco.ModelsBuilder/Building/TextBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,10 @@ private void WriteContentType(StringBuilder sb, TypeModel type)
203203
sb.AppendFormat("\t\tpublic new const PublishedItemType ModelItemType = PublishedItemType.{0};\n",
204204
itemType);
205205
WriteGeneratedCodeAttribute(sb, "\t\t");
206-
sb.Append("\t\tpublic new static PublishedContentType GetModelContentType()\n");
206+
sb.Append("\t\tpublic new static IPublishedContentType GetModelContentType()\n");
207207
sb.Append("\t\t\t=> PublishedModelUtility.GetModelContentType(ModelItemType, ModelTypeAlias);\n");
208208
WriteGeneratedCodeAttribute(sb, "\t\t");
209-
sb.AppendFormat("\t\tpublic static PublishedPropertyType GetModelPropertyType<TValue>(Expression<Func<{0}, TValue>> selector)\n",
209+
sb.AppendFormat("\t\tpublic static IPublishedPropertyType GetModelPropertyType<TValue>(Expression<Func<{0}, TValue>> selector)\n",
210210
type.ClrName);
211211
sb.Append("\t\t\t=> PublishedModelUtility.GetModelPropertyType(GetModelContentType(), selector);\n");
212212
sb.Append("#pragma warning restore 0109\n\n");

src/Umbraco.ModelsBuilder/Umbraco.ModelsBuilder.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<ItemGroup>
4242
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="2.10.0" />
4343
<PackageReference Include="UmbracoCms.Web">
44-
<Version>8.0.1</Version>
44+
<Version>8.1.0-zb.7</Version>
4545
</PackageReference>
4646
</ItemGroup>
4747
<ItemGroup>

src/Umbraco.ModelsBuilder/Umbraco/PublishedModelUtility.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static class PublishedModelUtility
2424
// // etc...
2525
//}
2626

27-
public static PublishedContentType GetModelContentType(PublishedItemType itemType, string alias)
27+
public static IPublishedContentType GetModelContentType(PublishedItemType itemType, string alias)
2828
{
2929
var facade = Current.UmbracoContext.PublishedSnapshot; // fixme inject!
3030
switch (itemType)
@@ -40,7 +40,7 @@ public static PublishedContentType GetModelContentType(PublishedItemType itemTyp
4040
}
4141
}
4242

43-
public static PublishedPropertyType GetModelPropertyType<TModel, TValue>(PublishedContentType contentType, Expression<Func<TModel, TValue>> selector)
43+
public static IPublishedPropertyType GetModelPropertyType<TModel, TValue>(IPublishedContentType contentType, Expression<Func<TModel, TValue>> selector)
4444
//where TModel : PublishedContentModel // fixme PublishedContentModel _or_ PublishedElementModel
4545
{
4646
// fixme therefore, missing a check on TModel here

0 commit comments

Comments
 (0)