Ejemplo n.º 1
0
        public void Test_UnlessAttribute(string quote, bool unlessAttr)
        {
            const string build = @"<?xml version='1.0' ?>
                <project name='testing' default='test'>
                     <target name='test'>
                        <conditionaltest quote='{0}' unless='{1}'/>
                     </target>
                </project>";

            Project project          = CreateFilebasedProject(String.Format(build, quote, unlessAttr));
            var     propertyAccessor = new PropertyAccessor(project, project.RootTargetCallStack);

            ExecuteProject(project);

            if (unlessAttr)
            {
                Assert.IsFalse(propertyAccessor.Contains(ConditionalElementTestTask.PropName),
                               String.Format("Project does contain unexpected property: '{0}'",
                                             ConditionalElementTestTask.PropName));
            }
            else
            {
                Assert.IsTrue(propertyAccessor.Contains(ConditionalElementTestTask.PropName),
                              String.Format("Project does not contain expected property: '{0}'",
                                            ConditionalElementTestTask.PropName));
                string result = propertyAccessor[ConditionalElementTestTask.PropName];
                Assert.IsTrue(result.Contains(quote),
                              String.Format("Result does not contain quote: '{0}' | '{1}'", result, quote));
            }
        }
Ejemplo n.º 2
0
        [Test] // bug #1556326
        public void Remove_Readonly_Property()
        {
            Project p = CreateFilebasedProject("<project />");
            var     propertyAccessor = new PropertyAccessor(p, p.RootTargetCallStack);

            propertyAccessor.Set("test", "value1", readOnly: true);
            Assert.IsTrue(propertyAccessor.IsReadOnlyProperty("test"), "#1");
            Assert.IsTrue(propertyAccessor.Contains("test"), "#2");
            propertyAccessor.Remove("test");
            Assert.IsFalse(propertyAccessor.IsReadOnlyProperty("test"), "#3");
            Assert.IsFalse(propertyAccessor.Contains("test"), "#4");
            propertyAccessor.Set("test", "value2");
            Assert.IsFalse(propertyAccessor.IsReadOnlyProperty("test"), "#5");
            Assert.IsTrue(propertyAccessor.Contains("test"), "#6");
        }
Ejemplo n.º 3
0
            public void Catch(BuildException be, TargetCallStack callStack, PropertyAccessor accessor)
            {
                bool   propertyExists        = false;
                string originalPropertyValue = null;

                if (Property != null)
                {
                    propertyExists = accessor.Contains(Property);

                    if (accessor.Contains(Property))
                    {
                        originalPropertyValue = accessor[Property];
                    }

                    accessor[Property] = GetExceptionMessage(be);
                }

                try {
                    Execute(callStack);
                } finally {
                    if (Property != null)
                    {
                        if (!propertyExists)
                        {
                            // if the property did not exist, then remove it again
                            accessor.Remove(Property);
                        }
                        else
                        {
                            // restore original value
                            if (!String.IsNullOrWhiteSpace(originalPropertyValue))
                            {
                                accessor[Property] = originalPropertyValue;
                            }
                        }
                    }
                }
            }
Ejemplo n.º 4
0
        public void Test_CurrentTarget()
        {
            string buildFragment = @"
                <project default='A'>
                    <target name='A'>
                        <property name='A.1' value='${target::get-current-target()}' />
                        <call target='B' />
                        <property name='A.2' value='${target::get-current-target()}' />
                    </target>

                    <target name='B' depends='C'>
                        <property name='B' value='${target::get-current-target()}' />
                    </target>

                    <target name='C'>
                        <property name='C' value='${target::get-current-target()}' />
                    </target>
                </project>";

            Project project          = CreateFilebasedProject(buildFragment);
            var     propertyAccessor = new PropertyAccessor(project, project.RootTargetCallStack);

            ExecuteProject(project);

            // check whether all expected properties exist
            Assert.IsTrue(propertyAccessor.Contains("A.1"), "Property \"A.1\" does not exist.");
            Assert.IsTrue(propertyAccessor.Contains("A.2"), "Property \"A.2\" does not exist.");
            Assert.IsTrue(propertyAccessor.Contains("B"), "Property \"B\" does not exist.");
            Assert.IsTrue(propertyAccessor.Contains("C"), "Property \"C\" does not exist.");

            // check values
            Assert.AreEqual("A", propertyAccessor["A.1"], "A.1");
            Assert.AreEqual("A", propertyAccessor["A.2"], "A.2");
            Assert.AreEqual("B", propertyAccessor["B"], "B");
            Assert.AreEqual("C", propertyAccessor["C"], "C");
        }
Ejemplo n.º 5
0
        public void Test_Uri_Default()
        {
            const string build = @"<?xml version='1.0' ?>
                <project name='testing' default='test'>
                     <target name='test'>
                        <elementTest1 />
                     </target>
                </project>";

            Project project          = CreateFilebasedProject(build);
            var     propertyAccessor = new PropertyAccessor(project, project.RootTargetCallStack);

            ExecuteProject(project);

            // uri property should not be registered
            Assert.IsFalse(propertyAccessor.Contains(ElementTest1Task.UriPropertyName));
        }
Ejemplo n.º 6
0
        public void Test_Uri_HttpScheme()
        {
            const string build = @"<?xml version='1.0' ?>
                <project name='testing' default='test'>
                     <target name='test'>
                        <elementTest1 uri='http://nant.sourceforge.net' />
                     </target>
                </project>";

            Project project          = CreateFilebasedProject(build);
            var     propertyAccessor = new PropertyAccessor(project, project.RootTargetCallStack);

            ExecuteProject(project);

            // uri property should be registered
            Assert.IsTrue(propertyAccessor.Contains(ElementTest1Task.UriPropertyName));
            // ensure resulting property matches expected URI
            Assert.AreEqual("http://nant.sourceforge.net/", propertyAccessor[
                                ElementTest1Task.UriPropertyName]);
        }
Ejemplo n.º 7
0
        public void Test_Uri_RelativeFilePath()
        {
            const string build = @"<?xml version='1.0' ?>
                <project name='testing' default='test'>
                     <target name='test'>
                        <elementTest1 uri='dir/test.txt' />
                     </target>
                </project>";

            Project project          = CreateFilebasedProject(build);
            var     propertyAccessor = new PropertyAccessor(project, project.RootTargetCallStack);

            ExecuteProject(project);

            Uri expectedUri = new Uri(project.GetFullPath("dir/test.txt"));

            // uri property should be registered
            Assert.IsTrue(propertyAccessor.Contains(ElementTest1Task.UriPropertyName));
            // path should have been resolved to absolute path (in project dir)
            Assert.AreEqual(expectedUri.ToString(), propertyAccessor[
                                ElementTest1Task.UriPropertyName]);
        }