public void CanConvertImageCropperPropertyEditor(string val1, string val2, bool expected) { try { var container = RegisterFactory.Create(); var composition = new Composition(container, new TypeLoader(), Mock.Of <IProfilingLogger>(), ComponentTests.MockRuntimeState(RuntimeLevel.Run)); composition.WithCollectionBuilder <PropertyValueConverterCollectionBuilder>(); Current.Factory = composition.CreateFactory(); var logger = Mock.Of <ILogger>(); var scheme = Mock.Of <IMediaPathScheme>(); var config = Mock.Of <IContentSection>(); var mediaFileSystem = new MediaFileSystem(Mock.Of <IFileSystem>(), config, scheme, logger); var imageCropperConfiguration = new ImageCropperConfiguration() { Crops = new[] { new ImageCropperConfiguration.Crop() { Alias = "thumb", Width = 100, Height = 100 } } }; var dataTypeService = new TestObjects.TestDataTypeService( new DataType(new ImageCropperPropertyEditor(Mock.Of <ILogger>(), mediaFileSystem, Mock.Of <IContentSection>(), Mock.Of <IDataTypeService>())) { Id = 1, Configuration = imageCropperConfiguration }); var factory = new PublishedContentTypeFactory(Mock.Of <IPublishedModelFactory>(), new PropertyValueConverterCollection(Array.Empty <IPropertyValueConverter>()), dataTypeService); var converter = new ImageCropperValueConverter(); var result = converter.ConvertSourceToIntermediate(null, factory.CreatePropertyType("test", 1), val1, false); // does not use type for conversion var resultShouldMatch = val2.DeserializeImageCropperValue(); if (expected) { Assert.AreEqual(resultShouldMatch, result); } else { Assert.AreNotEqual(resultShouldMatch, result); } } finally { Current.Reset(); } }
/// <summary> /// This is called to merge in the prevalue crops with the value that is saved - similar to the property value converter for the front-end /// </summary> public override object ConvertDbToEditor(Property property, PropertyType propertyType, IDataTypeService dataTypeService) { var val = base.ConvertDbToEditor(property, propertyType, dataTypeService); var json = val as JObject; if (json != null) { ImageCropperValueConverter.MergePreValues(json, dataTypeService, propertyType.DataTypeDefinitionId); return(json); } return(val); }