Пример #1
0
        public void GroupsAreRecreated()
        {
            Func <object, object, bool>             nameMatcher = (groupName, itemName) => (string)groupName == (string)itemName;
            Func <object, int, CultureInfo, object> nameCreator = (item, level, culture) => ((int)item <= 2 ? "Lower" : "Upper") + level.ToString();

            var desc = new ConcretePropertyGroupDescription()
            {
                GroupNameFromItemFunc = nameCreator,
                NamesMatchFunc        = nameMatcher
            };

            var source = new CollectionViewSource {
                Source = new [] { 0, 1, 2, 3, 4, 5 }
            };

            source.GroupDescriptions.Add(desc);

            var groups     = source.View.Groups;
            var lowerGroup = (CollectionViewGroup)source.View.Groups [0];
            var upperGroup = (CollectionViewGroup)source.View.Groups [1];


            using (source.DeferRefresh())
                using (source.View.DeferRefresh()) {
                    source.GroupDescriptions.Clear();
                    source.GroupDescriptions.Add(desc);
                }

            Assert.AreSame(groups, source.View.Groups, "#1");
            Assert.AreNotSame(lowerGroup, source.View.Groups [0], "#2");
            Assert.AreNotSame(upperGroup, source.View.Groups [1], "#3");
        }
Пример #2
0
        public void GroupNameFromItem_InvalidName()
        {
            // An invalid name means return null
            var ob = new object();
            var p  = new ConcretePropertyGroupDescription("invalid");

            Assert.IsNull(p.GroupNameFromItem(ob, 0, null));
        }
Пример #3
0
        public void GroupNameFromItem_EmptyPropertyName()
        {
            // An empty name means 'use the object'
            var ob = new object();
            var p  = new ConcretePropertyGroupDescription("");

            Assert.AreSame(ob, p.GroupNameFromItem(ob, 0, null));
        }
Пример #4
0
        public void GroupNameFromItem_Indexer()
        {
            // An invalid name means return null
            var o = new Dictionary <string, string> ();

            o.Add("test", "result");
            var p = new ConcretePropertyGroupDescription("[test]");

            Assert.AreEqual("result", p.GroupNameFromItem(o, 0, null));
        }
Пример #5
0
        public void GroupNameFromItem_ValidName()
        {
            // An invalid name means return null
            var ob = new Rectangle {
                Width = 100
            };
            var p      = new ConcretePropertyGroupDescription("Width");
            var result = p.GroupNameFromItem(ob, 0, null);

            Assert.IsInstanceOfType <double> (result, "#1");
            Assert.AreEqual(100.0, (double)result, "#2");
        }
Пример #6
0
        public void CulturePropagatesToDescriptions()
        {
            CultureInfo culture = null;

            Source.Culture = CultureInfo.InvariantCulture;
            Assert.AreSame(Source.Culture, Source.View.Culture, "#1");

            var group = new ConcretePropertyGroupDescription {
                GroupNameFromItemFunc = (item, level, cult) => {
                    culture = cult;
                    return("A");
                }
            };

            // Verify that the method was called and we passed in the right cultureinfo
            Source.GroupDescriptions.Add(group);
            Assert.AreSame(Source.Culture, culture, "#2");
        }
Пример #7
0
        public void OneGroupDesciption()
        {
            Func <object, object, bool>             nameMatcher = (groupName, itemName) => (string)groupName == (string)itemName;
            Func <object, int, CultureInfo, object> nameCreator = (item, level, culture) => ((int)item <= 2 ? "Lower" : "Upper") + level.ToString();

            var desc = new ConcretePropertyGroupDescription()
            {
                GroupNameFromItemFunc = nameCreator,
                NamesMatchFunc        = nameMatcher
            };

            var source = new CollectionViewSource {
                Source = new [] { 0, 1, 2, 3, 4, 5 }
            };

            using (source.View.DeferRefresh()) {
                source.GroupDescriptions.Add(desc);
            }
            Assert.AreEqual(2, source.View.Groups.Count, "#1");
            var lowerGroup = (CollectionViewGroup)source.View.Groups [0];
            var upperGroup = (CollectionViewGroup)source.View.Groups [1];

            Assert.AreEqual("Lower0", lowerGroup.Name, "#2");
            Assert.AreEqual("Upper0", upperGroup.Name, "#3");

            Assert.IsTrue(lowerGroup.IsBottomLevel, "#4");
            Assert.IsTrue(upperGroup.IsBottomLevel, "#5");

            Assert.AreEqual(3, lowerGroup.ItemCount, "#6");
            Assert.AreEqual(3, upperGroup.ItemCount, "#7");

            for (int i = 0; i < 3; i++)
            {
                Assert.AreEqual(i, (int)lowerGroup.Items [i], "#8." + i);
            }
            for (int i = 0; i < 3; i++)
            {
                Assert.AreEqual(i + 3, (int)upperGroup.Items [i], "#9." + i);
            }
        }
Пример #8
0
		public void CulturePropagatesToDescriptions ()
		{
			CultureInfo culture = null;
			Source.Culture = CultureInfo.InvariantCulture;
			Assert.AreSame (Source.Culture, Source.View.Culture, "#1");

			var group = new ConcretePropertyGroupDescription {
				GroupNameFromItemFunc = (item, level, cult) => {
					culture = cult;
					return "A";
				}
			};

			// Verify that the method was called and we passed in the right cultureinfo
			Source.GroupDescriptions.Add (group);
			Assert.AreSame (Source.Culture, culture, "#2");
		}
Пример #9
0
		public void ICV_OneItemTwoGroups3 ()
		{
			var o = new object();
			var source = new CollectionViewSource { Source = new[] { o } };
			var group = new ConcretePropertyGroupDescription {
				GroupNameFromItemFunc = (item, level, culture) => new[] { "First", "Second" }
			};

			var box = new ListBox { ItemsSource = source.View };
			CreateAsyncTest(box,
				() => {
					box.ApplyTemplate();
				}, () => {
					source.GroupDescriptions.Add(group);
					Assert.AreEqual(2, box.Items.Count, "#1");
					Assert.AreEqual(o, box.Items[0], "#2");
					Assert.AreEqual(o, box.Items[1], "#3");

					// FIXME: This assertion passes in SL but not in ML. I don't think it's hugely important.
					Assert.IsNull(box.ItemContainerGenerator.ContainerFromIndex(0), "#4");
				}, () => {
					Assert.IsNotNull(box.ItemContainerGenerator.ContainerFromIndex(0), "#5");
					Assert.AreNotSame(box.ItemContainerGenerator.ContainerFromIndex(0), box.ItemContainerGenerator.ContainerFromIndex(1), "#6");
				}
			);
		}
Пример #10
0
		public void ICV_OneItemTwoGroups_Remove ()
		{
			var o = new object();
			var source = new CollectionViewSource { Source = new List<Object> { o } };
			var group = new ConcretePropertyGroupDescription {
				GroupNameFromItemFunc = (item, level, culture) => new[] { "First", "Second" }
			};

			source.GroupDescriptions.Add(group);
			var box = new ListBox { ItemsSource = source.View };
			CreateAsyncTest (box,
				() => {
					box.ApplyTemplate();
				}, () => {
					((IEditableCollectionView)source.View).RemoveAt (0);
					Assert.AreEqual (0, box.Items.Count, "#1");
				}
			);
		}
Пример #11
0
		public void ConstructorDoesNotRaisePropertyChanged ()
		{
			var p = new ConcretePropertyGroupDescription ();
			Assert.AreEqual (0, p.OnPropertyChangedCalled.Count, "#1");
		}
Пример #12
0
		public void GroupNameFromItem_Indexer ()
		{
			// An invalid name means return null
			var o = new Dictionary<string, string> ();
			o.Add ("test", "result");
			var p = new ConcretePropertyGroupDescription ("[test]");
			Assert.AreEqual ("result", p.GroupNameFromItem (o, 0, null));
		}
Пример #13
0
        public void TwoGroupDesciptions()
        {
            /* This test generates two subgroups giving this hierarchy:
             * Root
             *     Lower0
             *         Lower1 [Will contain (0, 1, 2)]
             *         Upper1
             *     Upper0
             *        Lower1
             *        Upper1 [Will contain (3, 4, 5)]
             */

            Func <object, object, bool>             nameMatcher = (groupName, itemName) => (string)groupName == (string)itemName;
            Func <object, int, CultureInfo, object> nameCreator = (item, level, culture) => ((int)item <= 2 ? "Lower" : "Upper") + level.ToString();

            var level0 = new ConcretePropertyGroupDescription()
            {
                GroupNameFromItemFunc = nameCreator,
                NamesMatchFunc        = nameMatcher
            };
            var level1 = new ConcretePropertyGroupDescription()
            {
                GroupNameFromItemFunc = nameCreator,
                NamesMatchFunc        = nameMatcher
            };

            var source = new CollectionViewSource {
                Source = new [] { 0, 1, 2, 3, 4, 5 }
            };

            using (source.View.DeferRefresh()) {
                source.GroupDescriptions.Add(level0);
                source.GroupDescriptions.Add(level1);
            }
            Assert.AreEqual(2, source.View.Groups.Count, "#1");
            var lowerGroup = (CollectionViewGroup)source.View.Groups [0];
            var upperGroup = (CollectionViewGroup)source.View.Groups [1];

            Assert.AreEqual("Lower0", lowerGroup.Name, "#2");
            Assert.AreEqual("Upper0", upperGroup.Name, "#3");

            Assert.IsFalse(lowerGroup.IsBottomLevel, "#4");
            Assert.IsFalse(upperGroup.IsBottomLevel, "#5");

            Assert.AreEqual(3, lowerGroup.ItemCount, "#6");
            Assert.AreEqual(3, upperGroup.ItemCount, "#7");

            Assert.AreEqual(1, lowerGroup.Items.Count, "#8");
            Assert.AreEqual(1, upperGroup.Items.Count, "#9");

            // Check the contents of Lower0
            var lower = (CollectionViewGroup)lowerGroup.Items [0];

            Assert.AreEqual("Lower1", lower.Name, "#10");
            Assert.IsTrue(lower.IsBottomLevel, "#12");
            Assert.AreEqual(3, lower.ItemCount, "#14");
            Assert.AreEqual(3, lower.Items.Count, "#16");

            // Check the contents of Upper0
            var upper = (CollectionViewGroup)upperGroup.Items [0];

            Assert.AreEqual("Upper1", upper.Name, "#11");
            Assert.IsTrue(upper.IsBottomLevel, "#13");
            Assert.AreEqual(3, upper.ItemCount, "#15");
            Assert.AreEqual(3, upper.Items.Count, "#17");
        }
Пример #14
0
		public void TwoGroupDesciptions ()
		{
			/* This test generates two subgroups giving this hierarchy:
			 * Root
			 *     Lower0
			 *         Lower1 [Will contain (0, 1, 2)]
			 *         Upper1
			 *     Upper0
			 *        Lower1
			 *        Upper1 [Will contain (3, 4, 5)]
			 */

			Func<object, object, bool> nameMatcher = (groupName, itemName) => (string) groupName == (string) itemName;
			Func<object, int, CultureInfo, object> nameCreator = (item, level, culture) => ((int) item <= 2 ? "Lower" : "Upper") + level.ToString ();

			var level0 = new ConcretePropertyGroupDescription () {
				GroupNameFromItemFunc = nameCreator,
				NamesMatchFunc = nameMatcher
			};
			var level1 = new ConcretePropertyGroupDescription () {
				GroupNameFromItemFunc = nameCreator,
				NamesMatchFunc = nameMatcher
			};

			var source = new CollectionViewSource { Source = new [] { 0, 1, 2, 3, 4, 5 } };
			using (source.View.DeferRefresh ()) {
				source.GroupDescriptions.Add (level0);
				source.GroupDescriptions.Add (level1);
			}
			Assert.AreEqual (2, source.View.Groups.Count, "#1");
			var lowerGroup = (CollectionViewGroup) source.View.Groups [0];
			var upperGroup = (CollectionViewGroup) source.View.Groups [1];

			Assert.AreEqual ("Lower0", lowerGroup.Name, "#2");
			Assert.AreEqual ("Upper0", upperGroup.Name, "#3");

			Assert.IsFalse (lowerGroup.IsBottomLevel, "#4");
			Assert.IsFalse (upperGroup.IsBottomLevel, "#5");

			Assert.AreEqual (3, lowerGroup.ItemCount, "#6");
			Assert.AreEqual (3, upperGroup.ItemCount, "#7");

			Assert.AreEqual (1, lowerGroup.Items.Count, "#8");
			Assert.AreEqual (1, upperGroup.Items.Count, "#9");

			// Check the contents of Lower0
			var lower = (CollectionViewGroup) lowerGroup.Items [0];
			Assert.AreEqual ("Lower1", lower.Name, "#10");
			Assert.IsTrue (lower.IsBottomLevel, "#12");
			Assert.AreEqual (3, lower.ItemCount, "#14");
			Assert.AreEqual (3, lower.Items.Count, "#16");

			// Check the contents of Upper0
			var upper = (CollectionViewGroup) upperGroup.Items [0];
			Assert.AreEqual ("Upper1", upper.Name, "#11");
			Assert.IsTrue (upper.IsBottomLevel, "#13");
			Assert.AreEqual (3, upper.ItemCount, "#15");
			Assert.AreEqual (3, upper.Items.Count, "#17");
		}
Пример #15
0
		public void GroupNameFromItem_EmptyPropertyName ()
		{
			// An empty name means 'use the object'
			var ob = new object ();
			var p = new ConcretePropertyGroupDescription ("");
			Assert.AreSame (ob, p.GroupNameFromItem (ob, 0, null));
		}
Пример #16
0
        public void ConstructorDoesNotRaisePropertyChanged()
        {
            var p = new ConcretePropertyGroupDescription();

            Assert.AreEqual(0, p.OnPropertyChangedCalled.Count, "#1");
        }
Пример #17
0
		public void OneGroupDesciption ()
		{
			Func<object, object, bool> nameMatcher = (groupName, itemName) => (string) groupName == (string) itemName;
			Func<object, int, CultureInfo, object> nameCreator = (item, level, culture) => ((int) item <= 2 ? "Lower" : "Upper") + level.ToString ();

			var desc = new ConcretePropertyGroupDescription () {
				GroupNameFromItemFunc = nameCreator,
				NamesMatchFunc = nameMatcher
			};

			var source = new CollectionViewSource { Source = new [] { 0, 1, 2, 3, 4, 5 } };
			using (source.View.DeferRefresh ()) {
				source.GroupDescriptions.Add (desc);
			}
			Assert.AreEqual (2, source.View.Groups.Count, "#1");
			var lowerGroup = (CollectionViewGroup) source.View.Groups [0];
			var upperGroup = (CollectionViewGroup) source.View.Groups [1];

			Assert.AreEqual ("Lower0", lowerGroup.Name, "#2");
			Assert.AreEqual ("Upper0", upperGroup.Name, "#3");

			Assert.IsTrue (lowerGroup.IsBottomLevel, "#4");
			Assert.IsTrue (upperGroup.IsBottomLevel, "#5");

			Assert.AreEqual (3, lowerGroup.ItemCount, "#6");
			Assert.AreEqual (3, upperGroup.ItemCount, "#7");

			for (int i = 0; i < 3; i++)
				Assert.AreEqual (i, (int) lowerGroup.Items [i], "#8." + i);
			for (int i = 0; i < 3; i++)
				Assert.AreEqual (i + 3, (int) upperGroup.Items [i], "#9." + i);
		}
Пример #18
0
		public void GroupNameFromItem_InvalidName ()
		{
			// An invalid name means return null
			var ob = new object ();
			var p = new ConcretePropertyGroupDescription ("invalid");
			Assert.IsNull (p.GroupNameFromItem (ob, 0, null));
		}
Пример #19
0
		public void GroupsAreRecreated ()
		{
			Func<object, object, bool> nameMatcher = (groupName, itemName) => (string) groupName == (string) itemName;
			Func<object, int, CultureInfo, object> nameCreator = (item, level, culture) => ((int) item <= 2 ? "Lower" : "Upper") + level.ToString ();

			var desc = new ConcretePropertyGroupDescription () {
				GroupNameFromItemFunc = nameCreator,
				NamesMatchFunc = nameMatcher
			};

			var source = new CollectionViewSource { Source = new [] { 0, 1, 2, 3, 4, 5 } };
			source.GroupDescriptions.Add (desc);

			var groups = source.View.Groups;
			var lowerGroup = (CollectionViewGroup) source.View.Groups [0];
			var upperGroup = (CollectionViewGroup) source.View.Groups [1];


			using (source.DeferRefresh ())
			using (source.View.DeferRefresh ()) {
				source.GroupDescriptions.Clear ();
				source.GroupDescriptions.Add (desc);
			}

			Assert.AreSame (groups, source.View.Groups, "#1");
			Assert.AreNotSame (lowerGroup, source.View.Groups [0], "#2");
			Assert.AreNotSame (upperGroup, source.View.Groups [1], "#3");
		}
Пример #20
0
		public void GroupNameFromItem_ValidName ()
		{
			// An invalid name means return null
			var ob = new Rectangle { Width = 100 };
			var p = new ConcretePropertyGroupDescription ("Width");
			var result = p.GroupNameFromItem (ob, 0, null);
			Assert.IsInstanceOfType<double> (result, "#1");
			Assert.AreEqual (100.0, (double) result, "#2");
		}