Fix tests

This commit is contained in:
Nikolaj
2020-09-08 15:17:57 +02:00
parent a6580cc3c5
commit 6cd8617202
9 changed files with 51 additions and 42 deletions

View File

@@ -191,10 +191,10 @@ namespace Umbraco.ModelsBuilder.Embedded.Building
type.ClrName);
sb.Append("\t\t\t=> PublishedModelUtility.GetModelPropertyType(GetModelContentType(publishedSnapshotAccessor), selector);\n");
sb.Append("#pragma warning restore 0109\n\n");
sb.Append("private IPublishedValueFallback _publishedValueFallback;");
sb.Append("\t\tprivate IPublishedValueFallback _publishedValueFallback;");
// write the ctor
sb.AppendFormat("\t\t// ctor\n\t\tpublic {0}(IPublished{1} content, IPublishedValueFallback publishedValueFallback)\n\t\t\t: base(content)\n\t\t{{\n _publishedValueFallback = publishedValueFallback; \n}}\n\n",
sb.AppendFormat("\n\n\t\t// ctor\n\t\tpublic {0}(IPublished{1} content, IPublishedValueFallback publishedValueFallback)\n\t\t\t: base(content)\n\t\t{{\n\t\t\t_publishedValueFallback = publishedValueFallback; \n\t\t}}\n\n",
type.ClrName, type.IsElement ? "Element" : "Content");
// write the properties

View File

@@ -98,7 +98,7 @@ namespace Umbraco.Tests.Integration.Persistence.Repositories
Assert.That(repository.Get("test"), Is.Not.Null);
Assert.That(_fileSystems.MvcViewsFileSystem.FileExists("test.cshtml"), Is.True);
Assert.AreEqual(
@"@inherits Umbraco.Web.Common.AspNetCore.UmbracoViewPage @{ Layout = null;}".StripWhitespace(),
@"@usingUmbraco.Web.PublishedModels;@inheritsUmbraco.Web.Common.AspNetCore.UmbracoViewPage@{Layout=null;}".StripWhitespace(),
template.Content.StripWhitespace());
}
}
@@ -126,7 +126,7 @@ namespace Umbraco.Tests.Integration.Persistence.Repositories
Assert.That(repository.Get("test2"), Is.Not.Null);
Assert.That(_fileSystems.MvcViewsFileSystem.FileExists("test2.cshtml"), Is.True);
Assert.AreEqual(
"@inherits Umbraco.Web.Common.AspNetCore.UmbracoViewPage @{ Layout = \"test.cshtml\";}".StripWhitespace(),
"@usingUmbraco.Web.PublishedModels;@inherits Umbraco.Web.Common.AspNetCore.UmbracoViewPage @{ Layout = \"test.cshtml\";}".StripWhitespace(),
template2.Content.StripWhitespace());
}
}

View File

@@ -61,14 +61,11 @@ namespace Umbraco.Tests.ModelsBuilder
//------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Web;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web;
using Umbraco.Web.PublishedCache;
using Umbraco.ModelsBuilder.Embedded;
using Umbraco.Core;
namespace Umbraco.Web.PublishedModels
{
@@ -89,16 +86,20 @@ namespace Umbraco.Web.PublishedModels
=> PublishedModelUtility.GetModelPropertyType(GetModelContentType(publishedSnapshotAccessor), selector);
#pragma warning restore 0109
private IPublishedValueFallback _publishedValueFallback;
// ctor
public Type1(IPublishedContent content)
public Type1(IPublishedContent content, IPublishedValueFallback publishedValueFallback)
: base(content)
{ }
{
_publishedValueFallback = publishedValueFallback;
}
// properties
[global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """ + version + @""")]
[ImplementPropertyType(""prop1"")]
public string Prop1 => this.Value<string>(""prop1"");
public string Prop1 => this.Value<string>(_publishedValueFallback, ""prop1"");
}
}
";
@@ -177,14 +178,11 @@ namespace Umbraco.Web.PublishedModels
//------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Web;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web;
using Umbraco.Web.PublishedCache;
using Umbraco.ModelsBuilder.Embedded;
using Umbraco.Core;
namespace Umbraco.Web.PublishedModels
{
@@ -205,16 +203,20 @@ namespace Umbraco.Web.PublishedModels
=> PublishedModelUtility.GetModelPropertyType(GetModelContentType(publishedSnapshotAccessor), selector);
#pragma warning restore 0109
private IPublishedValueFallback _publishedValueFallback;
// ctor
public Type1(IPublishedContent content)
public Type1(IPublishedContent content, IPublishedValueFallback publishedValueFallback)
: base(content)
{ }
{
_publishedValueFallback = publishedValueFallback;
}
// properties
[global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """ + version + @""")]
[ImplementPropertyType(""foo"")]
public global::System.Collections.Generic.IEnumerable<global::Foo> Foo => this.Value<global::System.Collections.Generic.IEnumerable<global::Foo>>(""foo"");
public global::System.Collections.Generic.IEnumerable<global::Foo> Foo => this.Value<global::System.Collections.Generic.IEnumerable<global::Foo>>(_publishedValueFallback, ""foo"");
}
}
";

View File

@@ -185,14 +185,14 @@ namespace Umbraco.Tests.Published
var composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of<IProfilingLogger>(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache);
composition.WithCollectionBuilder<PropertyValueConverterCollectionBuilder>()
.Append<SimpleConverter3A>()
.Append<SimpleConverter3A>()
.Append<SimpleConverter3B>();
IPublishedModelFactory factory = new PublishedModelFactory(new[]
{
typeof (PublishedSnapshotTestObjects.TestElementModel1), typeof (PublishedSnapshotTestObjects.TestElementModel2),
typeof (PublishedSnapshotTestObjects.TestContentModel1), typeof (PublishedSnapshotTestObjects.TestContentModel2),
});
}, Mock.Of<IPublishedValueFallback>());
register.Register(f => factory);
var registerFactory = composition.CreateFactory();

View File

@@ -11,7 +11,7 @@ namespace Umbraco.Tests.Published
[PublishedModel("element1")]
public class TestElementModel1 : PublishedElementModel
{
public TestElementModel1(IPublishedElement content)
public TestElementModel1(IPublishedElement content, IPublishedValueFallback fallback)
: base(content)
{ }
@@ -21,7 +21,7 @@ namespace Umbraco.Tests.Published
[PublishedModel("element2")]
public class TestElementModel2 : PublishedElementModel
{
public TestElementModel2(IPublishedElement content)
public TestElementModel2(IPublishedElement content, IPublishedValueFallback fallback)
: base(content)
{ }
@@ -31,7 +31,7 @@ namespace Umbraco.Tests.Published
[PublishedModel("content1")]
public class TestContentModel1 : PublishedContentModel
{
public TestContentModel1(IPublishedContent content)
public TestContentModel1(IPublishedContent content, IPublishedValueFallback fallback)
: base(content)
{ }
@@ -41,7 +41,7 @@ namespace Umbraco.Tests.Published
[PublishedModel("content2")]
public class TestContentModel2 : PublishedContentModel
{
public TestContentModel2(IPublishedContent content)
public TestContentModel2(IPublishedContent content, IPublishedValueFallback fallback)
: base(content)
{ }

View File

@@ -43,7 +43,7 @@ namespace Umbraco.Tests.PublishedContent
{
base.Compose();
Composition.RegisterUnique<IPublishedModelFactory>(f => new PublishedModelFactory(f.GetInstance<TypeLoader>().GetTypes<PublishedContentModel>()));
Composition.RegisterUnique<IPublishedModelFactory>(f => new PublishedModelFactory(f.GetInstance<TypeLoader>().GetTypes<PublishedContentModel>(), f.GetInstance<IPublishedValueFallback>()));
}
protected override TypeLoader CreateTypeLoader(IIOHelper ioHelper, ITypeFinder typeFinder, IAppPolicyCache runtimeCache,IProfilingLogger logger, IHostingEnvironment hostingEnvironment)

View File

@@ -42,7 +42,7 @@ namespace Umbraco.Tests.PublishedContent
_publishedSnapshotAccessorMock = new Mock<IPublishedSnapshotAccessor>();
Composition.RegisterUnique<IPublishedSnapshotAccessor>(_publishedSnapshotAccessorMock.Object);
Composition.RegisterUnique<IPublishedModelFactory>(f => new PublishedModelFactory(f.GetInstance<TypeLoader>().GetTypes<PublishedContentModel>()));
Composition.RegisterUnique<IPublishedModelFactory>(f => new PublishedModelFactory(f.GetInstance<TypeLoader>().GetTypes<PublishedContentModel>(), f.GetInstance<IPublishedValueFallback>()));
Composition.RegisterUnique<IPublishedContentTypeFactory, PublishedContentTypeFactory>();
Composition.RegisterUnique<IPublishedValueFallback, PublishedValueFallback>();
@@ -241,7 +241,7 @@ namespace Umbraco.Tests.PublishedContent
[PublishedModel("Home")]
internal class Home : PublishedContentModel
{
public Home(IPublishedContent content)
public Home(IPublishedContent content, IPublishedValueFallback fallback)
: base(content)
{}
}
@@ -249,7 +249,7 @@ namespace Umbraco.Tests.PublishedContent
[PublishedModel("anything")]
internal class Anything : PublishedContentModel
{
public Anything(IPublishedContent content)
public Anything(IPublishedContent content, IPublishedValueFallback fallback)
: base(content)
{ }
}

View File

@@ -360,7 +360,7 @@ namespace Umbraco.Tests.PublishedContent
{
#region Plumbing
public ContentType2(IPublishedContent content)
public ContentType2(IPublishedContent content, IPublishedValueFallback fallback)
: base(content)
{ }
@@ -374,8 +374,8 @@ namespace Umbraco.Tests.PublishedContent
{
#region Plumbing
public ContentType2Sub(IPublishedContent content)
: base(content)
public ContentType2Sub(IPublishedContent content, IPublishedValueFallback fallback)
: base(content, fallback)
{ }
#endregion
@@ -383,7 +383,7 @@ namespace Umbraco.Tests.PublishedContent
internal class PublishedContentStrong1 : PublishedContentModel
{
public PublishedContentStrong1(IPublishedContent content)
public PublishedContentStrong1(IPublishedContent content, IPublishedValueFallback fallback)
: base(content)
{ }
@@ -392,8 +392,8 @@ namespace Umbraco.Tests.PublishedContent
internal class PublishedContentStrong1Sub : PublishedContentStrong1
{
public PublishedContentStrong1Sub(IPublishedContent content)
: base(content)
public PublishedContentStrong1Sub(IPublishedContent content, IPublishedValueFallback fallback)
: base(content, fallback)
{ }
public int AnotherValue => this.Value<int>("anotherValue");
@@ -401,7 +401,7 @@ namespace Umbraco.Tests.PublishedContent
internal class PublishedContentStrong2 : PublishedContentModel
{
public PublishedContentStrong2(IPublishedContent content)
public PublishedContentStrong2(IPublishedContent content, IPublishedValueFallback fallback)
: base(content)
{ }

View File

@@ -10,7 +10,8 @@ namespace Umbraco.Tests.Templates
public void NoOptions()
{
var view = ViewHelper.GetDefaultFileContent();
Assert.AreEqual(FixView(@"@inherits Umbraco.Web.Common.AspNetCore.UmbracoViewPage
Assert.AreEqual(FixView(@"@using Umbraco.Web.PublishedModels;
@inherits Umbraco.Web.Common.AspNetCore.UmbracoViewPage
@{
Layout = null;
}"), FixView(view));
@@ -20,7 +21,8 @@ namespace Umbraco.Tests.Templates
public void Layout()
{
var view = ViewHelper.GetDefaultFileContent(layoutPageAlias: "Dharznoik");
Assert.AreEqual(FixView(@"@inherits Umbraco.Web.Common.AspNetCore.UmbracoViewPage
Assert.AreEqual(FixView(@"@using Umbraco.Web.PublishedModels;
@inherits Umbraco.Web.Common.AspNetCore.UmbracoViewPage
@{
Layout = ""Dharznoik.cshtml"";
}"), FixView(view));
@@ -30,7 +32,8 @@ namespace Umbraco.Tests.Templates
public void ClassName()
{
var view = ViewHelper.GetDefaultFileContent(modelClassName: "ClassName");
Assert.AreEqual(FixView(@"@inherits Umbraco.Web.Common.AspNetCore.UmbracoViewPage<ClassName>
Assert.AreEqual(FixView(@"@using Umbraco.Web.PublishedModels;
@inherits Umbraco.Web.Common.AspNetCore.UmbracoViewPage<ClassName>
@{
Layout = null;
}"), FixView(view));
@@ -40,7 +43,8 @@ namespace Umbraco.Tests.Templates
public void Namespace()
{
var view = ViewHelper.GetDefaultFileContent(modelNamespace: "Models");
Assert.AreEqual(FixView(@"@inherits Umbraco.Web.Common.AspNetCore.UmbracoViewPage
Assert.AreEqual(FixView(@"@using Umbraco.Web.PublishedModels;
@inherits Umbraco.Web.Common.AspNetCore.UmbracoViewPage
@{
Layout = null;
}"), FixView(view));
@@ -50,7 +54,8 @@ namespace Umbraco.Tests.Templates
public void ClassNameAndNamespace()
{
var view = ViewHelper.GetDefaultFileContent(modelClassName: "ClassName", modelNamespace: "My.Models");
Assert.AreEqual(FixView(@"@inherits Umbraco.Web.Common.AspNetCore.UmbracoViewPage<ContentModels.ClassName>
Assert.AreEqual(FixView(@"@using Umbraco.Web.PublishedModels;
@inherits Umbraco.Web.Common.AspNetCore.UmbracoViewPage<ContentModels.ClassName>
@using ContentModels = My.Models;
@{
Layout = null;
@@ -61,7 +66,8 @@ namespace Umbraco.Tests.Templates
public void ClassNameAndNamespaceAndAlias()
{
var view = ViewHelper.GetDefaultFileContent(modelClassName: "ClassName", modelNamespace: "My.Models", modelNamespaceAlias: "MyModels");
Assert.AreEqual(FixView(@"@inherits Umbraco.Web.Common.AspNetCore.UmbracoViewPage<MyModels.ClassName>
Assert.AreEqual(FixView(@"@using Umbraco.Web.PublishedModels;
@inherits Umbraco.Web.Common.AspNetCore.UmbracoViewPage<MyModels.ClassName>
@using MyModels = My.Models;
@{
Layout = null;
@@ -72,7 +78,8 @@ namespace Umbraco.Tests.Templates
public void Combined()
{
var view = ViewHelper.GetDefaultFileContent(layoutPageAlias: "Dharznoik", modelClassName: "ClassName", modelNamespace: "My.Models", modelNamespaceAlias: "MyModels");
Assert.AreEqual(FixView(@"@inherits Umbraco.Web.Common.AspNetCore.UmbracoViewPage<MyModels.ClassName>
Assert.AreEqual(FixView(@"@using Umbraco.Web.PublishedModels;
@inherits Umbraco.Web.Common.AspNetCore.UmbracoViewPage<MyModels.ClassName>
@using MyModels = My.Models;
@{
Layout = ""Dharznoik.cshtml"";