Ejemplo n.º 1
0
        public void DesignerActionItemCollection_Insert_DesignerActionItem_Success()
        {
            var collection = new DesignerActionItemCollection();

            var value1 = new SubDesignerActionItem("displayName", "category", "description");

            collection.Insert(0, value1);
            Assert.Same(value1, Assert.Single(collection));
            Assert.Same(value1, collection[0]);
            Assert.True(collection.Contains(value1));
            Assert.Equal(0, collection.IndexOf(value1));

            var value2 = new SubDesignerActionItem("displayName", "category", "description");

            collection.Insert(0, value2);
            Assert.Equal(new object[] { value2, value1 }, collection.Cast <object>());
            Assert.True(collection.Contains(value2));
            Assert.Equal(0, collection.IndexOf(value2));
        }
Ejemplo n.º 2
0
        public static DesignerActionItemCollection GetFilteredActionItems(this DesignerActionList actionList, IEnumerable <DesignerActionItem> fullAIList)
        {
            var col = new DesignerActionItemCollection();

            foreach (var ai in fullAIList)
            {
                if (CheckCondition(ai))
                {
                    col.Add(ai);
                }
            }

            // Add header items for displayed items
            string cat = null;

            for (var i = 0; i < col.Count; i++)
            {
                var curCat = col[i].Category;
                if (string.Compare(curCat, cat, true) != 0)
                {
                    col.Insert(i++, new DesignerActionHeaderItem(curCat));
                    cat = curCat;
                }
            }

            return(col);

            bool CheckCondition(DesignerActionItem ai)
            {
                if (ai.Properties["Condition"] != null)
                {
                    var p = actionList.GetType().GetProperty((string)ai.Properties["Condition"], allInstBind, null, typeof(bool), Type.EmptyTypes, null);
                    if (p != null)
                    {
                        return((bool)p.GetValue(actionList, null));
                    }
                }
                return(true);
            }
        }
Ejemplo n.º 3
0
        public void DesignerActionItemCollection_Insert_Remove_Count()
        {
            DesignerActionItemCollection underTest = new DesignerActionItemCollection();
            DesignerActionItem           item1     = new DesignerActionItemTest("name", "category", "description");
            DesignerActionItem           item2     = new DesignerActionItemTest("name1", "category1", "description1");
            DesignerActionItem           item3     = new DesignerActionItemTest("name2", "category2", "description2");
            DesignerActionItem           item4     = new DesignerActionItemTest("name3", "category3", "description3");

            underTest.Add(item1);
            underTest.Add(item2);

            underTest.Add(item3);
            Assert.Equal(2, underTest.IndexOf(item3));

            underTest.Insert(2, item4);
            Assert.Equal(3, underTest.IndexOf(item3));
            Assert.Equal(2, underTest.IndexOf(item4));

            underTest.Remove(item4);
            Assert.False(underTest.Contains(item4));
            Assert.Equal(2, underTest.IndexOf(item3));
            Assert.Equal(3, underTest.Count);
        }
Ejemplo n.º 4
0
        public void DesignerActionItemCollection_Insert_NullValue_ThrowsArgumentNullException()
        {
            var collection = new DesignerActionItemCollection();

            Assert.Throws <ArgumentNullException>("value", () => collection.Insert(0, null));
        }