public void AquireAndReleaseDoesNotThrowOnEmptyCollection()
        {
            var logicalChildSupportStub = new LogicalChildSupportNoFEStub();
            var collection = new ItemCollectionWithLogicalTreeSupport <object>(logicalChildSupportStub);

            Assert.That(() => collection.AquireLogicalOwnership(), Throws.Nothing);
            Assert.That(() => collection.ReleaseLogicalOwnership(), Throws.Nothing);
        }
        public void CollectionOperationsWorkAsExpected()
        {
            var logicalChildSupportStub = new LogicalChildSupportNoFEStub();
            var collection = new ItemCollectionWithLogicalTreeSupport <object>(logicalChildSupportStub);

            var item1 = "Item_1";
            var item2 = "Item_2";
            var item3 = "Item_3";

            // add items
            {
                collection.Add(item1);
                collection.Add(item2);
                collection.Add(item3);
            }

            Assert.That(collection.GetLogicalChildren(), Is.EquivalentTo(collection));

            collection.Clear();

            Assert.That(collection, Is.Empty);
            Assert.That(collection.GetLogicalChildren(), Is.EquivalentTo(collection));

            // add items
            {
                collection.Add(item1);
                collection.Add(item2);
                collection.Add(item3);
            }

            collection.RemoveAt(1);

            Assert.That(collection, Is.EquivalentTo(new[] { item1, item3 }));
            Assert.That(logicalChildSupportStub.LogicalChildren, Is.EquivalentTo(collection));
            Assert.That(collection.GetLogicalChildren(), Is.EquivalentTo(collection));

            collection[1] = item2;

            Assert.That(collection, Is.EquivalentTo(new[] { item1, item2 }));
            Assert.That(logicalChildSupportStub.LogicalChildren, Is.EquivalentTo(collection));
            Assert.That(collection.GetLogicalChildren(), Is.EquivalentTo(collection));

            collection.Insert(0, item3);

            Assert.That(collection, Is.EquivalentTo(new[] { item3, item1, item2 }));
            Assert.That(logicalChildSupportStub.LogicalChildren, Is.EquivalentTo(collection));
            Assert.That(collection.GetLogicalChildren(), Is.EquivalentTo(collection));

            collection.ReleaseLogicalOwnership();

            Assert.That(collection, Is.EquivalentTo(new[] { item3, item1, item2 }));
            Assert.That(logicalChildSupportStub.LogicalChildren, Is.Empty);
            Assert.That(collection.GetLogicalChildren(), Is.Empty);

            Assert.That(() => collection.ReleaseLogicalOwnership(), Throws.Nothing);

            Assert.That(logicalChildSupportStub.LogicalChildren, Is.Empty);
            Assert.That(collection.GetLogicalChildren(), Is.Empty);

            var item4 = "Item_4";

            collection.Add(item4);

            Assert.That(collection, Is.EquivalentTo(new[] { item3, item1, item2, item4 }));
            Assert.That(logicalChildSupportStub.LogicalChildren, Is.Empty);
            Assert.That(collection.GetLogicalChildren(), Is.Empty);

            collection.AquireLogicalOwnership();

            Assert.That(collection, Is.EquivalentTo(new[] { item3, item1, item2, item4 }));
            Assert.That(logicalChildSupportStub.LogicalChildren, Is.EquivalentTo(collection));
            Assert.That(collection.GetLogicalChildren(), Is.EquivalentTo(collection));

            Assert.That(() => collection.AquireLogicalOwnership(), Throws.Nothing);

            Assert.That(logicalChildSupportStub.LogicalChildren, Is.EquivalentTo(collection));
            Assert.That(collection.GetLogicalChildren(), Is.EquivalentTo(collection));

            collection.ReleaseLogicalOwnership();

            collection.Remove(item4);

            Assert.That(collection, Is.EquivalentTo(new[] { item3, item1, item2 }));
            Assert.That(logicalChildSupportStub.LogicalChildren, Is.Empty);
            Assert.That(collection.GetLogicalChildren(), Is.Empty);
        }