コード例 #1
0
        public void CanUpdatePartReferences ()
        {
            // given
            var obj = new KspObject ("OBJ")
                .AddChild (new KspPartObject ().AddProperty (new KspStringProperty ("name", "part1")))
                .AddChild (new KspPartObject ().AddProperty (new KspStringProperty ("name", "part2")))
                .AddChild (new KspPartObject ().AddProperty (new KspStringProperty ("name", "part3")));

            var parts = obj.Children<KspPartObject> ().ToArray ();

            var part = obj.Children [0]
                .AddProperty (new KspStringProperty ("not-a-link", "not-a-link"))
                .AddProperty (new KspPartLinkProperty (KspPartLinkProperty.Types.Link, "top", parts [0], false))
                .AddProperty (new KspPartLinkProperty (KspPartLinkProperty.Types.Parent, "top", parts [0], false))
                .AddProperty (new KspPartLinkProperty (KspPartLinkProperty.Types.Parent, "top", parts [1], false)) as KspPartObject;

            var newParentLink = new KspPartLinkProperty (KspPartLinkProperty.Types.Parent, "bottom", parts [1], false);

            var expectedProperties = new [] {
                part.Properties [0],
                part.Properties [1],
                part.Properties [2],
                newParentLink
            };

            // when
            part.UpdatePartLinks (KspPartLinkProperty.Types.Parent, new[] { newParentLink });

            // then
            Assert.That (part.Properties, Is.EqualTo (expectedProperties));
        }
コード例 #2
0
        public static TChild Child <TChild> (this KspObject obj, int id) where TChild : KspObject
        {
            if (id < 0)
            {
                return(null);
            }

            var children = obj.Children <TChild> ().ToList();

            return((children.Count > id) ? children [id] : null);
        }
コード例 #3
0
 public void CanFindChildrenOfAnObjectByType ()
 {
     // given
     var obj = new KspObject ("OBJ")
         .AddChild (new KspPartObject () // found
             .AddChild (new KspPartObject ())) // not found
         .AddChild (new KspObject (KspPartObject.TypeId) // not found
             .AddChild (new KspPartObject ())) // not found
         .AddChild (new KspPartObject () // found
             .AddChild (new KspObject (KspPartObject.TypeId))); // not found
     
     // when / then
     Assert.That (obj.Children<KspPartObject> (), Is.EqualTo (new[] { obj.Children [0], obj.Children [2] }));
 }
コード例 #4
0
        public void CanRetrievePartReferences ()
        {
            // given
            var obj = new KspObject ("OBJ")
                .AddChild (new KspPartObject ().AddProperty (new KspStringProperty ("name", "part1")))
                .AddChild (new KspPartObject ().AddProperty (new KspStringProperty ("name", "part2")))
                .AddChild (new KspPartObject ().AddProperty (new KspStringProperty ("name", "part3")));

            var parts = obj.Children<KspPartObject> ().ToArray ();

            var part = obj.Children [0]
                .AddProperty (new KspStringProperty ("not-a-link", "not-a-link"))
                .AddProperty (new KspPartLinkProperty (KspPartLinkProperty.Types.Link, "top", parts [0], false))
                .AddProperty (new KspPartLinkProperty (KspPartLinkProperty.Types.Parent, "top", parts [0], false))
                .AddProperty (new KspPartLinkProperty (KspPartLinkProperty.Types.Parent, "top", parts [1], false)) as KspPartObject;
            
            // when / then
            Assert.That (part.PartLinks (KspPartLinkProperty.Types.Parent), Is.EqualTo (new[] { part.Properties [3], part.Properties [4] }));
        }
コード例 #5
0
        public static int IdOfChild <TChild> (this KspObject obj, TChild child) where TChild : KspObject
        {
            var children = obj.Children <TChild> ().ToList();

            return(children.IndexOf(child));
        }