Beispiel #1
0
        public void ResolveMultipleSubtree()
        {
            var c1A = new C1Builder(this.Session).WithC1AllorsString("c1A").Build();
            var c1B = new C1Builder(this.Session).WithC1AllorsString("c1B").Build();
            var c1C = new C1Builder(this.Session).WithC1AllorsString("c1C").Build();
            var c1D = new C1Builder(this.Session).WithC1AllorsString("c1D").Build();
            var c1E = new C1Builder(this.Session).WithC1AllorsString("c1E").Build();

            var c2A = new C2Builder(this.Session).WithC2AllorsString("c2A").Build();
            var c2B = new C2Builder(this.Session).WithC2AllorsString("c2B").Build();
            var c2C = new C2Builder(this.Session).WithC2AllorsString("c2C").Build();
            var c2D = new C2Builder(this.Session).WithC2AllorsString("c2D").Build();

            c1A.AddC1I12One2Many(c1C);
            c1B.AddC1I12One2Many(c1E);
            c1B.AddC1I12One2Many(c2A);
            c1B.AddC1I12One2Many(c2B);

            c1C.AddC1C1One2Many(c1D);
            c2A.AddC2C2One2Many(c2C);
            c2A.AddC2C2One2Many(c2D);

            this.Session.Derive();

            this.Session.Commit();

            var tree = new[]
            {
                new Node(M.C1.C1I12One2Manies)
                .Add(M.C1.C1C1One2Manies),
                new Node(M.C1.C1I12One2Manies)
                .Add(M.C2.C2C2One2Manies),
            };

            var prefetchPolicy = tree.BuildPrefetchPolicy();

            var resolved = new HashSet <IObject>();

            this.Session.Prefetch(prefetchPolicy, c1A);

            tree.Resolve(c1A, this.AclsMock.Object, resolved);

            Assert.Equal(2, resolved.Count);
            Assert.Contains(c1C, resolved);
            Assert.Contains(c1D, resolved);

            resolved = new HashSet <IObject>();

            this.Session.Prefetch(prefetchPolicy, c1B);
            tree.Resolve(c1B, this.AclsMock.Object, resolved);

            Assert.Equal(5, resolved.Count);
            Assert.Contains(c1E, resolved);
            Assert.Contains(c2A, resolved);
            Assert.Contains(c2B, resolved);
            Assert.Contains(c2C, resolved);
            Assert.Contains(c2D, resolved);
        }
        public void ResolveMultipleSubtree()
        {
            var c1A = new C1Builder(this.Session).WithC1AllorsString("c1A").Build();
            var c1B = new C1Builder(this.Session).WithC1AllorsString("c1B").Build();
            var c1C = new C1Builder(this.Session).WithC1AllorsString("c1C").Build();
            var c1D = new C1Builder(this.Session).WithC1AllorsString("c1D").Build();
            var c1E = new C1Builder(this.Session).WithC1AllorsString("c1E").Build();

            var c2A = new C2Builder(this.Session).WithC2AllorsString("c2A").Build();
            var c2B = new C2Builder(this.Session).WithC2AllorsString("c2B").Build();
            var c2C = new C2Builder(this.Session).WithC2AllorsString("c2C").Build();
            var c2D = new C2Builder(this.Session).WithC2AllorsString("c2D").Build();

            c1A.AddC1I12One2Many(c1C);
            c1B.AddC1I12One2Many(c1E);
            c1B.AddC1I12One2Many(c2A);
            c1B.AddC1I12One2Many(c2B);

            c1C.AddC1C1One2Many(c1D);
            c2A.AddC2C2One2Many(c2C);
            c2A.AddC2C2One2Many(c2D);

            this.Session.Derive(true);

            this.Session.Commit();

            var tree =
                new Tree(M.C1.ObjectType)
                .Add(M.C1.C1I12One2Manies,
                     new Tree(M.C1.ObjectType).Add(M.C1.C1C1One2Manies))
                .Add(M.C1.C1I12One2Manies,
                     new Tree(M.C2.ObjectType).Add(M.C2.C2C2One2Manies));

            var prefetchPolicy = tree.BuildPrefetechPolicy();

            var resolved = new HashSet <IObject>();

            this.Session.Prefetch(prefetchPolicy, c1A);
            tree.Resolve(c1A, resolved);

            resolved.Count.ShouldEqual(2);
            resolved.ShouldContain(c1C);
            resolved.ShouldContain(c1D);

            resolved = new HashSet <IObject>();

            this.Session.Prefetch(prefetchPolicy, c1B);
            tree.Resolve(c1B, resolved);

            resolved.Count.ShouldEqual(5);
            resolved.ShouldContain(c1E);
            resolved.ShouldContain(c2A);
            resolved.ShouldContain(c2B);
            resolved.ShouldContain(c2C);
            resolved.ShouldContain(c2D);
        }