public void MoveNodeTest() { SrmDocument document = new SrmDocument(SrmSettingsList.GetDefault()); IdentityPath path = IdentityPath.ROOT; SrmDocument docFasta = document.ImportFasta(new StringReader(ExampleText.TEXT_FASTA_YEAST), false, path, out path); // 1. From peptide group to root SrmDocument docMoved = docFasta.MoveNode(docFasta.GetPathTo(0), IdentityPath.ROOT, out path); Assert.AreEqual(1, docMoved.FindNodeIndex(path)); Assert.AreSame(docFasta.Children[0], docMoved.Children[1]); Assert.AreSame(docFasta.Children[1], docMoved.Children[0]); // 2. From peptide group to before other peptide group docMoved = docFasta.MoveNode(docFasta.GetPathTo(1), docFasta.GetPathTo(0), out path); Assert.AreEqual(0, docMoved.FindNodeIndex(path)); Assert.AreSame(docFasta.Children[0], docMoved.Children[1]); Assert.AreSame(docFasta.Children[1], docMoved.Children[0]); // Some peptide lists IdentityPath pathPeptides; SrmDocument docPeptides = docFasta.ImportFasta(new StringReader(TEXT_BOVINE_PEPTIDES2), true, docFasta.GetPathTo(1), out pathPeptides); docPeptides = docPeptides.ImportFasta(new StringReader(TEXT_BOVINE_PEPTIDES1), true, IdentityPath.ROOT, out path); docPeptides = docPeptides.MoveNode(path, pathPeptides, out pathPeptides); Assert.AreEqual(1, docPeptides.FindNodeIndex(pathPeptides)); // 3. Peptide from one group to another IdentityPath fromParent = docPeptides.GetPathTo(2); IdentityPath from = new IdentityPath(fromParent, ((DocNodeParent)docPeptides.FindNode(fromParent)).Children[0].Id); SrmDocument docPeptides2 = docPeptides.MoveNode(from, pathPeptides, out path); Assert.AreEqual(pathPeptides, path.Parent); Assert.AreEqual(((DocNodeParent)docPeptides.Children[1]).Children.Count, ((DocNodeParent)docPeptides2.Children[1]).Children.Count - 1); Assert.AreEqual(((DocNodeParent)docPeptides.Children[2]).Children.Count, ((DocNodeParent)docPeptides2.Children[2]).Children.Count + 1); // Though moved to a different group, this should not have changed the overall // peptide order, since it was moved from the beginning of one group to the end // of the group before it. Assert.AreEqual(docPeptides.FindNodeIndex(from), docPeptides2.FindNodeIndex(path)); // 4. To before another peptide from = new IdentityPath(fromParent, ((DocNodeParent)docPeptides2.FindNode(fromParent)).Children[0].Id); IdentityPath path2; SrmDocument docPeptides3 = docPeptides2.MoveNode(from, path, out path2); Assert.AreEqual(pathPeptides, path.Parent); Assert.AreEqual(((DocNodeParent)docPeptides2.Children[1]).Children.Count, ((DocNodeParent)docPeptides3.Children[1]).Children.Count - 1); Assert.AreEqual(((DocNodeParent)docPeptides2.Children[2]).Children.Count, ((DocNodeParent)docPeptides3.Children[2]).Children.Count + 1); // Relative to all peptides, index should be 1 less than before Assert.AreEqual(docPeptides2.FindNodeIndex(from), docPeptides3.FindNodeIndex(path2) + 1); // 5. To within another peptide IdentityPath to = new IdentityPath(path, ((DocNodeParent)docPeptides3.FindNode(path)).Children[0].Id); SrmDocument docPeptides4 = docPeptides3.MoveNode(path2, to, out path); // Should not have changed to count in the group Assert.AreEqual(((DocNodeParent)docPeptides3.Children[1]).Children.Count, ((DocNodeParent)docPeptides4.Children[1]).Children.Count); // Relative to all peptides, should have been returned to original order Assert.AreEqual(docPeptides2.FindNodeIndex(from), docPeptides4.FindNodeIndex(path)); // Make sure expected exceptions are thrown Assert.IsNull(docPeptides4.FindNode(from)); AssertEx.ThrowsException <IdentityNotFoundException>(() => docPeptides4.MoveNode(from, to, out path)); AssertEx.ThrowsException <InvalidOperationException>(() => docPeptides2.MoveNode(from, docPeptides2.GetPathTo(0), out path)); AssertEx.ThrowsException <InvalidOperationException>(() => docPeptides3.MoveNode(docPeptides2.GetPathTo((int)SrmDocument.Level.Molecules, 0), to, out path)); AssertEx.ThrowsException <InvalidOperationException>(() => docPeptides3.MoveNode(docPeptides2.GetPathTo((int)SrmDocument.Level.Transitions, 0), to, out path)); }