public async Task NatvisCollectionEntityIsNotValidWhenAtLeastOneChildIsInvalidAsync()
        {
            INatvisEntity natvisCollection = CreateNatvisCollection(
                TestNatvisEntity.Create().Valid(true), TestNatvisEntity.Create().Valid(false));

            Assert.That(await natvisCollection.IsValidAsync(), Is.False);
        }
        public async Task NatvisCollectionEntityIsValidWhenAllChildrenAreValidAsync()
        {
            INatvisEntity natvisCollection = CreateNatvisCollection(
                TestNatvisEntity.Create().Valid(true), TestNatvisEntity.Create().Valid(true));

            Assert.That(await natvisCollection.IsValidAsync(), Is.True);
        }
            GetChildrenReturnsEmptyListWhenRequestedRangeDoesNotIntersectWithChildrenAsync()
        {
            INatvisEntity natvisCollection = CreateNatvisCollectionWithHiddenRawView(
                TestNatvisEntity.Create().WithCount(1), TestNatvisEntity.Create().WithCount(2));

            IList<IVariableInformation> children = await natvisCollection.GetChildrenAsync(3, 1);
            Assert.That(children.Count, Is.EqualTo(0));
        }
        public async Task LimitsCountToMaxChildrenCountAllowedWhenRangeIsWithOffsetAsync()
        {
            const int maxChildren  = 2;
            var       rangedEntity = RangedNatvisEntityDecorator.StartFrom(
                6, maxChildren, TestNatvisEntity.Create().WithCount(10));

            Assert.That(await rangedEntity.CountChildrenAsync(), Is.EqualTo(maxChildren + 1));
        }
        public async Task CountIsEqualToSumOfChildrenCountsPlusRawAsync()
        {
            INatvisEntity natvisCollection = CreateNatvisCollection(
                TestNatvisEntity.Create().WithCount(2), TestNatvisEntity.Create().WithCount(3));

            int count = await natvisCollection.CountChildrenAsync();
            Assert.That(count, Is.EqualTo(6));
        }
        public async Task CountIsEqualToSumOfChildrenCountsWhenRawViewIsHiddenAsync()
        {
            INatvisEntity natvisCollection = CreateNatvisCollectionWithHiddenRawView(
                TestNatvisEntity.Create().WithCount(2), TestNatvisEntity.Create().WithCount(3));

            int count = await natvisCollection.CountChildrenAsync();
            Assert.That(count, Is.EqualTo(5));
        }
        public async Task ReturnsChildrenCountForCurrentRangeAsync()
        {
            const int maxChildren  = 100;
            var       rangedEntity = RangedNatvisEntityDecorator.StartFrom(
                6, maxChildren, TestNatvisEntity.Create().WithCount(10));

            Assert.That(await rangedEntity.CountChildrenAsync(), Is.EqualTo(4));
        }
        public async Task DelegatesChildrenCountingToWrappedEntityAsync()
        {
            const int maxChildren  = 100;
            var       rangedEntity =
                RangedNatvisEntityDecorator.First(maxChildren,
                                                  TestNatvisEntity.Create().WithCount(5));

            Assert.That(await rangedEntity.CountChildrenAsync(), Is.EqualTo(5));
        }
        public async Task LimitsCountToMaxChildrenCountAllowedPlusOneForMoreAsync()
        {
            const int maxChildren  = 2;
            var       rangedEntity =
                RangedNatvisEntityDecorator.First(maxChildren,
                                                  TestNatvisEntity.Create().WithCount(5));

            Assert.That(await rangedEntity.CountChildrenAsync(), Is.EqualTo(maxChildren + 1));
        }
        public async Task GetChildrenDoesNotIncludeRawViewWhenAskedToHideAsync()
        {
            INatvisEntity natvisCollection =
                CreateNatvisCollectionWithHiddenRawView(TestNatvisEntity.Create().WithCount(2));

            IList<IVariableInformation> children = await natvisCollection.GetChildrenAsync(0, 3);
            Assert.That(children.Count, Is.EqualTo(2));
            Assert.That(await children[0].ValueAsync(), Is.EqualTo("0"));
            Assert.That(await children[1].ValueAsync(), Is.EqualTo("1"));
        }
        public async Task GetChildrenIncludesRawViewWhenErrorEvenWhenAskedToHideRawViewAsync()
        {
            INatvisEntity natvisCollection =
                CreateNatvisCollectionWithHiddenRawView(
                    TestNatvisEntity.Create().WithCount(1).Valid(false));

            IList<IVariableInformation> children = await natvisCollection.GetChildrenAsync(0, 2);
            Assert.That(children.Count, Is.EqualTo(2));
            Assert.That(children[1].GetType(), Is.EqualTo(typeof(RawChildVariableInformation)));
        }
        public async Task GetChildrenReturnsMaxNumberOfElementsIfMoreRequestedAsync()
        {
            INatvisEntity natvisCollection =
                CreateNatvisCollectionWithHiddenRawView(TestNatvisEntity.Create().WithCount(2));

            IList<IVariableInformation> children = await natvisCollection.GetChildrenAsync(0, 5);
            Assert.That(children.Count, Is.EqualTo(2));
            Assert.That(await children[0].ValueAsync(), Is.EqualTo("0"));
            Assert.That(await children[1].ValueAsync(), Is.EqualTo("1"));
        }
        public async Task GetChildrenIsShiftedWhenOffsetSpecifiedAsync()
        {
            INatvisEntity natvisCollection =
                CreateNatvisCollection(TestNatvisEntity.Create().WithCount(3));

            IList<IVariableInformation> children = await natvisCollection.GetChildrenAsync(1, 2);
            Assert.That(children.Count, Is.EqualTo(2));
            Assert.That(await children[0].ValueAsync(), Is.EqualTo("1"));
            Assert.That(await children[1].ValueAsync(), Is.EqualTo("2"));
        }
        public async Task GetChildrenStartsFromTheFirstChildAsync()
        {
            INatvisEntity natvisCollection =
                CreateNatvisCollection(TestNatvisEntity.Create().WithCount(3));

            IList<IVariableInformation> children = await natvisCollection.GetChildrenAsync(0, 2);
            Assert.That(children.Count, Is.EqualTo(2));
            Assert.That(await children[0].ValueAsync(), Is.EqualTo("0"));
            Assert.That(await children[1].ValueAsync(), Is.EqualTo("1"));
        }
        public async Task GetChildrenCombinesElementFromChildrenAsync()
        {
            INatvisEntity natvisCollection = CreateNatvisCollection(
                TestNatvisEntity.Create().WithCount(1).WithId(1),
                TestNatvisEntity.Create().WithCount(1).WithId(2));

            IList<IVariableInformation> children = await natvisCollection.GetChildrenAsync(0, 2);
            Assert.That(children.Count, Is.EqualTo(2));
            Assert.That(await children[0].ValueAsync(), Is.EqualTo("1_0"));
            Assert.That(await children[1].ValueAsync(), Is.EqualTo("2_0"));
        }
        public async Task GetChildrenSkipsFirstChildIfOffsetIsMoreThanChildSizeAsync()
        {
            INatvisEntity natvisCollection = CreateNatvisCollection(
                TestNatvisEntity.Create().WithCount(1).WithId(1),
                TestNatvisEntity.Create().WithCount(2).WithId(2));

            IList<IVariableInformation> children = await natvisCollection.GetChildrenAsync(1, 2);
            Assert.That(children.Count, Is.EqualTo(2));
            Assert.That(await children[0].ValueAsync(), Is.EqualTo("2_0"));
            Assert.That(await children[1].ValueAsync(), Is.EqualTo("2_1"));
        }
        public async Task GetChildrenCalculatesOffsetForTheSecondChildAsync()
        {
            INatvisEntity natvisCollection = CreateNatvisCollection(
                TestNatvisEntity.Create().WithCount(2).WithId(1),
                TestNatvisEntity.Create().WithCount(5).WithId(2));

            IList<IVariableInformation> children = await natvisCollection.GetChildrenAsync(4, 2);
            Assert.That(children.Count, Is.EqualTo(2));
            Assert.That(await children[0].ValueAsync(), Is.EqualTo("2_2"));
            Assert.That(await children[1].ValueAsync(), Is.EqualTo("2_3"));
        }
        public async Task GetChildrenIncludesRawViewAsync()
        {
            INatvisEntity natvisCollection =
                CreateNatvisCollection(TestNatvisEntity.Create().WithCount(2));

            IList<IVariableInformation> children = await natvisCollection.GetChildrenAsync(0, 3);
            Assert.That(children.Count, Is.EqualTo(3));
            Assert.That(await children[0].ValueAsync(), Is.EqualTo("0"));
            Assert.That(await children[1].ValueAsync(), Is.EqualTo("1"));
            Assert.That(children[2].GetType(), Is.EqualTo(typeof(RawChildVariableInformation)));
        }
        public async Task SetChildrenLimitForWrappedEntityBeforeCountAsync()
        {
            const int maxChildren  = 100;
            var       entity       = TestNatvisEntity.Create();
            var       rangedEntity = RangedNatvisEntityDecorator.First(maxChildren, entity);

            Assert.That(entity.ChildrenLimit, Is.EqualTo(0));
            await rangedEntity.CountChildrenAsync();

            Assert.That(entity.ChildrenLimit, Is.EqualTo(maxChildren + 1));
        }
        public async Task ReturnsEmptyListIfRequestedRangeIsNotPresentAsync()
        {
            const int maxChildren  = 2;
            var       rangedEntity =
                RangedNatvisEntityDecorator.First(maxChildren,
                                                  TestNatvisEntity.Create().WithCount(10));

            IList <IVariableInformation> children = await rangedEntity.GetChildrenAsync(7, 2);

            Assert.That(children.Count, Is.EqualTo(0));
        }
        public async Task DoesNotAddMoreElementIfItIsNotInRangeWithOffsetAsync()
        {
            const int maxChildren  = 2;
            var       rangedEntity = RangedNatvisEntityDecorator.StartFrom(
                6, maxChildren, TestNatvisEntity.Create().WithCount(10));

            IList <IVariableInformation> children = await rangedEntity.GetChildrenAsync(0, 2);

            Assert.That(children.Count, Is.EqualTo(2));
            Assert.That(await children[0].ValueAsync(), Is.EqualTo("6"));
            Assert.That(await children[1].ValueAsync(), Is.EqualTo("7"));
        }
        public async Task DelegatesGettingChildrenToWrappedEntityAsync()
        {
            const int maxChildren  = 100;
            var       rangedEntity =
                RangedNatvisEntityDecorator.First(maxChildren,
                                                  TestNatvisEntity.Create().WithCount(10));

            IList <IVariableInformation> children = await rangedEntity.GetChildrenAsync(0, 2);

            Assert.That(children.Count, Is.EqualTo(2));
            Assert.That(await children[0].ValueAsync(), Is.EqualTo("0"));
            Assert.That(await children[1].ValueAsync(), Is.EqualTo("1"));
        }
        public async Task AddsMoreElementIfItIsInRangeWhenOnlyUpperPartRequestedAsync()
        {
            const int maxChildren  = 5;
            var       rangedEntity =
                RangedNatvisEntityDecorator.First(maxChildren,
                                                  TestNatvisEntity.Create().WithCount(10));

            IList <IVariableInformation> children = await rangedEntity.GetChildrenAsync(4, 2);

            Assert.That(children.Count, Is.EqualTo(2));
            Assert.That(await children[0].ValueAsync(), Is.EqualTo("4"));
            Assert.That(children[1].DisplayName, Is.EqualTo("[More]"));
        }
        public async Task ReturnsAllChildrenIfLessThanMaxIfRequestedMoreAsync()
        {
            const int maxChildren  = 100;
            var       rangedEntity =
                RangedNatvisEntityDecorator.First(maxChildren,
                                                  TestNatvisEntity.Create().WithCount(2));

            IList <IVariableInformation> children = await rangedEntity.GetChildrenAsync(0, 5);

            Assert.That(children.Count, Is.EqualTo(2));
            Assert.That(await children[0].ValueAsync(), Is.EqualTo("0"));
            Assert.That(await children[1].ValueAsync(), Is.EqualTo("1"));
        }
        public async Task DoesNotAddMoreElementIfAllElementsFitAsync()
        {
            const int maxChildren  = 2;
            var       rangedEntity =
                RangedNatvisEntityDecorator.First(maxChildren,
                                                  TestNatvisEntity.Create().WithCount(2));

            IList <IVariableInformation> children = await rangedEntity.GetChildrenAsync(0, 2);

            Assert.That(children.Count, Is.EqualTo(2));
            Assert.That(await children[0].ValueAsync(), Is.EqualTo("0"));
            Assert.That(await children[1].ValueAsync(), Is.EqualTo("1"));
        }
        public async Task GetChildrenCombinesChildrenWhenMoreThanTwoAsync()
        {
            INatvisEntity natvisCollection = CreateNatvisCollection(
                TestNatvisEntity.Create().WithCount(3).WithId(1),
                TestNatvisEntity.Create().WithCount(3).WithId(2),
                TestNatvisEntity.Create().WithCount(3).WithId(3));

            IList<IVariableInformation> children = await natvisCollection.GetChildrenAsync(4, 4);
            Assert.That(children.Count, Is.EqualTo(4));
            Assert.That(await children[0].ValueAsync(), Is.EqualTo("2_1"));
            Assert.That(await children[1].ValueAsync(), Is.EqualTo("2_2"));
            Assert.That(await children[2].ValueAsync(), Is.EqualTo("3_0"));
            Assert.That(await children[3].ValueAsync(), Is.EqualTo("3_1"));
        }
        public async Task DelegatesIsValidToWrappedEntityAsync()
        {
            const int maxChildren       = 100;
            var       validRangedEntity =
                RangedNatvisEntityDecorator.First(maxChildren,
                                                  TestNatvisEntity.Create().Valid(true));

            var invalidRangedEntity =
                RangedNatvisEntityDecorator.First(maxChildren,
                                                  TestNatvisEntity.Create().Valid(false));

            Assert.That(await validRangedEntity.IsValidAsync(), Is.True);
            Assert.That(await invalidRangedEntity.IsValidAsync(), Is.False);
        }
        public async Task ReturnsMaxChildrenAllowedIfRequestedMoreAsync()
        {
            const int maxChildren  = 2;
            var       rangedEntity =
                RangedNatvisEntityDecorator.First(maxChildren,
                                                  TestNatvisEntity.Create().WithCount(10));

            IList <IVariableInformation> children = await rangedEntity.GetChildrenAsync(0, 5);

            Assert.That(children.Count, Is.EqualTo(3));
            Assert.That(await children[0].ValueAsync(), Is.EqualTo("0"));
            Assert.That(await children[1].ValueAsync(), Is.EqualTo("1"));
            Assert.That(children[2].DisplayName, Is.EqualTo("[More]"));
        }
        public async Task ReturnsMoreThatStartsFromTheNextItemAsync()
        {
            const int maxChildren  = 2;
            var       rangedEntity =
                RangedNatvisEntityDecorator.First(maxChildren,
                                                  TestNatvisEntity.Create().WithCount(10));

            IList <IVariableInformation> children = await rangedEntity.GetChildrenAsync(0, 3);

            var moreAdapter = children[2].GetChildAdapter();

            Assert.That(await moreAdapter.CountChildrenAsync(), Is.EqualTo(3));

            IList <IVariableInformation> moreChildren = await moreAdapter.GetChildrenAsync(0, 3);

            Assert.That(await moreChildren[0].ValueAsync(), Is.EqualTo("2"));
            Assert.That(await moreChildren[1].ValueAsync(), Is.EqualTo("3"));
            Assert.That(moreChildren[2].DisplayName, Is.EqualTo("[More]"));
        }