public void Insert_InMiddlePosition_ShouldAddItemInFifthPosition()
        {
            string inputValue = "<PropertyGroup></PropertyGroup>";

            MsBuildXmlPropertyGroupImplementation propertyGroupImplementation =
                new MsBuildXmlPropertyGroupImplementation(CreateFromString(inputValue));

            for (int i = 0; i <= 10; i++)
            {
                Mock <IMsBuildProperty> mock = new Mock <IMsBuildProperty>();
                mock.Setup(m => m.Value).Returns($"OverwrittenContent{i}");
                mock.Setup(m => m.Name).Returns($"OverwrittenTest{i}");

                propertyGroupImplementation.Add(mock.Object);
            }

            Mock <IMsBuildProperty> mockInsert = new Mock <IMsBuildProperty>();

            mockInsert.Setup(m => m.Value).Returns($"OverwrittenContent99");
            mockInsert.Setup(m => m.Name).Returns($"OverwrittenTest99");

            propertyGroupImplementation.Insert(5, mockInsert.Object);

            Assert.AreEqual("OverwrittenContent99", propertyGroupImplementation[5].Value);
        }
        /// <summary>
        /// Creates a new implemented object of the given interface type. Also checks if
        /// the given element is assignable to the given msbuild type.
        /// </summary>
        /// <param name="element"><seealso cref="XmlElement"/> to create a msbuild element from</param>
        /// <typeparam name="T">Type to create a new object from</typeparam>
        /// <returns>Created object if the given element is assignable to the given type</returns>
        public virtual T Create <T>(XmlElement element) where T : IMsBuildElement
        {
            IMsBuildElement createdObject = null;

            if (typeof(T) == typeof(IMsBuildTarget) &&
                MsBuildXmlTargetImplementation.XmlElementName.Equals(element.Name,
                                                                     StringComparison.OrdinalIgnoreCase))
            {
                createdObject = new MsBuildXmlTargetImplementation(element);
            }

            if (typeof(T) == typeof(IMsBuildOnError) &&
                MsBuildXmlOnErrorTaskImplementation.XmlElementName.Equals(element.Name,
                                                                          StringComparison.OrdinalIgnoreCase))
            {
                createdObject = new MsBuildXmlOnErrorTaskImplementation(element);
            }

            if (typeof(T) == typeof(IMsBuildPropertyGroup) &&
                MsBuildXmlPropertyGroupImplementation.XmlElementName.Equals(element.Name,
                                                                            StringComparison.OrdinalIgnoreCase))
            {
                createdObject = new MsBuildXmlPropertyGroupImplementation(element);
            }

            return((T)createdObject);
        }
        public void Construct_WithOnePropertyNotConditional_ShouldInitializeOnePropertNotConditional()
        {
            string inputValue = "<PropertyGroup><Test>Content</Test></PropertyGroup>";

            MsBuildXmlPropertyGroupImplementation propertyGroupImplementation =
                new MsBuildXmlPropertyGroupImplementation(CreateFromString(inputValue));

            Assert.IsFalse(propertyGroupImplementation[0].IsConditional);
        }
        public void Count_WithOneProperty_ShouldReturnOne()
        {
            string inputValue = "<PropertyGroup><Test>Content</Test></PropertyGroup>";

            MsBuildXmlPropertyGroupImplementation propertyGroupImplementation =
                new MsBuildXmlPropertyGroupImplementation(CreateFromString(inputValue));

            Assert.AreEqual(1, propertyGroupImplementation.Count);
        }
        public void IsReadOnly_WithOneProperty_ShouldReturnFalse()
        {
            string inputValue = "<PropertyGroup><Test>Content</Test></PropertyGroup>";

            MsBuildXmlPropertyGroupImplementation propertyGroupImplementation =
                new MsBuildXmlPropertyGroupImplementation(CreateFromString(inputValue));

            Assert.AreEqual(false, propertyGroupImplementation.IsReadOnly);
        }
        public void AccessorGetValue_WithOneProperty_ShouldBeAccessible()
        {
            string inputValue = "<PropertyGroup><Test>Content</Test></PropertyGroup>";

            MsBuildXmlPropertyGroupImplementation propertyGroupImplementation =
                new MsBuildXmlPropertyGroupImplementation(CreateFromString(inputValue));

            Assert.AreEqual("Content", propertyGroupImplementation[0].Value);
        }
        public void Construct_WithoutProperties_ShouldInitializeNoProperties()
        {
            string inputValue = "<PropertyGroup></PropertyGroup>";

            MsBuildXmlPropertyGroupImplementation propertyGroupImplementation =
                new MsBuildXmlPropertyGroupImplementation(CreateFromString(inputValue));

            Assert.AreEqual(0, propertyGroupImplementation.Count);
        }
        public void Construct_WithTwoProperties_ShouldInitializeTwoProperties()
        {
            string inputValue = "<PropertyGroup><Test>Content</Test><Test2>Content</Test2></PropertyGroup>";

            MsBuildXmlPropertyGroupImplementation propertyGroupImplementation =
                new MsBuildXmlPropertyGroupImplementation(CreateFromString(inputValue));

            Assert.AreEqual("Test", propertyGroupImplementation[0].Name);
            Assert.AreEqual("Test2", propertyGroupImplementation[1].Name);
        }
        public void Construct_WithPropertyAndCondition_ShouldInitializePropertyHasConditionTrue()
        {
            string inputValue =
                "<PropertyGroup><Test Condition=\"$(Conditioner)=='Condition'\">Value</Test></PropertyGroup>";

            MsBuildXmlPropertyGroupImplementation propertyGroupImplementation =
                new MsBuildXmlPropertyGroupImplementation(CreateFromString(inputValue));

            Assert.IsTrue(propertyGroupImplementation[0].IsConditional);
        }
        Construct_WithOnePropertyNameTestAndValueContent_ShouldInitializeOnePropertyWithNameTestAndValueContent()
        {
            string inputValue = "<PropertyGroup><Test>Content</Test></PropertyGroup>";

            MsBuildXmlPropertyGroupImplementation propertyGroupImplementation =
                new MsBuildXmlPropertyGroupImplementation(CreateFromString(inputValue));

            Assert.AreEqual("Test", propertyGroupImplementation[0].Name);
            Assert.AreEqual("Content", propertyGroupImplementation[0].Value);
        }
        public void Contains_WithExistentProperty_ShouldReturnTrue()
        {
            string inputValue = "<PropertyGroup><Test>Content</Test></PropertyGroup>";

            MsBuildXmlPropertyGroupImplementation propertyGroupImplementation =
                new MsBuildXmlPropertyGroupImplementation(CreateFromString(inputValue));

            IMsBuildProperty property = propertyGroupImplementation.First();

            Assert.IsTrue(propertyGroupImplementation.Contains(property));
        }
        public void Clear_WithOneProperty_ShouldRemoveAllEntries()
        {
            string inputValue = "<PropertyGroup><Test>Content</Test></PropertyGroup>";

            MsBuildXmlPropertyGroupImplementation propertyGroupImplementation =
                new MsBuildXmlPropertyGroupImplementation(CreateFromString(inputValue));

            propertyGroupImplementation.Clear();

            Assert.AreEqual(0, propertyGroupImplementation.Count);
        }
        public void Enumerate_WithTwoEntries_ShouldEnumerateAllEntries()
        {
            string inputValue = "<PropertyGroup><Test>Content</Test><Test2>Content</Test2></PropertyGroup>";

            IEnumerable <IMsBuildProperty> propertyGroupImplementation =
                new MsBuildXmlPropertyGroupImplementation(CreateFromString(inputValue));

            foreach (IMsBuildProperty property in propertyGroupImplementation)
            {
                Assert.AreEqual("Content", property.Value);
            }
        }
        public void Add_WithOneProperty_ShouldAddItemToList()
        {
            string inputValue = "<PropertyGroup></PropertyGroup>";

            MsBuildXmlPropertyGroupImplementation propertyGroupImplementation =
                new MsBuildXmlPropertyGroupImplementation(CreateFromString(inputValue));

            Mock <IMsBuildProperty> mock = new Mock <IMsBuildProperty>();

            mock.Setup(m => m.Value).Returns("OverwrittenContent");
            mock.Setup(m => m.Name).Returns("OverwrittenTest");

            propertyGroupImplementation.Add(mock.Object);

            Assert.AreEqual("OverwrittenContent", propertyGroupImplementation[0].Value);
        }
        public void AccessorSetValue_WithOneProperty_ShouldBeSettable()
        {
            string inputValue = "<PropertyGroup><Test>Content</Test></PropertyGroup>";

            MsBuildXmlPropertyGroupImplementation propertyGroupImplementation =
                new MsBuildXmlPropertyGroupImplementation(CreateFromString(inputValue));

            Mock <IMsBuildProperty> mock = new Mock <IMsBuildProperty>();

            mock.Setup(m => m.Value).Returns("OverwrittenContent");
            mock.Setup(m => m.Name).Returns("OverwrittenTest");

            propertyGroupImplementation[0] = mock.Object;

            Assert.AreEqual("OverwrittenContent", propertyGroupImplementation[0].Value);
        }
        public void IndexOf_LastEntryOfTenItems_ShouldReturnValueTen()
        {
            string inputValue = "<PropertyGroup></PropertyGroup>";

            MsBuildXmlPropertyGroupImplementation propertyGroupImplementation =
                new MsBuildXmlPropertyGroupImplementation(CreateFromString(inputValue));

            for (int i = 0; i <= 10; i++)
            {
                Mock <IMsBuildProperty> mock = new Mock <IMsBuildProperty>();
                mock.Setup(m => m.Value).Returns($"OverwrittenContent{i}");
                mock.Setup(m => m.Name).Returns($"OverwrittenTest{i}");

                propertyGroupImplementation.Add(mock.Object);
            }

            Assert.AreEqual(10, propertyGroupImplementation.IndexOf(propertyGroupImplementation.Last()));
        }
        public void Remove_FirstEntry_ShouldRemoveFirstEntry()
        {
            string inputValue = "<PropertyGroup></PropertyGroup>";

            MsBuildXmlPropertyGroupImplementation propertyGroupImplementation =
                new MsBuildXmlPropertyGroupImplementation(CreateFromString(inputValue));

            for (int i = 1; i < 10; i++)
            {
                Mock <IMsBuildProperty> mock = new Mock <IMsBuildProperty>();
                mock.Setup(m => m.Value).Returns($"OverwrittenContent{i}");
                mock.Setup(m => m.Name).Returns($"OverwrittenTest{i}");

                propertyGroupImplementation.Add(mock.Object);
            }

            propertyGroupImplementation.Remove(propertyGroupImplementation[0]);

            Assert.AreEqual("OverwrittenContent2", propertyGroupImplementation[0].Value);
        }
        public void CopyTo_Array_ShouldCopyAllValuesToArray()
        {
            string inputValue = "<PropertyGroup></PropertyGroup>";

            IMsBuildProperty[] array = new IMsBuildProperty[20];

            MsBuildXmlPropertyGroupImplementation propertyGroupImplementation =
                new MsBuildXmlPropertyGroupImplementation(CreateFromString(inputValue));

            for (int i = 0; i <= 10; i++)
            {
                Mock <IMsBuildProperty> mock = new Mock <IMsBuildProperty>();
                mock.Setup(m => m.Value).Returns($"OverwrittenContent{i}");
                mock.Setup(m => m.Name).Returns($"OverwrittenTest{i}");

                propertyGroupImplementation.Add(mock.Object);
            }

            propertyGroupImplementation.CopyTo(array, 0);

            Assert.AreEqual("OverwrittenContent0", array[0].Value);
        }
 public void Construct_WithNullElement_ShouldThrowArgumentNullException()
 {
     MsBuildXmlPropertyGroupImplementation propertyGroupImplementation =
         new MsBuildXmlPropertyGroupImplementation(null);
 }