public void GetAllReferences_Invariant_With_IDataValueReference_Editor()
        {
            var collection = new DataValueReferenceFactoryCollection(() => Enumerable.Empty <IDataValueReferenceFactory>());

            // mediaPicker does implement IDataValueReference
            var mediaPicker = new MediaPickerPropertyEditor(
                DataValueEditorFactory,
                IOHelper);
            var propertyEditors = new PropertyEditorCollection(new DataEditorCollection(() => mediaPicker.Yield()));
            var trackedUdi1     = Udi.Create(Constants.UdiEntityType.Media, Guid.NewGuid()).ToString();
            var trackedUdi2     = Udi.Create(Constants.UdiEntityType.Media, Guid.NewGuid()).ToString();
            var trackedUdi3     = Udi.Create(Constants.UdiEntityType.Media, Guid.NewGuid()).ToString();
            var trackedUdi4     = Udi.Create(Constants.UdiEntityType.Media, Guid.NewGuid()).ToString();
            var serializer      = new ConfigurationEditorJsonSerializer();
            var property        = new Property(new PropertyType(ShortStringHelper, new DataType(mediaPicker, serializer))
            {
                Variations = ContentVariation.Nothing | ContentVariation.Segment
            })
            {
                Values = new List <PropertyValue>
                {
                    new PropertyValue
                    {
                        EditedValue = trackedUdi1
                    },

                    // Ignored (has culture)
                    new PropertyValue
                    {
                        Culture     = "en-US",
                        EditedValue = trackedUdi2
                    },

                    // Ignored (has culture)
                    new PropertyValue
                    {
                        Culture     = "en-US",
                        Segment     = "A",
                        EditedValue = trackedUdi3
                    },
                    new PropertyValue
                    {
                        Segment     = "A",
                        EditedValue = trackedUdi4
                    },

                    // Duplicate
                    new PropertyValue
                    {
                        Segment     = "B",
                        EditedValue = trackedUdi4
                    }
                }
            };
            var properties = new PropertyCollection
            {
                property
            };
            IEnumerable <UmbracoEntityReference> result = collection.GetAllReferences(properties, propertyEditors);

            Assert.AreEqual(2, result.Count());
            Assert.AreEqual(trackedUdi1, result.ElementAt(0).Udi.ToString());
            Assert.AreEqual(trackedUdi4, result.ElementAt(1).Udi.ToString());
        }
コード例 #2
0
        public void GetAllReferences_All_Variants_With_IDataValueReference_Editor()
        {
            var collection = new DataValueReferenceFactoryCollection(Enumerable.Empty <IDataValueReferenceFactory>());

            // mediaPicker does implement IDataValueReference
            var mediaPicker     = new MediaPickerPropertyEditor(Mock.Of <ILogger>());
            var propertyEditors = new PropertyEditorCollection(new DataEditorCollection(mediaPicker.Yield()));
            var trackedUdi1     = Udi.Create(Constants.UdiEntityType.Media, Guid.NewGuid()).ToString();
            var trackedUdi2     = Udi.Create(Constants.UdiEntityType.Media, Guid.NewGuid()).ToString();
            var trackedUdi3     = Udi.Create(Constants.UdiEntityType.Media, Guid.NewGuid()).ToString();
            var trackedUdi4     = Udi.Create(Constants.UdiEntityType.Media, Guid.NewGuid()).ToString();
            var property        = new Property(new PropertyType(new DataType(mediaPicker))
            {
                Variations = ContentVariation.CultureAndSegment
            })
            {
                Values = new List <PropertyValue>
                {
                    // Ignored (no culture)
                    new PropertyValue
                    {
                        EditedValue = trackedUdi1
                    },
                    new PropertyValue
                    {
                        Culture     = "en-US",
                        EditedValue = trackedUdi2
                    },
                    new PropertyValue
                    {
                        Culture     = "en-US",
                        Segment     = "A",
                        EditedValue = trackedUdi3
                    },
                    // Ignored (no culture)
                    new PropertyValue
                    {
                        Segment     = "A",
                        EditedValue = trackedUdi4
                    },
                    // duplicate
                    new PropertyValue
                    {
                        Culture     = "en-US",
                        Segment     = "B",
                        EditedValue = trackedUdi3
                    }
                }
            };
            var properties = new PropertyCollection
            {
                property
            };
            var result = collection.GetAllReferences(properties, propertyEditors);

            Assert.AreEqual(2, result.Count());
            Assert.AreEqual(trackedUdi2, result.ElementAt(0).Udi.ToString());
            Assert.AreEqual(trackedUdi3, result.ElementAt(1).Udi.ToString());
        }