예제 #1
0
        public void ProjectUsingTaskElementModify()
        {
            var pair          = GetNewInMemoryProject("temp.prj");
            var xmlPair       = new ProjectXmlPair(pair);
            var usingTaskFile = xmlPair.AddNewChaildWithVerify <ProjectUsingTaskElement>(ObjectType.View, "NewUsingTask", (p, n) => p.AddUsingTask(n, "assemblyFile", null), (ut, n) => true);

            usingTaskFile.VerifySetter("newArgch", (ut) => ut.Architecture, (ut, v) => ut.Architecture     = v);
            usingTaskFile.VerifySetter("newTaskFactory", (ut) => ut.TaskFactory, (ut, v) => ut.TaskFactory = v);
            usingTaskFile.VerifySetter("newTaskName", (ut) => ut.TaskName, (ut, v) => ut.TaskName          = v);
            // this was double rename - validate overal integrity.
            usingTaskFile.VerifySame(xmlPair.QuerySingleChildrenWithValidation <ProjectUsingTaskElement>((ut) => true));
            usingTaskFile.VerifySetter("newAssemblyPath", (ut) => ut.AssemblyFile, (ut, v) => ut.AssemblyFile = v);
            Assert.ThrowsAny <InvalidOperationException>(() => usingTaskFile.View.AssemblyName = "xxx");
            usingTaskFile.VerifySetter("newRuntime", (ut) => ut.Runtime, (ut, v) => ut.Runtime = v);

            Assert.Null(usingTaskFile.View.TaskBody);
            var body = usingTaskFile.AddNewChaildWithVerify <ProjectUsingTaskBodyElement>(ObjectType.View, "eval", (ut, e) => ut.AddUsingTaskBody(e, "body"), (ut, e) => true);

            Assert.Same(body.View, usingTaskFile.View.TaskBody);
            Assert.Same(body.Real, usingTaskFile.Real.TaskBody);

            Assert.Null(usingTaskFile.View.ParameterGroup);
            var pg = usingTaskFile.AddNewChaildWithVerify <UsingTaskParameterGroupElement>(ObjectType.View, "pg", (ut, e) => ut.AddParameterGroup(), (ut, e) => true);

            Assert.Same(pg.View, usingTaskFile.View.ParameterGroup);
            Assert.Same(pg.Real, usingTaskFile.Real.ParameterGroup);


            xmlPair.View.RemoveChild(usingTaskFile.View);

            var usingTaskName = xmlPair.AddNewChaildWithVerify <ProjectUsingTaskElement>(ObjectType.View, "NewUsingTask", (p, n) => p.AddUsingTask(n, null, "assemblyName"), (ut, n) => true);

            usingTaskName.VerifySetter("newAssemblyName", (ut) => ut.AssemblyName, (ut, v) => ut.AssemblyName = v);
            Assert.ThrowsAny <InvalidOperationException>(() => usingTaskName.View.AssemblyFile = "xxx");
        }
예제 #2
0
        private void CloneAndAddInternal(ProjectRootElement sourceProject)
        {
            bool externalSource = sourceProject != null;

            var projectPair = GetNewInMemoryProject("Clone", TestCollectionGroup.BigProjectFile);
            var xmlPair     = new ProjectXmlPair(projectPair);

            Assert.True(xmlPair.View.HasUnsavedChanges);
            xmlPair.View.Save();
            Assert.False(xmlPair.View.HasUnsavedChanges);

            sourceProject = sourceProject ?? xmlPair.View;


            // var existingItemGroup1 = sourceProject.QuerySingleChildrenWithValidation<ProjectItemGroupElement>((ig) => ig.Label == "Group1");
            var existingItemGroupList = sourceProject.AllChildren.OfType <ProjectItemGroupElement>().Where(((ig) => ig.Label == "Group1")).ToList();

            Assert.Single(existingItemGroupList);
            var existingItemGroup = existingItemGroupList[0];

            var cloned = (ProjectItemGroupElement)existingItemGroup.Clone();

            Assert.NotSame(cloned, existingItemGroup);
            Assert.False(sourceProject.HasUnsavedChanges);

            var sourceIsALink = ViewValidation.IsLinkedObject(sourceProject);

            ViewValidation.VerifyNotNull(cloned, sourceIsALink);


            if (externalSource)
            {
                Assert.ThrowsAny <InvalidOperationException>(() => xmlPair.View.AppendChild(cloned));
            }
            else
            {
                var clonedPair = xmlPair.CreateFromView(cloned);
                xmlPair.QueryChildrenWithValidation <ProjectItemGroupElement>((ig) => ig == cloned || ig == clonedPair.Real, 0);

                xmlPair.View.AppendChild(cloned);
                Assert.True(xmlPair.View.HasUnsavedChanges);
                Assert.True(xmlPair.Real.HasUnsavedChanges);

                clonedPair.VerifySame(xmlPair.QuerySingleChildrenWithValidation <ProjectItemGroupElement>((ig) => ig == clonedPair.View || ig == clonedPair.Real));
                xmlPair.QueryChildrenWithValidation <ProjectItemGroupElement>((ig) => ig.Label == "Group1", 2);

                clonedPair.VerifySetter("Group2", (g) => g.Label, (g, v) => g.Label = v);
                xmlPair.Verify();

                Assert.Equal("Group1", existingItemGroup.Label);
            }
        }
예제 #3
0
        public void ProjectChooseElementModify()
        {
            var pair    = GetNewInMemoryProject("temp.prj");
            var xmlPair = new ProjectXmlPair(pair);

            // slightly more verbose to validate some Create/Append intended semantic.
            var chooseCreataed = xmlPair.CreateWithVerify <ProjectChooseElement>((p) => p.CreateChooseElement());

            xmlPair.QueryChildrenWithValidation <ProjectChooseElement>((pc) => true, 0);

            xmlPair.View.AppendChild(chooseCreataed.View);
            var choose = xmlPair.QuerySingleChildrenWithValidation <ProjectChooseElement>((pc) => true);

            Assert.Same(choose.View, chooseCreataed.View);
            // "real" must be different, the chooseCreated real is the same remote object as the View, and chooseReal is just the second created element
            // we did for validation.
            Assert.NotSame(choose.Real, chooseCreataed.Real);

            Assert.ThrowsAny <InvalidOperationException>(() => choose.View.Condition = "ccc");

            Assert.Empty(choose.View.WhenElements);
            choose.Append2NewLabeledChildrenWithVerify <ProjectWhenElement>("when", (p, l) => p.CreateWhenElement($"'$(c)' == '{l}'"), out var when1, out var when2);
            Assert.Equal(2, choose.View.WhenElements.Count);
            when1.VerifySame(choose.QuerySingleChildrenWithValidation <ProjectWhenElement>((ch) => ch.Label == when1.View.Label));
            when2.VerifySame(choose.QuerySingleChildrenWithValidation <ProjectWhenElement>((ch) => ch.Label == when2.View.Label));

            Assert.Null(choose.View.OtherwiseElement);

            var otherWise = choose.AppendNewChaildWithVerify <ProjectOtherwiseElement>(ObjectType.View, "when", (p, l) => p.CreateOtherwiseElement(), (p, l) => true);

            Assert.Same(otherWise.View, choose.View.OtherwiseElement);
            Assert.Same(otherWise.Real, choose.Real.OtherwiseElement);

            choose.Verify();

            choose.View.RemoveChild(when2.View);
            Assert.Equal(1, choose.View.WhenElements.Count);
            when1.VerifySame(choose.QuerySingleChildrenWithValidation <ProjectWhenElement>((ch) => ch.Label == when1.View.Label));

            choose.View.RemoveChild(otherWise.View);
            Assert.Null(choose.View.OtherwiseElement);
            choose.Verify();
        }
예제 #4
0
        public void ProjectTargetElementModify()
        {
            var pair    = GetNewInMemoryProject("temp.prj");
            var xmlPair = new ProjectXmlPair(pair);

            // create new target
            const string NewTargetName = "NewTargetName";
            var          newTarget1    = xmlPair.AddNewChaildWithVerify <ProjectTargetElement>(ObjectType.View, NewTargetName, (p, n) => p.AddTarget(n), (t, n) => string.Equals(t.Name, n));

            // add tasks to target
            const string NewTaskName = "NewTaskName";

            newTarget1.Add2NewNamedChildrenWithVerify <ProjectTaskElement>(NewTaskName, (t, n) => t.AddTask(n), out var newTask1, out var newTask2);

            // Add item groups
            const string NewTargetItemGroup = "NewTargetItemGroup";

            newTarget1.Add2NewLabeledChildrenWithVerify <ProjectItemGroupElement>(NewTargetItemGroup, (t, l) => t.AddItemGroup(), out var newItemGroup1, out var newItemGroup2);

            // Add property groups
            const string NewPropertyGroup = "NewPropertyGroup";

            newTarget1.Add2NewLabeledChildrenWithVerify <ProjectPropertyGroupElement>(NewPropertyGroup, (t, l) => t.AddPropertyGroup(), out var newPropertyGroup1, out var newPropertyGroup2);

            // Add property groups
            newTarget1.Append2NewChildrenWithVerify <ProjectOnErrorElement>("errTarget", (p, et) => p.CreateOnErrorElement(et), (oe, et) => oe.ExecuteTargetsAttribute == et, out var newOnErr1, out var newOnErr2);


            // string setters
            newTarget1.VerifySetter("newBeforeTargets", (t) => t.BeforeTargets, (t, v) => t.BeforeTargets          = v);
            newTarget1.VerifySetter("newDependsOnTargets", (t) => t.DependsOnTargets, (t, v) => t.DependsOnTargets = v);
            newTarget1.VerifySetter("newAfterTargets", (t) => t.AfterTargets, (t, v) => t.AfterTargets             = v);
            newTarget1.VerifySetter("newReturns", (t) => t.Returns, (t, v) => t.Returns = v);
            newTarget1.VerifySetter("newInputs", (t) => t.Inputs, (t, v) => t.Inputs    = v);
            newTarget1.VerifySetter("newOutputs", (t) => t.Outputs, (t, v) => t.Outputs = v);
            newTarget1.VerifySetter("newKeepDuplicateOutputs", (t) => t.KeepDuplicateOutputs, (t, v) => t.KeepDuplicateOutputs = v);


            newTarget1.VerifySetter("'Configuration' == 'Foo'", (t) => t.Condition, (t, v) => t.Condition = v);
            newTarget1.VerifySetter("newLabel", (t) => t.Label, (t, v) => t.Label = v);

            // rename target. First validate we do not change identity of the view
            const string NewTargetRenamed = "NewTargetRenamed";

            newTarget1.View.Name = NewTargetRenamed;
            Assert.Empty(xmlPair.QueryChildrenWithValidation <ProjectTargetElement>((t) => string.Equals(t.Name, NewTargetName)));
            newTarget1.VerifySame(xmlPair.QuerySingleChildrenWithValidation <ProjectTargetElement>((t) => string.Equals(t.Name, NewTargetRenamed)));

            newTarget1.Real.Name = NewTargetRenamed.Ver(2);
            Assert.Empty(xmlPair.QueryChildrenWithValidation <ProjectTargetElement>((t) => string.Equals(t.Name, NewTargetRenamed)));
            Assert.Empty(xmlPair.QueryChildrenWithValidation <ProjectTargetElement>((t) => string.Equals(t.Name, NewTargetName)));

            newTarget1.VerifySame(xmlPair.QuerySingleChildrenWithValidation <ProjectTargetElement>((t) => string.Equals(t.Name, NewTargetRenamed.Ver(2))));

            // this will rename back, as well as check the reqular way (after we confirmed the view identity dont change on rename).
            newTarget1.VerifySetter(NewTargetName, (t) => t.Name, (t, v) => t.Name = v);


            // removes
            newTarget1.View.RemoveChild(newTask2.View);
            Assert.ThrowsAny <ArgumentException>(() => newTarget1.Real.RemoveChild(newTask2.Real));
            Assert.Equal(1, newTarget1.View.Tasks.Count);
            newTarget1.Real.RemoveChild(newTask1.Real);
            Assert.ThrowsAny <ArgumentException>(() => newTarget1.View.RemoveChild(newTask1.View));
            Assert.Empty(newTarget1.View.Tasks);

            Assert.NotEmpty(newTarget1.View.ItemGroups);
            Assert.NotEmpty(newTarget1.View.PropertyGroups);
            newTarget1.View.RemoveAllChildren();

            Assert.Empty(newTarget1.View.ItemGroups);
            Assert.Empty(newTarget1.View.PropertyGroups);


            newTarget1.Verify();
        }
예제 #5
0
        private void CopyFromInternal(ProjectRootElement sourceProject)
        {
            // quite a few complexity in the ExternalProjectProvider implementation is because of
            // ProjectElement.CopyFrom and ProjectElementContainer.DeepCopyFrom....

            bool externalSource = sourceProject != null;

            var projectPair = GetNewInMemoryProject("CopyFrom", TestCollectionGroup.BigProjectFile);
            var xmlPair     = new ProjectXmlPair(projectPair);

            Assert.True(xmlPair.View.HasUnsavedChanges);
            xmlPair.View.Save();
            Assert.False(xmlPair.View.HasUnsavedChanges);

            sourceProject = sourceProject ?? xmlPair.View;

            var existingItemGroupList = sourceProject.AllChildren.OfType <ProjectItemGroupElement>().Where(((ig) => ig.Label == "Group1")).ToList();

            Assert.Single(existingItemGroupList);
            var existingItemGroup = existingItemGroupList[0];

            Assert.NotNull(existingItemGroup);
            var realExistingItemGroup = ViewValidation.GetRealObject(existingItemGroup);

            var ourGroup1 = xmlPair.QuerySingleChildrenWithValidation <ProjectItemGroupElement>((ig) => ig.Label == "Group1");

            var newCopyFrom = xmlPair.AddNewLabeledChaildWithVerify <ProjectItemGroupElement>(ObjectType.View, "newGrop", (p, l) => p.AddItemGroup());

            newCopyFrom.View.CopyFrom(existingItemGroup);
            xmlPair.QueryChildrenWithValidation <ProjectItemGroupElement>((ig) => ig.Label == "Group1", 2);
            newCopyFrom.View.Label = "CopyFrom";
            newCopyFrom.VerifySame(xmlPair.QuerySingleChildrenWithValidation <ProjectItemGroupElement>((ig) => ig.Label == "CopyFrom"));
            ourGroup1.VerifySame(xmlPair.QuerySingleChildrenWithValidation <ProjectItemGroupElement>((ig) => ig.Label == "Group1"));
            // children are not copied.
            Assert.Empty(newCopyFrom.View.Items);
            // but attributes are (even non standard)
            //Assert.Equal("2", ProjectElementLink.GetAttributeValue(existingItemGroup, "FunnyAttribute", true));
            //Assert.Equal("2", ProjectElementLink.GetAttributeValue(newCopyFrom.View, "FunnyAttribute", true));
            newCopyFrom.VerifyNotSame(ourGroup1);


            Assert.True(xmlPair.View.HasUnsavedChanges);
            Assert.False(externalSource && sourceProject.HasUnsavedChanges);

            var newDeepCopy = xmlPair.AddNewLabeledChaildWithVerify <ProjectItemGroupElement>(ObjectType.View, "newGrop", (p, l) => p.AddItemGroup());

            newDeepCopy.View.DeepCopyFrom(existingItemGroup);

            xmlPair.QueryChildrenWithValidation <ProjectItemGroupElement>((ig) => ig.Label == "Group1", 2);
            // slightly cheting but we know that the large groups should be the same, even though there are not the same object
            // note do that before changing the label.
            Assert.NotSame(realExistingItemGroup, newDeepCopy.Real);
            // TODO XmlLocation is (correctly) different for the items, need to find a way to bypass it.
            var context = new ValidationContext();

            context.ValidateLocation = delegate(ElementLocation a, ElementLocation e) { return; };

            ViewValidation.Verify(newDeepCopy.View, realExistingItemGroup, context);
            newDeepCopy.View.Label = "DeepCopyFrom";
            newDeepCopy.VerifySame(xmlPair.QuerySingleChildrenWithValidation <ProjectItemGroupElement>((ig) => ig.Label == "DeepCopyFrom"));
            ourGroup1.VerifySame(xmlPair.QuerySingleChildrenWithValidation <ProjectItemGroupElement>((ig) => ig.Label == "Group1"));
            newDeepCopy.VerifyNotSame(ourGroup1);

            Assert.False(externalSource && sourceProject.HasUnsavedChanges);
        }