public static void Test_AddRange()
        {
            var listItemCollection = new ListItemCollection();

            var listItem1 = new ListItem("Hello");
            var listItem2 = new ListItem("Hello", "World");
            var listItem3 = new ListItem("Test", "Test");
            var list      = new List <ListItem> {
                listItem1, listItem2, listItem3
            };

            var listItem4 = new ListItem("Missing");

            Assert.Empty(listItemCollection);

            listItemCollection.AddRange(list);
            Assert.Equal(list.Count, listItemCollection.Count);
            foreach (var x in list)
            {
                Assert.True(listItemCollection.Contains(x));
            }
            Assert.False(listItemCollection.Contains(listItem4));

            listItemCollection.Add(listItem4);
            Assert.Equal(list.Count + 1, listItemCollection.Count);
            foreach (var x in list)
            {
                Assert.True(listItemCollection.Contains(x));
            }
            Assert.True(listItemCollection.Contains(listItem4));
        }
Exemplo n.º 2
0
        public void ContainsTest()
        {
            ListItemCollection c;
            ListItem           i;
            ListItem           i2;

            c  = new ListItemCollection();
            i  = new ListItem("Item 1", "1");
            i2 = new ListItem("Item 2", "2");

            c.Add(i);
            c.Add(i2);

            i2 = new ListItem("Item 1", "1");

            // test same vs equal
            Assert.AreEqual(true, c.Contains(i), "C1");
            Assert.AreEqual(true, c.Contains(i2), "C2");
        }
Exemplo n.º 3
0
        public ListItemCollection OpcionNula(ListItemCollection ItemCollection)
        {
            ListItem Item = new ListItem(" Seleccionar ", "0");

            if (!ItemCollection.Contains(Item))
            {
                ItemCollection.Insert(0, Item);
            }
            return(ItemCollection);
        }
Exemplo n.º 4
0
        public void Methods()
        {
            ListItemCollection c;
            ListItem           i;
            ListItem           i2;

            c = new ListItemCollection();
            Assert.AreEqual(0, c.Count, "T1");

            i = new ListItem("Item 1", "10");
            c.Add(i);
            Assert.AreEqual(1, c.Count, "T2");

            i = new ListItem("This is item 2", "20");
            c.Add(i);
            Assert.AreEqual(2, c.Count, "T3");

            Assert.AreEqual(null, c.FindByText(" is "), "T4");
            Assert.AreEqual(i.Text, c.FindByText("This is item 2").Text, "T5");
            Assert.AreSame(i, c.FindByText("This is item 2"), "T6");
            Assert.AreEqual(1, c.IndexOf(c.FindByText("This is item 2")), "T7");
            Assert.AreEqual(1, c.IndexOf(c.FindByValue("20")), "T8");

            i = new ListItem("Item 3", "30");
            Assert.IsFalse(c.Contains(i), "T9");
            c.Add(i);
            Assert.IsTrue(c.Contains(i), "T10");

            i  = new ListItem("Forth", "40");
            i2 = new ListItem("Fifth", "50");
            c.AddRange(new ListItem[] { i, i2 });
            Assert.AreEqual(5, c.Count, "T11");

            c.RemoveAt(1);
            Assert.AreEqual(4, c.Count, "T12");
            Assert.AreEqual(null, c.FindByText("This is item 2"), "T13");

            c.Clear();
            Assert.AreEqual(0, c.Count, "T13");
        }
Exemplo n.º 5
0
 /// <summary>
 /// Determines whether the supplied item is in the list.
 /// </summary>
 /// <param name="item">The item to search for.</param>
 /// <returns>True if the item is in the list, false otherwise.</returns>
 public bool Contains(SharePointListItem item)
 {
     return(ListItemCollection.Contains(item.ListItem));
 }