Exemplo n.º 1
0
        public void ReadTargetOnlyContainingOnError()
        {
            ProjectOnErrorElement onError = GetOnError();

            Assert.AreEqual("t", onError.ExecuteTargetsAttribute);
            Assert.AreEqual("c", onError.Condition);
        }
Exemplo n.º 2
0
        public void SetExecuteTargetsValid()
        {
            ProjectOnErrorElement onError = GetOnError();

            onError.ExecuteTargetsAttribute = "t2";

            Assert.AreEqual("t2", onError.ExecuteTargetsAttribute);
        }
Exemplo n.º 3
0
 internal ProjectOnErrorInstance(ProjectOnErrorElement xml)
 {
     condition      = xml.Condition;
     ExecuteTargets = xml.ExecuteTargetsAttribute;
     //this.FullPath = fullPath;
     condition_location     = xml.ConditionLocation;
     ExecuteTargetsLocation = xml.ExecuteTargetsAttributeLocation;
     location = xml.Location;
 }
        public void SetInvalidExecuteTargetsEmpty()
        {
            Assert.Throws <ArgumentException>(() =>
            {
                ProjectOnErrorElement onError = GetOnError();

                onError.ExecuteTargetsAttribute = String.Empty;
            }
                                              );
        }
        public void SetInvalidExecuteTargetsNull()
        {
            Assert.Throws <ArgumentNullException>(() =>
            {
                ProjectOnErrorElement onError = GetOnError();

                onError.ExecuteTargetsAttribute = null;
            }
                                                  );
        }
Exemplo n.º 6
0
        public static void Verify(ProjectOnErrorElement viewXml, ProjectOnErrorElement realXml, ValidationContext context = null)
        {
            if (viewXml == null && realXml == null)
            {
                return;
            }
            VerifyProjectElement(viewXml, realXml, context);

            Assert.Equal(realXml.ExecuteTargetsAttribute, viewXml.ExecuteTargetsAttribute);
            VerifySameLocation(realXml.ExecuteTargetsLocation, viewXml.ExecuteTargetsLocation);
        }
        /// <summary>
        /// Adds an &lt;OnError /&gt; element to the current target.
        /// </summary>
        /// <param name="executeTargets">The targets to execute if a task fails. Separate multiple targets with semicolons. Multiple targets are executed in the order specified.</param>
        /// <param name="condition">Condition to be evaluated.</param>
        /// <param name="label">An optional label to add.</param>
        /// <returns>The current <see cref="ProjectCreator"/>.</returns>
        public ProjectCreator TargetOnError(string executeTargets, string condition = null, string label = null)
        {
            ProjectOnErrorElement onErrorElement = RootElement.CreateOnErrorElement(executeTargets);

            LastTarget.AppendChild(onErrorElement);

            onErrorElement.Condition = condition;
            onErrorElement.Label     = label;

            return(this);
        }
Exemplo n.º 8
0
        public void SetExecuteTargets()
        {
            ProjectRootElement    project = ProjectRootElement.Create();
            ProjectTargetElement  target  = project.AddTarget("t");
            ProjectOnErrorElement onError = project.CreateOnErrorElement("et");

            target.AppendChild(onError);
            Helpers.ClearDirtyFlag(project);

            onError.ExecuteTargetsAttribute = "et2";

            Assert.AreEqual("et2", onError.ExecuteTargetsAttribute);
            Assert.AreEqual(true, project.HasUnsavedChanges);
        }
Exemplo n.º 9
0
        public void SetCondition()
        {
            ProjectRootElement    project = ProjectRootElement.Create();
            ProjectTargetElement  target  = project.AddTarget("t");
            ProjectOnErrorElement onError = project.CreateOnErrorElement("et");

            target.AppendChild(onError);
            Helpers.ClearDirtyFlag(project);

            onError.Condition = "c";

            Assert.AreEqual("c", onError.Condition);
            Assert.AreEqual(true, project.HasUnsavedChanges);
        }
Exemplo n.º 10
0
        public void ReadMissingExecuteTargets()
        {
            string content = @"
                    <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' >
                        <Target Name='t'>
                            <OnError/>
                        </Target>
                    </Project>
                ";

            ProjectRootElement    project = ProjectRootElement.Create(XmlReader.Create(new StringReader(content)));
            ProjectTargetElement  target  = (ProjectTargetElement)Helpers.GetFirst(project.Children);
            ProjectOnErrorElement onError = (ProjectOnErrorElement)Helpers.GetFirst(target.Children);

            Assert.AreEqual(String.Empty, onError.ExecuteTargetsAttribute);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Get a basic ProjectOnErrorElement
        /// </summary>
        private static ProjectOnErrorElement GetOnError()
        {
            string content = @"
                    <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' >
                        <Target Name='t'>
                            <OnError ExecuteTargets='t' Condition='c'/>
                        </Target>
                    </Project>
                ";

            ProjectRootElement    project = ProjectRootElement.Create(XmlReader.Create(new StringReader(content)));
            ProjectTargetElement  target  = (ProjectTargetElement)Helpers.GetFirst(project.Children);
            ProjectOnErrorElement onError = (ProjectOnErrorElement)Helpers.GetFirst(target.Children);

            return(onError);
        }
Exemplo n.º 12
0
        private static ProjectOnErrorElement GetOnError()
        {
            string content = @"
                    <Project>
                        <Target Name='t'>
                            <OnError ExecuteTargets='t' Condition='c'/>
                        </Target>
                    </Project>
                ";

            ProjectRootElement    project = ProjectRootElement.Create(XmlReader.Create(new StringReader(content)));
            ProjectTargetElement  target  = (ProjectTargetElement)Helpers.GetFirst(project.Children);
            ProjectOnErrorElement onError = (ProjectOnErrorElement)Helpers.GetFirst(target.Children);

            return(onError);
        }
Exemplo n.º 13
0
        public void ReadEmptyExecuteTargets()
        {
            Assert.Throws <InvalidProjectFileException>(() =>
            {
                string content = @"
                    <Project>
                        <Target Name='t'>
                            <OnError ExecuteTargets=''/>
                        </Target>
                    </Project>
                ";

                ProjectRootElement project    = ProjectRootElement.Create(XmlReader.Create(new StringReader(content)));
                ProjectTargetElement target   = (ProjectTargetElement)Helpers.GetFirst(project.Children);
                ProjectOnErrorElement onError = (ProjectOnErrorElement)Helpers.GetFirst(target.Children);

                Assert.Equal(String.Empty, onError.ExecuteTargetsAttribute);
            }
                                                        );
        }
Exemplo n.º 14
0
        public void ReadTargetTwoOnErrors()
        {
            string content = @"
                    <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' >
                        <Target Name='t'>
                            <t1/>
                            <t2/>
                            <OnError ExecuteTargets='1'/>
                            <OnError ExecuteTargets='2'/>
                        </Target>
                    </Project>
                ";

            ProjectRootElement   project = ProjectRootElement.Create(XmlReader.Create(new StringReader(content)));
            ProjectTargetElement target  = (ProjectTargetElement)Helpers.GetFirst(project.Children);
            var onErrors = Helpers.MakeList(target.OnErrors);

            ProjectOnErrorElement onError1 = onErrors[0];
            ProjectOnErrorElement onError2 = onErrors[1];

            Assert.AreEqual("1", onError1.ExecuteTargetsAttribute);
            Assert.AreEqual("2", onError2.ExecuteTargetsAttribute);
        }
Exemplo n.º 15
0
        public void SetInvalidExecuteTargetsEmpty()
        {
            ProjectOnErrorElement onError = GetOnError();

            onError.ExecuteTargetsAttribute = String.Empty;
        }
Exemplo n.º 16
0
        public void SetInvalidExecuteTargetsNull()
        {
            ProjectOnErrorElement onError = GetOnError();

            onError.ExecuteTargetsAttribute = null;
        }