public void SimpleConverter1Test() { var converters = new PropertyValueConverterCollection(() => new IPropertyValueConverter[] { new SimpleConverter1(), }); var serializer = new ConfigurationEditorJsonSerializer(); var dataTypeServiceMock = new Mock <IDataTypeService>(); var dataType = new DataType( new VoidEditor( Mock.Of <IDataValueEditorFactory>()), serializer) { Id = 1 }; dataTypeServiceMock.Setup(x => x.GetAll()).Returns(dataType.Yield); var contentTypeFactory = new PublishedContentTypeFactory(Mock.Of <IPublishedModelFactory>(), converters, dataTypeServiceMock.Object); IEnumerable <IPublishedPropertyType> CreatePropertyTypes(IPublishedContentType contentType) { yield return(contentTypeFactory.CreatePropertyType(contentType, "prop1", 1)); } IPublishedContentType elementType1 = contentTypeFactory.CreateContentType(Guid.NewGuid(), 1000, "element1", CreatePropertyTypes); var element1 = new PublishedElement(elementType1, Guid.NewGuid(), new Dictionary <string, object> { { "prop1", "1234" } }, false); Assert.AreEqual(1234, element1.Value(Mock.Of <IPublishedValueFallback>(), "prop1")); // 'null' would be considered a 'missing' value by the default, magic logic var e = new PublishedElement(elementType1, Guid.NewGuid(), new Dictionary <string, object> { { "prop1", null } }, false); Assert.IsFalse(e.HasValue("prop1")); // '0' would not - it's a valid integer - but the converter knows better e = new PublishedElement(elementType1, Guid.NewGuid(), new Dictionary <string, object> { { "prop1", "0" } }, false); Assert.IsFalse(e.HasValue("prop1")); }
public void SimpleConverter1Test() { var converters = new PropertyValueConverterCollection(new IPropertyValueConverter[] { new SimpleConverter1(), }); var dataTypeService = new TestObjects.TestDataTypeService( new DataType(new VoidEditor(Mock.Of <ILogger>())) { Id = 1 }); var contentTypeFactory = new PublishedContentTypeFactory(Mock.Of <IPublishedModelFactory>(), converters, dataTypeService); IEnumerable <IPublishedPropertyType> CreatePropertyTypes(IPublishedContentType contentType) { yield return(contentTypeFactory.CreatePropertyType(contentType, "prop1", 1)); } var elementType1 = contentTypeFactory.CreateContentType(1000, "element1", CreatePropertyTypes); var element1 = new PublishedElement(elementType1, Guid.NewGuid(), new Dictionary <string, object> { { "prop1", "1234" } }, false); Assert.AreEqual(1234, element1.Value("prop1")); // 'null' would be considered a 'missing' value by the default, magic logic var e = new PublishedElement(elementType1, Guid.NewGuid(), new Dictionary <string, object> { { "prop1", null } }, false); Assert.IsFalse(e.HasValue("prop1")); // '0' would not - it's a valid integer - but the converter knows better e = new PublishedElement(elementType1, Guid.NewGuid(), new Dictionary <string, object> { { "prop1", "0" } }, false); Assert.IsFalse(e.HasValue("prop1")); }