Exemplo n.º 1
0
        public void RemoveItems()
        {
            var list = new ListHistory <string>
            {
                "a",
                "b",
                "c",
                "d",
                "e",
                "f",
            };

            list.Remove("a");
            Assert.IsFalse(list.Contains("a"));

            list.Remove("b");
            Assert.IsFalse(list.Contains("b"));

            list.Remove("c");
            Assert.IsFalse(list.Contains("c"));

            list.Remove("d");
            Assert.IsFalse(list.Contains("d"));

            list.Remove("e");
            Assert.IsFalse(list.Contains("e"));

            list.Remove("f");
            Assert.IsFalse(list.Contains("f"));
        }
Exemplo n.º 2
0
        public void RemoveItemsAtInvalidIndex()
        {
            var list = new ListHistory <string>
            {
                "a",
                "b",
                "c",
                "d",
                "e",
                "f",
            };

            Assert.Throws <ArgumentOutOfRangeException>(() => list.RemoveAt(-1));
            Assert.Throws <ArgumentOutOfRangeException>(() => list.RemoveAt(list.Count));
        }
Exemplo n.º 3
0
        public void InsertItemsAtInvalidIndex()
        {
            var list = new ListHistory <string>
            {
                "a",
                "b",
                "c",
                "d",
                "e",
                "f",
            };

            Assert.Throws <ArgumentOutOfRangeException>(() => list.Insert(-1, "aa"));
            Assert.Throws <ArgumentOutOfRangeException>(() => list.Insert(list.Count + 1, "bb"));
        }
Exemplo n.º 4
0
        public void IndexerGetItemsAtInvalidIndex()
        {
            var list = new ListHistory <string>
            {
                "a",
                "b",
                "c",
                "d",
                "e",
                "f",
            };

            Assert.Throws <ArgumentOutOfRangeException>(
                () =>
            {
                var result = list[-1];

                // We're not expecting to get this far but code analysis says that
                // we shouldn't have unused locals, unfortunately the compiler doesn't
                // like it when we remove the local, so ..
                Assert.IsNull(result);
                Assert.Fail();
            });

            Assert.Throws <ArgumentOutOfRangeException>(
                () =>
            {
                var result = list[list.Count];

                // We're not expecting to get this far but code analysis says that
                // we shouldn't have unused locals, unfortunately the compiler doesn't
                // like it when we remove the local, so ..
                Assert.IsNull(result);
                Assert.Fail();
            });
        }