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); } }