Esempio n. 1
0
        public void SettingWhenConditionDirties()
        {
            string content = @"
                    <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' >
                        <Choose>
                            <When Condition='true'>
                              <PropertyGroup>
                                <p>v1</p>
                              </PropertyGroup> 
                            </When>      
                        </Choose>
                    </Project>
                ";

            Project project             = new Project(XmlReader.Create(new StringReader(content)));
            ProjectChooseElement choose = Helpers.GetFirst(project.Xml.ChooseElements);
            ProjectWhenElement   when   = Helpers.GetFirst(choose.WhenElements);

            when.Condition = "false";

            Assert.Equal("v1", project.GetPropertyValue("p"));

            project.ReevaluateIfNecessary();

            Assert.Equal(String.Empty, project.GetPropertyValue("p"));
        }
Esempio n. 2
0
        public static void Verify(ProjectChooseElement viewXml, ProjectChooseElement realXml, ValidationContext context = null)
        {
            if (viewXml == null && realXml == null)
            {
                return;
            }
            VerifyProjectElement(viewXml, realXml, context);


            Verify(viewXml.WhenElements, realXml.WhenElements, Verify, context);
            Verify(viewXml.OtherwiseElement, realXml.OtherwiseElement, context);
        }
        public void ReadInvalidEmptyChoose()
        {
            string content = @"
                    <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' >
                        <Choose/>
                    </Project>
                ";

            ProjectRootElement   project = ProjectRootElement.Create(XmlReader.Create(new StringReader(content)));
            ProjectChooseElement choose  = (ProjectChooseElement)Helpers.GetFirst(project.Children);

            Assert.AreEqual(null, Helpers.GetFirst(choose.Children));
        }
Esempio n. 4
0
        /// <summary>
        /// Adds a &lt;Choose /&gt; element to the current project.
        /// </summary>
        /// <param name="label">An optional label to add to the Choose.</param>
        /// <returns>The current <see cref="ProjectCreator"/>.</returns>
        public ProjectCreator Choose(string label = null)
        {
            _lastChoose       = AddTopLevelElement(RootElement.CreateChooseElement());
            _lastChoose.Label = label;

            _lastOtherwiseItemGroup     = null;
            _lastOtherwisePropertyGroup = null;
            _lastWhen              = null;
            _lastWhenItemGroup     = null;
            _lastWhenPropertyGroup = null;

            return(this);
        }
Esempio n. 5
0
        /// <summary>
        /// Adds a &lt;When /&gt; element to the current &lt;Choose /&gt; element.
        /// </summary>
        /// <param name="condition">An optional condition to add to the &lt;When /&gt; element.</param>
        /// <param name="label">An optional label to add to the &lt;When /&gt; element.</param>
        /// <returns>The current <see cref="ProjectCreator"/>.</returns>
        public ProjectCreator When(string condition = null, string label = null)
        {
            ProjectChooseElement lastChoose = LastChoose;

            _lastWhen       = RootElement.CreateWhenElement(condition);
            _lastWhen.Label = label;
            lastChoose.AppendChild(_lastWhen);

            _lastWhenPropertyGroup = null;
            _lastWhenItemGroup     = null;

            return(this);
        }
Esempio n. 6
0
        public void ReadChooseOnlyWhen()
        {
            string content = @"
                    <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' >
                        <Choose>
                            <When Condition='c'/>
                        </Choose>
                    </Project>
                ";

            ProjectRootElement   project = ProjectRootElement.Create(XmlReader.Create(new StringReader(content)));
            ProjectChooseElement choose  = (ProjectChooseElement)Helpers.GetFirst(project.Children);

            Assert.Equal(1, Helpers.Count(choose.WhenElements));
            Assert.Null(choose.OtherwiseElement);
        }
Esempio n. 7
0
        public void ReadChooseOnlyWhen()
        {
            string content = @"
                    <Project>
                        <Choose>
                            <When Condition='c'/>
                        </Choose>
                    </Project>
                ";

            ProjectRootElement   project = ProjectRootElement.Create(XmlReader.Create(new StringReader(content)));
            ProjectChooseElement choose  = (ProjectChooseElement)Helpers.GetFirst(project.Children);

            Assert.Equal(1, Helpers.Count(choose.WhenElements));
            Assert.Null(choose.OtherwiseElement);
        }
Esempio n. 8
0
        public void ReadInvalidEmptyChoose()
        {
            Assert.Throws <InvalidProjectFileException>(() =>
            {
                string content = @"
                    <Project>
                        <Choose/>
                    </Project>
                ";

                ProjectRootElement project  = ProjectRootElement.Create(XmlReader.Create(new StringReader(content)));
                ProjectChooseElement choose = (ProjectChooseElement)Helpers.GetFirst(project.Children);

                Assert.Null(Helpers.GetFirst(choose.Children));
            }
                                                        );
        }
Esempio n. 9
0
        public void ReadChooseBothWhenOtherwise()
        {
            string content = @"
                    <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' >
                        <Choose>
                            <When Condition='c1'/>
                            <When Condition='c2'/>
                            <Otherwise/>
                        </Choose>
                    </Project>
                ";

            ProjectRootElement   project = ProjectRootElement.Create(XmlReader.Create(new StringReader(content)));
            ProjectChooseElement choose  = (ProjectChooseElement)Helpers.GetFirst(project.Children);

            List <ProjectWhenElement> whens = Helpers.MakeList(choose.WhenElements);

            Assert.Equal(2, whens.Count);
            Assert.Equal("c1", whens[0].Condition);
            Assert.Equal("c2", whens[1].Condition);
            Assert.NotNull(choose.OtherwiseElement);
        }