Remove() публичный Метод

public Remove ( string name ) : void
name string
Результат void
        public void Constructor_Provider_Comparer()
        {
#pragma warning disable CS0618 // Type or member is obsolete
            MyNameObjectCollection coll = new MyNameObjectCollection(CaseInsensitiveHashCodeProvider.Default, CaseInsensitiveComparer.Default);
#pragma warning restore CS0618 // Type or member is obsolete
            coll.Add(null, null);
            Assert.Equal(1, coll.Count);
            coll.Remove(null);
            Assert.Equal(0, coll.Count);
        }
        public void Constructor_Provider_Comparer()
        {
#pragma warning disable CS0618 // Type or member is obsolete
            MyNameObjectCollection coll = new MyNameObjectCollection(CaseInsensitiveHashCodeProvider.Default, CaseInsensitiveComparer.Default);
#pragma warning restore CS0618 // Type or member is obsolete
            coll.Add(null, null);
            Assert.Equal(1, coll.Count);
            coll.Remove(null);
            Assert.Equal(0, coll.Count);
        }
        public void IsReadOnly_Set()
        {
            MyNameObjectCollection nameObjectCollection = Helpers.CreateNameObjectCollection(10);

            Assert.False(nameObjectCollection.IsReadOnly);

            nameObjectCollection.IsReadOnly = true;
            Assert.True(nameObjectCollection.IsReadOnly);

            Assert.Throws <NotSupportedException>(() => nameObjectCollection.Add("name", null));
            Assert.Throws <NotSupportedException>(() => nameObjectCollection["name"] = null);
            Assert.Throws <NotSupportedException>(() => nameObjectCollection[0]      = null);

            Assert.Throws <NotSupportedException>(() => nameObjectCollection.Remove("name"));
            Assert.Throws <NotSupportedException>(() => nameObjectCollection.RemoveAt(0));
            Assert.Throws <NotSupportedException>(() => nameObjectCollection.Clear());

            Assert.Equal("Name_0", nameObjectCollection.GetKey(0));
            Assert.Equal(new Foo("Value_0"), nameObjectCollection["Name_0"]);
            Assert.Equal(new Foo("Value_0"), nameObjectCollection[0]);
        }
Пример #4
0
        public void Test01()
        {
            MyNameObjectCollection noc = new MyNameObjectCollection();
            String key   = "key1";
            Foo    value = new Foo();


            // [] IsReadOnly is initially false
            if (noc.IsReadOnly != false)
            {
                Assert.False(true, _strErr + "IsReadOnly should be false initially");
            }

            // [] Set IsReadOnly to true
            noc.IsReadOnly = true;
            if (noc.IsReadOnly != true)
            {
                Assert.False(true, _strErr + "IsReadOnly should be true");
            }

            // Now we are going to verify that methods that change the collection throw an exception
            // if IsReadOnly is true.

            // [] Set IsReadOnly to false and add an element
            noc.IsReadOnly = false;
            if (noc.IsReadOnly != false)
            {
                Assert.False(true, _strErr + "IsReadOnly should be false");
            }

            noc.Add(key, value);
            noc.IsReadOnly = true;

            // [] Add fails
            Assert.Throws <NotSupportedException>(() => { noc.Add("new key", new Foo()); });

            // [] Remove fails
            Assert.Throws <NotSupportedException>(() => { noc.Remove(key); });

            // [] RemoveAt fails
            Assert.Throws <NotSupportedException>(() => { noc.RemoveAt(0); });

            // [] Clear fails
            Assert.Throws <NotSupportedException>(() => { noc.Clear(); });

            // [] Get by key succeeds
            if (noc[key] != value)
            {
                Assert.False(true, string.Format(_strErr + "Wrong value returned.  Expected {0}, got {1}", value, noc[key]));
            }

            // [] Set by key fails
            Assert.Throws <NotSupportedException>(() => { noc[key] = new Foo(); });

            // [] Get by index succeeds
            if (noc[0] != value)
            {
                Assert.False(true, string.Format(_strErr + "Wrong value returned.  Expected {0}, got {1}", value, noc[0]));
            }

            // [] Set by index fails
            Assert.Throws <NotSupportedException>(() => { noc[0] = new Foo(); });

            // [] GetKey succeeds
            if (noc.GetKey(0) != key)
            {
                Assert.False(true, string.Format(_strErr + "Wrong value returned.  Expected {0}, got {1}", key, noc.GetKey(0)));
            }
        }
Пример #5
0
        public void Test01()
        {
            MyNameObjectCollection noc = new MyNameObjectCollection();
            String key = "key1";
            Foo value = new Foo();


            // [] IsReadOnly is initially false
            if (noc.IsReadOnly != false)
            {
                Assert.False(true, _strErr + "IsReadOnly should be false initially");
            }

            // [] Set IsReadOnly to true
            noc.IsReadOnly = true;
            if (noc.IsReadOnly != true)
            {
                Assert.False(true, _strErr + "IsReadOnly should be true");
            }

            // Now we are going to verify that methods that change the collection throw an exception
            // if IsReadOnly is true.

            // [] Set IsReadOnly to false and add an element
            noc.IsReadOnly = false;
            if (noc.IsReadOnly != false)
            {
                Assert.False(true, _strErr + "IsReadOnly should be false");
            }

            noc.Add(key, value);
            noc.IsReadOnly = true;

            // [] Add fails
            Assert.Throws<NotSupportedException>(() => { noc.Add("new key", new Foo()); });

            // [] Remove fails
            Assert.Throws<NotSupportedException>(() => { noc.Remove(key); });

            // [] RemoveAt fails
            Assert.Throws<NotSupportedException>(() => { noc.RemoveAt(0); });

            // [] Clear fails
            Assert.Throws<NotSupportedException>(() => { noc.Clear(); });

            // [] Get by key succeeds
            if (noc[key] != value)
            {
                Assert.False(true, string.Format(_strErr + "Wrong value returned.  Expected {0}, got {1}", value, noc[key]));
            }

            // [] Set by key fails
            Assert.Throws<NotSupportedException>(() => { noc[key] = new Foo(); });

            // [] Get by index succeeds
            if (noc[0] != value)
            {
                Assert.False(true, string.Format(_strErr + "Wrong value returned.  Expected {0}, got {1}", value, noc[0]));
            }

            // [] Set by index fails
            Assert.Throws<NotSupportedException>(() => { noc[0] = new Foo(); });

            // [] GetKey succeeds
            if (noc.GetKey(0) != key)
            {
                Assert.False(true, string.Format(_strErr + "Wrong value returned.  Expected {0}, got {1}", key, noc.GetKey(0)));
            }
        }