示例#1
0
        public void NotifyAddRemoveTest()
        {
            var a = new BoundedObjectWithParentList(new Vector2(0, 0), new Vector2(15, 15));
            var b = new BoundedObjectWithParentList(new Vector2(8, 8), new Vector2(23, 23));

            Assert.AreEqual(0, a.Parents.Count);
            Assert.AreEqual(0, b.Parents.Count);

            Collection.Add(a);
            Collection.Add(b);

            Assert.AreEqual(1, a.Parents.Count);
            Assert.AreEqual(1, b.Parents.Count);

            Assert.AreEqual(Collection, a.Parents[0].Target);
            Assert.AreEqual(Collection, b.Parents[0].Target);

            Collection.Remove(a);

            Assert.AreEqual(0, a.Parents.Count);
            Assert.AreEqual(1, b.Parents.Count);

            Collection.Remove(b);

            Assert.AreEqual(0, a.Parents.Count);
            Assert.AreEqual(0, b.Parents.Count);
        }
示例#2
0
        public void UpdateItemBoundsDoesNotCallAddRemoveNotificationMethods()
        {
            var c2 = new SpatialCollection <BoundedObject>();
            var c3 = new SpatialCollection <BoundedObject>();
            var a  = new BoundedObjectWithParentList(new Vector2(0, 0), new Vector2(15, 15));

            Collection.Add(a);
            c2.Add(a);
            c3.Add(a);

            a.Bounds = a.Bounds.Translate(Vector2.One * 128f);

            foreach (var collection in a.Parents)
            {
                var strongCollection = (SpatialCollection <BoundedObject>)collection.Target;
                strongCollection.UpdateItemBounds(a);
            }
        }
示例#3
0
        public void ClearNotifiesRemovalTest()
        {
            var a = new BoundedObjectWithParentList(new Vector2(0, 0), new Vector2(15, 15));
            var b = new BoundedObjectWithParentList(new Vector2(8, 8), new Vector2(23, 23));

            Assert.AreEqual(0, a.Parents.Count);
            Assert.AreEqual(0, b.Parents.Count);

            Collection.Add(a);
            Collection.Add(b);

            Assert.AreEqual(1, a.Parents.Count);
            Assert.AreEqual(1, b.Parents.Count);

            Collection.Clear();

            Assert.AreEqual(0, a.Parents.Count);
            Assert.AreEqual(0, b.Parents.Count);
        }