public void CopyTo_ShouldCopyTheCollectionToTheArrayParameter()
        {
            ConfigurationElementMock firstConfigurationElement = new ConfigurationElementMock {Name = "1"};
            ConfigurationElementMock secondConfigurationElement = new ConfigurationElementMock {Name = "2"};
            ConfigurationElementMock thirdConfigurationElement = new ConfigurationElementMock {Name = "3"};

            ConfigurationElementCollectionMock configurationElementCollection = new ConfigurationElementCollectionMock
            {
                firstConfigurationElement,
                secondConfigurationElement,
                thirdConfigurationElement
            };

            ConfigurationElementMock[] array = new ConfigurationElementMock[10];
            configurationElementCollection.CopyTo(array, 0);
            Assert.AreEqual(firstConfigurationElement, array[0]);
            Assert.AreEqual(secondConfigurationElement, array[1]);
            Assert.AreEqual(thirdConfigurationElement, array[2]);
            for(int i = 3; i < 10; i++)
            {
                Assert.IsNull(array[i]);
            }

            array = new ConfigurationElementMock[10];
            configurationElementCollection.CopyTo(array, 7);
            Assert.AreEqual(firstConfigurationElement, array[7]);
            Assert.AreEqual(secondConfigurationElement, array[8]);
            Assert.AreEqual(thirdConfigurationElement, array[9]);
            for(int i = 0; i < 7; i++)
            {
                Assert.IsNull(array[i]);
            }
        }
 public void Contains_IfTheCollectionContainsTheItem_ShouldReturnTrue()
 {
     ConfigurationElementMock configurationElement = new ConfigurationElementMock();
     ConfigurationElementCollectionMock configurationElementCollection = new ConfigurationElementCollectionMock
     {
         configurationElement
     };
     Assert.IsTrue(configurationElementCollection.Contains(configurationElement));
 }
 public void Contains_IfTheCollectionDoesNotContainTheItem_ShouldReturnFalse()
 {
     ConfigurationElementMock configurationElement = new ConfigurationElementMock();
     ConfigurationElementCollectionMock configurationElementCollection = new ConfigurationElementCollectionMock();
     Assert.IsFalse(configurationElementCollection.Contains(configurationElement));
 }
 public void This_Set_ShouldSetTheItemAtTheGivenIndex()
 {
     ConfigurationElementMock configurationElement = new ConfigurationElementMock();
     ConfigurationElementCollectionMock configurationElementCollection = new ConfigurationElementCollectionMock {configurationElement};
     Assert.AreEqual(configurationElement, configurationElementCollection[0]);
     ConfigurationElementMock anotherConfigurationElement = new ConfigurationElementMock();
     configurationElementCollection[0] = anotherConfigurationElement;
     Assert.AreEqual(anotherConfigurationElement, configurationElementCollection[0]);
     Assert.AreEqual(1, configurationElementCollection.Count);
 }
 public void This_Get_ShouldReturnTheItemAtTheGivenIndex()
 {
     ConfigurationElementMock configurationElement = new ConfigurationElementMock();
     ConfigurationElementCollectionMock configurationElementCollection = new ConfigurationElementCollectionMock {configurationElement};
     Assert.AreEqual(configurationElement, configurationElementCollection[0]);
 }
 public void This_Set_IfTheIndexIsOutOfRange_ShouldThrowAConfigurationErrorsException()
 {
     ConfigurationElementMock configurationElement = new ConfigurationElementMock();
     ConfigurationElementCollectionMock configurationElementCollection = new ConfigurationElementCollectionMock {configurationElement};
     configurationElementCollection[1] = configurationElement;
 }
        public void Remove_IfTheItemExists_ShouldRemoveTheItemFromTheCollectionAndReturnTrue()
        {
            ConfigurationElementMock firstConfigurationElement = new ConfigurationElementMock {Name = "1"};

            ConfigurationElementCollectionMock configurationElementCollection = new ConfigurationElementCollectionMock {firstConfigurationElement};

            Assert.IsTrue(configurationElementCollection.Remove(firstConfigurationElement));
            Assert.AreEqual(0, configurationElementCollection.Count);

            configurationElementCollection.Add(firstConfigurationElement);
            Assert.AreEqual(1, configurationElementCollection.Count);

            ConfigurationElementMock secondConfigurationElement = new ConfigurationElementMock {Name = "1"};

            Assert.IsTrue(configurationElementCollection.Remove(secondConfigurationElement));
            Assert.AreEqual(0, configurationElementCollection.Count);
        }
        public void Remove_IfTheItemDoesNotExist_ShouldReturnFalse()
        {
            ConfigurationElementMock firstConfigurationElement = new ConfigurationElementMock {Name = "1"};

            ConfigurationElementCollectionMock configurationElementCollection = new ConfigurationElementCollectionMock {firstConfigurationElement};

            ConfigurationElementMock secondConfigurationElement = new ConfigurationElementMock {Name = "2"};

            Assert.AreEqual(1, configurationElementCollection.Count);
            Assert.IsFalse(configurationElementCollection.Remove(secondConfigurationElement));
            Assert.AreEqual(1, configurationElementCollection.Count);
        }
        public void RemoveAt_ShouldRemoveTheItemAtTheGivenIndex()
        {
            ConfigurationElementMock firstConfigurationElement = new ConfigurationElementMock {Name = "1"};
            ConfigurationElementMock secondConfigurationElement = new ConfigurationElementMock {Name = "2"};
            ConfigurationElementMock thirdConfigurationElement = new ConfigurationElementMock {Name = "3"};

            ConfigurationElementCollectionMock configurationElementCollection = new ConfigurationElementCollectionMock
            {
                firstConfigurationElement,
                secondConfigurationElement,
                thirdConfigurationElement
            };

            Assert.AreEqual(3, configurationElementCollection.Count);

            configurationElementCollection.RemoveAt(1);

            Assert.AreEqual(2, configurationElementCollection.Count);
            Assert.AreEqual(firstConfigurationElement, configurationElementCollection[0]);
            Assert.AreEqual(thirdConfigurationElement, configurationElementCollection[1]);

            configurationElementCollection.RemoveAt(0);

            Assert.AreEqual(1, configurationElementCollection.Count);
            Assert.AreEqual(thirdConfigurationElement, configurationElementCollection[0]);

            configurationElementCollection.RemoveAt(0);

            Assert.AreEqual(0, configurationElementCollection.Count);
        }
        public void Insert_ShouldInsertTheItemAtTheGivenIndex()
        {
            ConfigurationElementMock firstConfigurationElement = new ConfigurationElementMock {Name = "1"};
            ConfigurationElementMock secondConfigurationElement = new ConfigurationElementMock {Name = "2"};
            ConfigurationElementMock thirdConfigurationElement = new ConfigurationElementMock {Name = "3"};

            ConfigurationElementCollectionMock configurationElementCollection = new ConfigurationElementCollectionMock
            {
                firstConfigurationElement,
                secondConfigurationElement,
                thirdConfigurationElement
            };

            Assert.AreEqual(firstConfigurationElement, configurationElementCollection[0]);
            Assert.AreEqual(secondConfigurationElement, configurationElementCollection[1]);
            Assert.AreEqual(thirdConfigurationElement, configurationElementCollection[2]);

            configurationElementCollection.Clear();

            configurationElementCollection.Insert(0, firstConfigurationElement);
            configurationElementCollection.Insert(0, secondConfigurationElement);
            configurationElementCollection.Insert(0, thirdConfigurationElement);

            Assert.AreEqual(thirdConfigurationElement, configurationElementCollection[0]);
            Assert.AreEqual(secondConfigurationElement, configurationElementCollection[1]);
            Assert.AreEqual(firstConfigurationElement, configurationElementCollection[2]);
        }
        public void IndexOf_ShouldReturnTheIndexOfTheItem()
        {
            ConfigurationElementMock configurationElement = new ConfigurationElementMock {Name = "1"};

            ConfigurationElementCollectionMock configurationElementCollection = new ConfigurationElementCollectionMock
            {
                configurationElement
            };

            Assert.AreEqual(0, configurationElementCollection.IndexOf(configurationElement));
            Assert.AreEqual(-1, configurationElementCollection.IndexOf(new ConfigurationElementMock {Name = "2"}));
        }