public IEnumerable <KspPartObject> LookupParts(RegexFilter partFilter) { int id; if (int.TryParse(partFilter.Pattern, out id)) { var dependency = craft.Child <KspPartObject> (id); return(dependency != null ? new[] { dependency } : Enumerable.Empty <KspPartObject> ()); } return(partFilter.Apply(craft.Children <KspPartObject> (), part => part.Name)); }
private static KspCraftObject createTestCraft() { var craft = new KspCraftObject() .AddChild(new KspPartObject().AddProperty(new KspStringProperty("name", "part1"))) .AddChild(new KspPartObject().AddProperty(new KspStringProperty("name", "part2"))) .AddChild(new KspPartObject().AddProperty(new KspStringProperty("name", "part3"))) .AddChild(new KspPartObject().AddProperty(new KspStringProperty("name", "part4"))) .AddChild(new KspPartObject().AddProperty(new KspStringProperty("name", "part5"))) .AddChild(new KspPartObject().AddProperty(new KspStringProperty("name", "part6"))) .AddChild(new KspPartObject().AddProperty(new KspStringProperty("name", "part7"))) .AddChild(new KspPartObject().AddProperty(new KspStringProperty("name", "part8"))) .AddChild(new KspPartObject().AddProperty(new KspStringProperty("name", "part9"))) as KspCraftObject; var parts = craft.Children <KspPartObject> ().ToArray(); parts [1] .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.Parent, "", parts [2])); // parent is [2] parts [3] .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.SrfN, "srfAttach", parts [0])) // srfN to [0] .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.SrfN, "srfAttach", parts [1])); // srfN to [1] parts [4] .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.AttN, "top", null)) // attN to nirvana .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.AttN, "bottom", parts [3])); // attN to [3] parts [5] .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.Sym, "bottom", parts [1])); // sym to [1] parts [6] .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.Link, "bottom", parts [0])); // link to [0] parts [7] .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.SrfN, "srfAttach", parts [6])) // srfN to [6] .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.SrfN, "srfAttach", parts [0])); // srfN to [0] parts [8] .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.AttN, "top", parts [0])) // attN to [0] .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.AttN, "bottom", parts [7])) // attN to [7] .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.Link, "bottom", parts [1])); // link to [1] return(craft); }
public void RemovesPartsAndCorrespondingLinks() { // given var craft = new KspCraftObject() .AddChild(new KspPartObject().AddProperty(new KspStringProperty("name", "part1"))) .AddChild(new KspPartObject().AddProperty(new KspStringProperty("name", "part2"))) .AddChild(new KspPartObject().AddProperty(new KspStringProperty("name", "part3"))) .AddChild(new KspPartObject().AddProperty(new KspStringProperty("name", "part4"))) as KspCraftObject; var parts = craft.Children <KspPartObject> ().ToArray(); parts [0] .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.Link, "", parts [1])) .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.Link, "", parts [2])) .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.Link, "", parts [3])) .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.Parent, "", parts [1])) .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.Parent, "", parts [2])) .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.Parent, "", parts [3])) .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.Sym, "top", parts [1])) .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.Sym, "bottom", parts [2])) .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.Sym, "left", parts [3])) .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.SrfN, "srfAttach", parts [1])) .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.SrfN, "srfAttach", parts [2])) .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.SrfN, "srfAttach", parts [3])) .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.AttN, "left", parts [1])) .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.AttN, "bottom", parts [2])) .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.AttN, "top", parts [3])); parts [3] .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.Link, "", parts [1])) .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.Link, "", parts [2])) .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.Link, "", parts [0])) .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.Parent, "", parts [1])) .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.Parent, "", parts [2])) .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.Parent, "", parts [0])) .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.Sym, "top", parts [1])) .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.Sym, "bottom", parts [2])) .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.Sym, "left", parts [0])) .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.SrfN, "srfAttach", parts [1])) .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.SrfN, "srfAttach", parts [2])) .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.SrfN, "srfAttach", parts [0])) .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.AttN, "left", parts [1])) .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.AttN, "bottom", parts [2])) .AddProperty(new KspPartLinkProperty(KspPartLinkProperty.Types.AttN, "top", parts [0])); var partsToRemove = new[] { parts [1], parts [2] }; var expectedRemainingParts = new[] { parts [0], parts [3] }; var expectedPropertiesPart1 = new KspProperty[] { parts [0].Properties [0], parts [0].Properties [3], parts [0].Properties [6], parts [0].Properties [9], parts [0].Properties [12], parts [0].Properties [15] }; var expectedPropertiesPart2 = new KspProperty[] { parts [3].Properties [0], parts [3].Properties [3], parts [3].Properties [6], parts [3].Properties [9], parts [3].Properties [12], parts [3].Properties [15] }; // when craft.Edit().RemoveParts(partsToRemove); var remainingParts = craft.Children <KspPartObject> ().ToArray(); // then Assert.That(remainingParts, Is.EqualTo(expectedRemainingParts)); Assert.That(remainingParts [0].Properties, Is.EqualTo(expectedPropertiesPart1)); Assert.That(remainingParts [1].Properties, Is.EqualTo(expectedPropertiesPart2)); }