static void AssertEnumWithDisplayName(Type enumType)
        {
            var source = EnumSourceHelper.GetEnumSource(enumType);

            source.AreEqual(x => x.Count(), 2);
            source.ElementAt(0)
            .AreEqual(x => x.Name, "OneMember")
            .AreEqual(x => GetImageUri(x.Image), UriPrefix + "icon1.ico")
            .IsNull(x => x.Description);
            source.ElementAt(1)
            .AreEqual(x => x.Name, "TwoMember")
            .AreEqual(x => GetImageUri(x.Image).ToString(), UriPrefix + "icon2.ico")
            .AreEqual(x => x.Description, "desc");

            source = EnumSourceHelper.GetEnumSource(enumType, false, null, true);
            source.ElementAt(0)
            .AreEqual(x => x.Name, "OneMember");
            source.ElementAt(1)
            .AreEqual(x => x.Name, "TwoMember");

            source = EnumSourceHelper.GetEnumSource(enumType, false, new TestEnumValueConverter(), true);
            source.ElementAt(0)
            .AreEqual(x => x.Name, "MemberOne_");
            source.ElementAt(1)
            .AreEqual(x => x.Name, "MemberTwo_");
        }
        public void IsEnumTypeTest()
        {
            var source  = EnumSourceHelper.GetEnumSource(typeof(string));
            var source2 = EnumSourceHelper.GetEnumSource(null);

            source.AreEqual <IEnumerable <EnumMemberInfo> >(Enumerable.Empty <EnumMemberInfo>());
            source2.AreEqual <IEnumerable <EnumMemberInfo> >(Enumerable.Empty <EnumMemberInfo>());
        }
 public void OrderedEnumWithSortModeTest()
 {
     EnumSourceHelperCore.GetEnumSource(typeof(OrderedEnumWithSortMode), true, null, false, EnumMembersSortMode.Default, (x, y) => { throw new InvalidOperationException(); })
     .Select(x => x.Name).SequenceEqual(new[] { "VV", "DDDD", "EEE", "B", "CCC", "AA", "XXX", "GGGGGGG" }).IsTrue();
     EnumSourceHelper.GetEnumSource(typeof(OrderedEnumWithSortMode), true, null, false, EnumMembersSortMode.DisplayName)
     .Select(x => x.Name).SequenceEqual(new[] { "VV", "DDDD", "EEE", "AA", "B", "CCC", "XXX", "GGGGGGG" }).IsTrue();
     EnumSourceHelper.GetEnumSource(typeof(OrderedEnumWithSortMode), true, null, false, EnumMembersSortMode.DisplayNameDescending)
     .Select(x => x.Name).SequenceEqual(new[] { "VV", "DDDD", "EEE", "CCC", "B", "AA", "XXX", "GGGGGGG" }).IsTrue();
     EnumSourceHelper.GetEnumSource(typeof(OrderedEnumWithSortMode), true, null, false, EnumMembersSortMode.DisplayNameLength)
     .Select(x => x.Name).SequenceEqual(new[] { "VV", "DDDD", "EEE", "B", "AA", "CCC", "XXX", "GGGGGGG" }).IsTrue();
     EnumSourceHelper.GetEnumSource(typeof(OrderedEnumWithSortMode), true, null, false, EnumMembersSortMode.DisplayNameLengthDescending)
     .Select(x => x.Name).SequenceEqual(new[] { "VV", "DDDD", "EEE", "CCC", "AA", "B", "XXX", "GGGGGGG" }).IsTrue();
 }
 void ChangeAssociatedObjectItemsSource()
 {
     if (this.AssociatedObject != null)
     {
         if (EnumType == null)
         {
             throw new Exception("EnumType required");
         }
         else
         {
             this.AssociatedObject.ItemsSource = EnumSourceHelper.GetEnumSource(EnumType, UseNumericEnumValue, NameConverter, SplitNames, SortMode);
         }
     }
 }
 void ChangeAssociatedObjectItemsSource()
 {
     if (this.AssociatedObject != null)
     {
         PropertyDescriptor descriptor = TypeDescriptor.GetProperties(this.AssociatedObject).Find("ItemsSource", true);
         if (descriptor == null)
         {
             throw new Exception("ItemsSource dependency property required");
         }
         else
         {
             descriptor.SetValue(this.AssociatedObject, EnumSourceHelper.GetEnumSource(EnumType, UseNumericEnumValue, NameConverter, SplitNames, SortMode));
         }
     }
 }
        public void SimpleEnumMetadataTest()
        {
            var source = EnumSourceHelper.GetEnumSource(typeof(EnumSimple));

            source.AreEqual(x => x.Count(), 2);
            source.ElementAt(0)
            .AreEqual(x => x.Id, 0)
            .AreEqual(x => x.Name, "MemberOne")
            .IsNull(x => x.Image);
            source.ElementAt(1)
            .AreEqual(x => x.Id, 1)
            .AreEqual(x => x.Name, "MemberTwo")
            .IsNull(x => x.Image);

            source = EnumSourceHelper.GetEnumSource(typeof(EnumSimple), false, null, true);
            source.AreEqual(x => x.Count(), 2);
            source.ElementAt(0)
            .AreEqual(x => x.Id, EnumSimple.MemberOne)
            .AreEqual(x => x.Name, "Member One")
            .IsNull(x => x.Image);
            source.ElementAt(1)
            .AreEqual(x => x.Id, EnumSimple.MemberTwo)
            .AreEqual(x => x.Name, "Member Two")
            .IsNull(x => x.Image);

            source = EnumSourceHelper.GetEnumSource(typeof(EnumSimple), false, new TestEnumValueConverter(), true);
            source.AreEqual(x => x.Count(), 2);
            source.ElementAt(0)
            .AreEqual(x => x.Id, EnumSimple.MemberOne)
            .AreEqual(x => x.Name, "MemberOne_")
            .IsNull(x => x.Image);
            source.ElementAt(1)
            .AreEqual(x => x.Id, EnumSimple.MemberTwo)
            .AreEqual(x => x.Name, "MemberTwo_")
            .IsNull(x => x.Image);
        }