DataTypes refactoring - troubleshooting

This commit is contained in:
Stephan
2018-02-08 16:08:52 +01:00
parent 450854a209
commit c0439b3c4e
37 changed files with 493 additions and 315 deletions

View File

@@ -12,6 +12,8 @@ using Umbraco.Web;
using Umbraco.Web.PublishedCache.XmlPublishedCache;
using LightInject;
using Moq;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
namespace Umbraco.Tests.Misc
{
@@ -26,7 +28,10 @@ namespace Umbraco.Tests.Misc
{
base.SetUp();
var factory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), new PropertyValueConverterCollection(Array.Empty<IPropertyValueConverter>()), Mock.Of<IDataTypeConfigurationSource>());
var dataTypeService = new TestObjects.TestDataTypeService(
new DataType(new VoidEditor(Mock.Of<ILogger>())) { Id = 1 });
var factory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), new PropertyValueConverterCollection(Array.Empty<IPropertyValueConverter>()), dataTypeService);
// need to specify a custom callback for unit tests
// AutoPublishedContentTypes generates properties automatically
@@ -36,7 +41,7 @@ namespace Umbraco.Tests.Misc
var propertyTypes = new[]
{
// AutoPublishedContentType will auto-generate other properties
factory.CreatePropertyType("content", 0, "?"),
factory.CreatePropertyType("content", 1),
};
var type = new AutoPublishedContentType(0, "anything", propertyTypes);
ContentTypesCache.GetPublishedContentTypeByAlias = (alias) => type;

View File

@@ -138,10 +138,6 @@ namespace Umbraco.Tests.Models
postedFileMock.Setup(x => x.FileName).Returns("sample.txt");
postedFileMock.Setup(x => x.InputStream).Returns(stream);
// note: must pass a data type service, the "dynamic" SetValue that accepts an object
// arg and does not get a dataTypeService is trying to get the service from app context
var dataTypeService = Mock.Of<IDataTypeService>();
// Assert
content.SetValue("title", postedFileMock.Object);

View File

@@ -7,11 +7,17 @@ using NUnit.Framework;
using Newtonsoft.Json.Linq;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.IO;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.PropertyEditors.ValueConverters;
using Umbraco.Tests.TestHelpers;
using Umbraco.Web.Models;
using Umbraco.Web;
using Umbraco.Web.PropertyEditors;
namespace Umbraco.Tests.PropertyEditors
{
@@ -64,9 +70,17 @@ namespace Umbraco.Tests.PropertyEditors
container.ConfigureUmbracoCore();
container.RegisterCollectionBuilder<PropertyValueConverterCollectionBuilder>();
container.Register<ILogger, PerContainerLifetime>(f => Mock.Of<ILogger>());
container.Register<IContentSection, PerContainerLifetime>(f => Mock.Of<IContentSection>());
var mediaFileSystem = new MediaFileSystem(Mock.Of<IFileSystem>());
var dataTypeService = new TestObjects.TestDataTypeService(
new DataType(new ImageCropperPropertyEditor(Mock.Of<ILogger>(), mediaFileSystem, Mock.Of<IContentSection>())) { Id = 1 });
var factory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), new PropertyValueConverterCollection(Array.Empty<IPropertyValueConverter>()), dataTypeService);
var converter = new ImageCropperValueConverter();
var factory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), new PropertyValueConverterCollection(Array.Empty<IPropertyValueConverter>()), Mock.Of<IDataTypeConfigurationSource>());
var result = converter.ConvertSourceToIntermediate(null, factory.CreatePropertyType("test", 0, "test"), val1, false); // does not use type for conversion
var result = converter.ConvertSourceToIntermediate(null, factory.CreatePropertyType("test", 1), val1, false); // does not use type for conversion
var resultShouldMatch = val2.DeserializeImageCropperValue();
if (expected)

View File

@@ -58,11 +58,7 @@ namespace Umbraco.Tests.PropertyEditors
Id = 1
};
var dataTypeService = Mock.Of<IDataTypeService>();
Mock.Get(dataTypeService)
.Setup(x => x.GetDataType(It.IsAny<int>()))
.Returns<int>(x => x == 1 ? dataType : null);
var dataTypeService = new TestObjects.TestDataTypeService(dataType);
var prop = new Property(1, new PropertyType(dataType));
prop.SetValue("1234,4567,8910");
@@ -89,11 +85,7 @@ namespace Umbraco.Tests.PropertyEditors
Id = 1
};
var dataTypeService = Mock.Of<IDataTypeService>();
Mock.Get(dataTypeService)
.Setup(x => x.GetDataType(It.IsAny<int>()))
.Returns<int>(x => x == 1 ? dataType : null);
var dataTypeService = new TestObjects.TestDataTypeService(dataType);
var prop = new Property(1, new PropertyType(dataType));
prop.SetValue("1234");

View File

@@ -6,8 +6,11 @@ using Moq;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
using Umbraco.Tests.TestHelpers;
using Umbraco.Web;
using Umbraco.Web.PublishedCache;
@@ -25,11 +28,15 @@ namespace Umbraco.Tests.Published
{
new SimpleConverter1(),
});
var contentTypeFactory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), converters, Mock.Of<IDataTypeConfigurationSource>());
var dataTypeService = new TestObjects.TestDataTypeService(
new DataType(new VoidEditor(Mock.Of<ILogger>())) { Id = 1 });
var contentTypeFactory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), converters, dataTypeService);
var elementType1 = contentTypeFactory.CreateContentType(1000, "element1", new[]
{
contentTypeFactory.CreatePropertyType("prop1", 0, "editor1"),
contentTypeFactory.CreatePropertyType("prop1", 1),
});
var element1 = new PublishedElement(elementType1, Guid.NewGuid(), new Dictionary<string, object> { { "prop1", "1234" } }, false);
@@ -40,7 +47,7 @@ namespace Umbraco.Tests.Published
private class SimpleConverter1 : IPropertyValueConverter
{
public bool IsConverter(PublishedPropertyType propertyType)
=> propertyType.EditorAlias.InvariantEquals("editor1");
=> propertyType.EditorAlias.InvariantEquals("Umbraco.Void");
public Type GetPropertyValueType(PublishedPropertyType propertyType)
=> typeof (int);
@@ -78,11 +85,15 @@ namespace Umbraco.Tests.Published
{
new SimpleConverter2(publishedSnapshotAccessor),
});
var contentTypeFactory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), converters, Mock.Of<IDataTypeConfigurationSource>());
var dataTypeService = new TestObjects.TestDataTypeService(
new DataType(new VoidEditor(Mock.Of<ILogger>())) { Id = 1 });
var contentTypeFactory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), converters, dataTypeService);
var elementType1 = contentTypeFactory.CreateContentType(1000, "element1", new[]
{
contentTypeFactory.CreatePropertyType("prop1", 0, "editor2"),
contentTypeFactory.CreatePropertyType("prop1", 1),
});
var element1 = new PublishedElement(elementType1, Guid.NewGuid(), new Dictionary<string, object> { { "prop1", "1234" } }, false);
@@ -106,7 +117,7 @@ namespace Umbraco.Tests.Published
}
public bool IsConverter(PublishedPropertyType propertyType)
=> propertyType.EditorAlias.InvariantEquals("editor2");
=> propertyType.EditorAlias.InvariantEquals("Umbraco.Void");
public Type GetPropertyValueType(PublishedPropertyType propertyType)
// the first version would be the "generic" version, but say we want to be more precise
@@ -160,26 +171,31 @@ namespace Umbraco.Tests.Published
Current.Container.Register(f => publishedSnapshotAccessorMock.Object);
var converters = Current.Container.GetInstance<PropertyValueConverterCollection>();
var contentTypeFactory = new PublishedContentTypeFactory(factory, converters, Mock.Of<IDataTypeConfigurationSource>());
var dataTypeService = new TestObjects.TestDataTypeService(
new DataType(new VoidEditor(Mock.Of<ILogger>())) { Id = 1 },
new DataType(new VoidEditor("2", Mock.Of<ILogger>())) { Id = 2 });
var contentTypeFactory = new PublishedContentTypeFactory(factory, converters, dataTypeService);
var elementType1 = contentTypeFactory.CreateContentType(1000, "element1", new[]
{
contentTypeFactory.CreatePropertyType("prop1", 0, "editor1"),
contentTypeFactory.CreatePropertyType("prop1", 1),
});
var elementType2 = contentTypeFactory.CreateContentType(1001, "element2", new[]
{
contentTypeFactory.CreatePropertyType("prop2", 0, "editor2"),
contentTypeFactory.CreatePropertyType("prop2", 2),
});
var contentType1 = contentTypeFactory.CreateContentType(1002, "content1", new[]
{
contentTypeFactory.CreatePropertyType("prop1", 0, "editor1"),
contentTypeFactory.CreatePropertyType("prop1", 1),
});
var contentType2 = contentTypeFactory.CreateContentType(1003, "content2", new[]
{
contentTypeFactory.CreatePropertyType("prop2", 0, "editor2"),
contentTypeFactory.CreatePropertyType("prop2", 2),
});
var element1 = new PublishedElement(elementType1, Guid.NewGuid(), new Dictionary<string, object> { { "prop1", "val1" } }, false);
@@ -222,7 +238,7 @@ namespace Umbraco.Tests.Published
public class SimpleConverter3A : PropertyValueConverterBase
{
public override bool IsConverter(PublishedPropertyType propertyType)
=> propertyType.EditorAlias == "editor1";
=> propertyType.EditorAlias == "Umbraco.Void";
public override Type GetPropertyValueType(PublishedPropertyType propertyType)
=> typeof (string);
@@ -241,7 +257,7 @@ namespace Umbraco.Tests.Published
}
public override bool IsConverter(PublishedPropertyType propertyType)
=> propertyType.EditorAlias == "editor2";
=> propertyType.EditorAlias == "Umbraco.Void.2";
public override Type GetPropertyValueType(PublishedPropertyType propertyType)
=> typeof (IEnumerable<>).MakeGenericType(ModelType.For("content1"));

View File

@@ -12,6 +12,7 @@ using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
using Umbraco.Tests.TestHelpers;
using Umbraco.Web;
using Umbraco.Web.Models;
using Umbraco.Web.PropertyEditors;
@@ -63,20 +64,13 @@ namespace Umbraco.Tests.Published
}
};
// mocked dataservice returns nested content preValues
var dataTypeService = Mock.Of<IDataTypeService>();
var dataType3 = new DataType(new TextboxPropertyEditor(logger))
{
Id = 3
};
Mock.Get(dataTypeService)
.Setup(x => x.GetDataType(It.IsAny<int>()))
.Returns<int>(x =>
{
switch (x)
{
case 1: return dataType1;
case 2: return dataType2;
default: return null;
}
});
// mocked dataservice returns nested content preValues
var dataTypeService = new TestObjects.TestDataTypeService(dataType1, dataType2, dataType3);
var publishedModelFactory = new Mock<IPublishedModelFactory>();
@@ -130,12 +124,11 @@ namespace Umbraco.Tests.Published
new NestedContentManyValueConverter(publishedSnapshotAccessor.Object, publishedModelFactory.Object, proflog),
});
var source = new DataTypeConfigurationSource(dataTypeService, editors);
var factory = new PublishedContentTypeFactory(publishedModelFactory.Object, converters, source);
var factory = new PublishedContentTypeFactory(publishedModelFactory.Object, converters, dataTypeService);
var propertyType1 = factory.CreatePropertyType("property1", 1, Constants.PropertyEditors.Aliases.NestedContent);
var propertyType2 = factory.CreatePropertyType("property2", 2, Constants.PropertyEditors.Aliases.NestedContent);
var propertyTypeN1 = factory.CreatePropertyType("propertyN1", 0, Constants.PropertyEditors.Aliases.Textbox);
var propertyType1 = factory.CreatePropertyType("property1", 1);
var propertyType2 = factory.CreatePropertyType("property2", 2);
var propertyTypeN1 = factory.CreatePropertyType("propertyN1", 3);
var contentType1 = factory.CreateContentType(1, "content1", new[] { propertyType1 });
var contentType2 = factory.CreateContentType(2, "content2", new[] { propertyType2 });

View File

@@ -4,8 +4,12 @@ using Moq;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
using Umbraco.Tests.TestHelpers;
using Umbraco.Web;
using Umbraco.Web.PublishedCache;
@@ -27,10 +31,13 @@ namespace Umbraco.Tests.Published
converter,
});
var publishedContentTypeFactory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), converters, Mock.Of<IDataTypeConfigurationSource>());
var dataTypeService = new TestObjects.TestDataTypeService(
new DataType(new VoidEditor(Mock.Of<ILogger>())) { Id = 1 });
var publishedContentTypeFactory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), converters, dataTypeService);
var setType1 = publishedContentTypeFactory.CreateContentType(1000, "set1", new[]
{
publishedContentTypeFactory.CreatePropertyType("prop1", 0, "editor1"),
publishedContentTypeFactory.CreatePropertyType("prop1", 1),
});
// PublishedElementPropertyBase.GetCacheLevels:
@@ -102,10 +109,13 @@ namespace Umbraco.Tests.Published
converter,
});
var publishedContentTypeFactory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), converters, Mock.Of<IDataTypeConfigurationSource>());
var dataTypeService = new TestObjects.TestDataTypeService(
new DataType(new VoidEditor(Mock.Of<ILogger>())) { Id = 1 });
var publishedContentTypeFactory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), converters, dataTypeService);
var setType1 = publishedContentTypeFactory.CreateContentType(1000, "set1", new[]
{
publishedContentTypeFactory.CreatePropertyType("prop1", 0, "editor1"),
publishedContentTypeFactory.CreatePropertyType("prop1", 1),
});
var elementsCache = new DictionaryCacheProvider();
@@ -173,10 +183,13 @@ namespace Umbraco.Tests.Published
converter,
});
var publishedContentTypeFactory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), converters, Mock.Of<IDataTypeConfigurationSource>());
var dataTypeService = new TestObjects.TestDataTypeService(
new DataType(new VoidEditor(Mock.Of<ILogger>())) { Id = 1 });
var publishedContentTypeFactory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), converters, dataTypeService);
var setType1 = publishedContentTypeFactory.CreateContentType(1000, "set1", new[]
{
publishedContentTypeFactory.CreatePropertyType("prop1", 0, "editor1"),
publishedContentTypeFactory.CreatePropertyType("prop1", 1),
});
Assert.Throws<Exception>(() =>
@@ -198,7 +211,7 @@ namespace Umbraco.Tests.Published
public int InterConverts { get; private set; }
public bool IsConverter(PublishedPropertyType propertyType)
=> propertyType.EditorAlias.InvariantEquals("editor1");
=> propertyType.EditorAlias.InvariantEquals("Umbraco.Void");
public Type GetPropertyValueType(PublishedPropertyType propertyType)
=> typeof(int);

View File

@@ -6,9 +6,11 @@ using Moq;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
using Umbraco.Tests.TestHelpers;
using Umbraco.Web;
@@ -121,7 +123,10 @@ namespace Umbraco.Tests.PublishedContent
private IPublishedContent GetContent(bool createChildren, int indexVals)
{
var factory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), new PropertyValueConverterCollection(Array.Empty<IPropertyValueConverter>()), Mock.Of<IDataTypeConfigurationSource>());
var dataTypeService = new TestObjects.TestDataTypeService(
new DataType(new VoidEditor(Mock.Of<ILogger>())) { Id = 1 });
var factory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), new PropertyValueConverterCollection(Array.Empty<IPropertyValueConverter>()), dataTypeService);
var contentTypeAlias = createChildren ? "Parent" : "Child";
var d = new TestPublishedContent
{
@@ -146,8 +151,8 @@ namespace Umbraco.Tests.PublishedContent
};
d.Properties = new Collection<IPublishedProperty>(new List<IPublishedProperty>
{
new RawValueProperty(factory.CreatePropertyType("property1", 0, ""), d, "value" + indexVals),
new RawValueProperty(factory.CreatePropertyType("property2", 0, ""), d, "value" + (indexVals + 1))
new RawValueProperty(factory.CreatePropertyType("property1", 1), d, "value" + indexVals),
new RawValueProperty(factory.CreatePropertyType("property2", 1), d, "value" + (indexVals + 1))
});
if (createChildren)
{
@@ -163,12 +168,12 @@ namespace Umbraco.Tests.PublishedContent
{
//create additional columns, used to test the different columns for child nodes
((Collection<IPublishedProperty>) d.Properties).Add(
new RawValueProperty(factory.CreatePropertyType("property4", 0, ""), d, "value" + (indexVals + 2)));
new RawValueProperty(factory.CreatePropertyType("property4",1), d, "value" + (indexVals + 2)));
}
else
{
((Collection<IPublishedProperty>) d.Properties).Add(
new RawValueProperty(factory.CreatePropertyType("property3", 0, ""), d, "value" + (indexVals + 2)));
new RawValueProperty(factory.CreatePropertyType("property3", 1), d, "value" + (indexVals + 2)));
}
return d;
}

View File

@@ -12,7 +12,11 @@ using Umbraco.Web.Security;
using Umbraco.Core.Composing;
using Current = Umbraco.Core.Composing.Current;
using LightInject;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.Testing;
namespace Umbraco.Tests.PublishedContent
@@ -191,13 +195,16 @@ namespace Umbraco.Tests.PublishedContent
private static SolidPublishedShapshot CreatePublishedSnapshot()
{
var factory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), new PropertyValueConverterCollection(Array.Empty<IPropertyValueConverter>()), Mock.Of<IDataTypeConfigurationSource>());
var dataTypeService = new TestObjects.TestDataTypeService(
new DataType(new VoidEditor(Mock.Of<ILogger>())) { Id = 1 });
var factory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), new PropertyValueConverterCollection(Array.Empty<IPropertyValueConverter>()), dataTypeService);
var caches = new SolidPublishedShapshot();
var cache = caches.InnerContentCache;
var props = new[]
{
factory.CreatePropertyType("prop1", 1, "?"),
factory.CreatePropertyType("prop1", 1),
};
var contentType1 = factory.CreateContentType(1, "ContentType1", Enumerable.Empty<string>(), props);

View File

@@ -6,6 +6,10 @@ using Umbraco.Core.PropertyEditors.ValueConverters;
using Umbraco.Tests.TestHelpers;
using LightInject;
using Moq;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
using Umbraco.Web.PropertyEditors;
namespace Umbraco.Tests.PublishedContent
{
@@ -35,13 +39,17 @@ namespace Umbraco.Tests.PublishedContent
base.Initialize();
var converters = Container.GetInstance<PropertyValueConverterCollection>();
var publishedContentTypeFactory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), converters, Mock.Of<IDataTypeConfigurationSource>());
var dataTypeService = new TestObjects.TestDataTypeService(
new DataType(new RichTextPropertyEditor(Mock.Of<ILogger>())) { Id = 1 });
var publishedContentTypeFactory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), converters, dataTypeService);
// need to specify a custom callback for unit tests
var propertyTypes = new[]
{
// AutoPublishedContentType will auto-generate other properties
publishedContentTypeFactory.CreatePropertyType("content", 0, Constants.PropertyEditors.Aliases.TinyMce),
publishedContentTypeFactory.CreatePropertyType("content", 1),
};
var type = new AutoPublishedContentType(0, "anything", propertyTypes);
ContentTypesCache.GetPublishedContentTypeByAlias = alias => type;

View File

@@ -4,9 +4,11 @@ using System.Linq;
using Moq;
using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
using Umbraco.Tests.TestHelpers;
using Umbraco.Web;
using Umbraco.Web.PublishedCache;
@@ -315,10 +317,16 @@ namespace Umbraco.Tests.PublishedContent
class AutoPublishedContentType : PublishedContentType
{
private static readonly PublishedContentTypeFactory Factory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), new PropertyValueConverterCollection(Array.Empty<IPropertyValueConverter>()), Mock.Of<IDataTypeConfigurationSource>());
private static readonly PublishedPropertyType Default;
private static readonly PublishedPropertyType Default
= Factory.CreatePropertyType("*", 0, "?");
static AutoPublishedContentType()
{
var dataTypeService = new TestObjects.TestDataTypeService(
new DataType(new VoidEditor(Mock.Of<ILogger>())) { Id = 666 });
var factory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), new PropertyValueConverterCollection(Array.Empty<IPropertyValueConverter>()), dataTypeService);
Default = factory.CreatePropertyType("*", 666);
}
public AutoPublishedContentType(int id, string alias, IEnumerable<PublishedPropertyType> propertyTypes)
: base(id, alias, PublishedItemType.Content, Enumerable.Empty<string>(), propertyTypes, ContentVariation.InvariantNeutral)

View File

@@ -10,7 +10,13 @@ using Umbraco.Web;
using Umbraco.Web.PublishedCache;
using Umbraco.Core.Composing;
using LightInject;
using Moq;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.Testing;
using Umbraco.Web.PropertyEditors;
namespace Umbraco.Tests.PublishedContent
{
@@ -27,6 +33,16 @@ namespace Umbraco.Tests.PublishedContent
Container.RegisterSingleton<IPublishedModelFactory>(f => new PublishedModelFactory(f.GetInstance<TypeLoader>().GetTypes<PublishedContentModel>()));
Container.RegisterSingleton<IPublishedContentTypeFactory, PublishedContentTypeFactory>();
var logger = Mock.Of<ILogger>();
var dataTypeService = new TestObjects.TestDataTypeService(
new DataType(new VoidEditor(logger)) { Id = 1},
new DataType(new TrueFalsePropertyEditor(logger)) { Id = 1001 },
new DataType(new RichTextPropertyEditor(logger)) { Id = 1002 },
new DataType(new IntegerPropertyEditor(logger)) { Id = 1003 },
new DataType(new TextboxPropertyEditor(logger)) { Id = 1004 },
new DataType(new MediaPicker2PropertyEditor(logger)) { Id = 1005 });
Container.RegisterSingleton<IDataTypeService>(f => dataTypeService);
}
protected override void Initialize()
@@ -43,11 +59,11 @@ namespace Umbraco.Tests.PublishedContent
var propertyTypes = new[]
{
// AutoPublishedContentType will auto-generate other properties
factory.CreatePropertyType("umbracoNaviHide", 0, Constants.PropertyEditors.Aliases.Boolean),
factory.CreatePropertyType("selectedNodes", 0, "?"),
factory.CreatePropertyType("umbracoUrlAlias", 0, "?"),
factory.CreatePropertyType("content", 0, Constants.PropertyEditors.Aliases.TinyMce),
factory.CreatePropertyType("testRecursive", 0, "?"),
factory.CreatePropertyType("umbracoNaviHide", 1001),
factory.CreatePropertyType("selectedNodes", 1),
factory.CreatePropertyType("umbracoUrlAlias", 1),
factory.CreatePropertyType("content", 1002),
factory.CreatePropertyType("testRecursive", 1),
};
var compositionAliases = new[] { "MyCompositionAlias" };
var type = new AutoPublishedContentType(0, "anything", compositionAliases, propertyTypes);
@@ -553,7 +569,7 @@ namespace Umbraco.Tests.PublishedContent
{
var factory = Container.GetInstance<IPublishedContentTypeFactory>() as PublishedContentTypeFactory;
var pt = factory.CreatePropertyType("detached", 0, Constants.PropertyEditors.Aliases.Integer);
var pt = factory.CreatePropertyType("detached", 1003);
var ct = factory.CreateContentType(0, "alias", new[] { pt });
var prop = new PublishedElementPropertyBase(pt, null, false, PropertyCacheLevel.None, 5548);
Assert.IsInstanceOf<int>(prop.GetValue());
@@ -572,9 +588,9 @@ namespace Umbraco.Tests.PublishedContent
{
var factory = Container.GetInstance<IPublishedContentTypeFactory>() as PublishedContentTypeFactory;
var pt1 = factory.CreatePropertyType("legend", 0, Constants.PropertyEditors.Aliases.Textbox);
var pt2 = factory.CreatePropertyType("image", 0, Constants.PropertyEditors.Aliases.MediaPicker2);
var pt3 = factory.CreatePropertyType("size", 0, Constants.PropertyEditors.Aliases.Integer);
var pt1 = factory.CreatePropertyType("legend", 1004);
var pt2 = factory.CreatePropertyType("image", 1005);
var pt3 = factory.CreatePropertyType("size", 1003);
const string val1 = "boom bam";
const int val2 = 0;
const int val3 = 666;

View File

@@ -74,7 +74,7 @@ namespace Umbraco.Tests.Scoping
var runtimeStateMock = new Mock<IRuntimeState>();
runtimeStateMock.Setup(x => x.Level).Returns(() => RuntimeLevel.Run);
var contentTypeFactory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), new PropertyValueConverterCollection(Array.Empty<IPropertyValueConverter>()), Mock.Of<IDataTypeConfigurationSource>());
var contentTypeFactory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), new PropertyValueConverterCollection(Array.Empty<IPropertyValueConverter>()), Mock.Of<IDataTypeService>());
var documentRepository = Mock.Of<IDocumentRepository>();
var mediaRepository = Mock.Of<IMediaRepository>();
var memberRepository = Mock.Of<IMemberRepository>();

View File

@@ -6,6 +6,7 @@ using Moq;
using NUnit.Framework;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
@@ -24,7 +25,11 @@ namespace Umbraco.Tests.TestHelpers
// need to specify a custom callback for unit tests
// AutoPublishedContentTypes generates properties automatically
var factory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), new PropertyValueConverterCollection(Array.Empty<IPropertyValueConverter>()), Mock.Of<IDataTypeConfigurationSource>());
var dataTypeService = new TestObjects.TestDataTypeService(
new DataType(new VoidEditor(Mock.Of<ILogger>())) { Id = 1 });
var factory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), new PropertyValueConverterCollection(Array.Empty<IPropertyValueConverter>()), dataTypeService);
var type = new AutoPublishedContentType(0, "anything", new PublishedPropertyType[] { });
ContentTypesCache.GetPublishedContentTypeByAlias = alias => type;
}

View File

@@ -1,13 +1,16 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Web;
using LightInject;
using Moq;
using Umbraco.Core;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.Events;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Persistence;
using Umbraco.Core.Services;
using Umbraco.Tests.TestHelpers.Stubs;
@@ -128,8 +131,6 @@ namespace Umbraco.Tests.TestHelpers
#region Inner classes
private class MockDbConnection : DbConnection
{
protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel)
@@ -165,6 +166,123 @@ namespace Umbraco.Tests.TestHelpers
public override ConnectionState State => ConnectionState.Open; // else NPoco reopens
}
public class TestDataTypeService : IDataTypeService
{
public TestDataTypeService()
{
DataTypes = new Dictionary<int, IDataType>();
}
public TestDataTypeService(params IDataType[] dataTypes)
{
DataTypes = dataTypes.ToDictionary(x => x.Id, x => x);
}
public TestDataTypeService(IEnumerable<IDataType> dataTypes)
{
DataTypes = dataTypes.ToDictionary(x => x.Id, x => x);
}
public Dictionary<int, IDataType> DataTypes { get; }
public Attempt<OperationResult<OperationResultType, EntityContainer>> CreateContainer(int parentId, string name, int userId = 0)
{
throw new NotImplementedException();
}
public Attempt<OperationResult> SaveContainer(EntityContainer container, int userId = 0)
{
throw new NotImplementedException();
}
public EntityContainer GetContainer(int containerId)
{
throw new NotImplementedException();
}
public EntityContainer GetContainer(Guid containerId)
{
throw new NotImplementedException();
}
public IEnumerable<EntityContainer> GetContainers(string folderName, int level)
{
throw new NotImplementedException();
}
public IEnumerable<EntityContainer> GetContainers(IDataType dataType)
{
throw new NotImplementedException();
}
public IEnumerable<EntityContainer> GetContainers(int[] containerIds)
{
throw new NotImplementedException();
}
public Attempt<OperationResult> DeleteContainer(int containerId, int userId = 0)
{
throw new NotImplementedException();
}
public Attempt<OperationResult<OperationResultType, EntityContainer>> RenameContainer(int id, string name, int userId = 0)
{
throw new NotImplementedException();
}
public IDataType GetDataType(string name)
{
throw new NotImplementedException();
}
public IDataType GetDataType(int id)
{
DataTypes.TryGetValue(id, out var dataType);
return dataType;
}
public IDataType GetDataType(Guid id)
{
throw new NotImplementedException();
}
public IEnumerable<IDataType> GetAll(params int[] ids)
{
if (ids.Length == 0) return DataTypes.Values;
return ids.Select(x => DataTypes.TryGetValue(x, out var dataType) ? dataType : null).WhereNotNull();
}
public void Save(IDataType dataType, int userId = 0)
{
throw new NotImplementedException();
}
public void Save(IEnumerable<IDataType> dataTypeDefinitions, int userId = 0)
{
throw new NotImplementedException();
}
public void Save(IEnumerable<IDataType> dataTypeDefinitions, int userId, bool raiseEvents)
{
throw new NotImplementedException();
}
public void Delete(IDataType dataType, int userId = 0)
{
throw new NotImplementedException();
}
public IEnumerable<IDataType> GetByEditorAlias(string propertyEditorAlias)
{
throw new NotImplementedException();
}
public Attempt<OperationResult<MoveOperationStatusType>> Move(IDataType toMove, int parentId)
{
throw new NotImplementedException();
}
}
#endregion
}
}

View File

@@ -183,7 +183,6 @@ namespace Umbraco.Tests.Testing
Container.RegisterCollectionBuilder<PropertyValueConverterCollectionBuilder>();
Container.RegisterSingleton<IPublishedContentTypeFactory, PublishedContentTypeFactory>();
Container.RegisterSingleton<IDataTypeConfigurationSource, DataTypeConfigurationSource>();
}
protected virtual void ComposeCacheHelper()