コード例 #1
0
ファイル: PathTests.cs プロジェクト: lulzzz/allors2
        public void One2ManyWithPropertyNames()
        {
            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 c1A = new C1Builder(this.Session)
                      .WithC1AllorsString("c1A")
                      .WithC1C2One2Many(c2A)
                      .Build();

            var c1B = new C1Builder(this.Session)
                      .WithC1AllorsString("c1B")
                      .WithC1C2One2Many(c2B)
                      .WithC1C2One2Many(c2C)
                      .Build();

            this.Session.Derive(true);

            Fetch fetch;

            Fetch.TryParse(M.C2.ObjectType, "C1WhereC1C2One2Many", out fetch);

            var aclMock = new Mock <IAccessControlList>();

            aclMock.Setup(acl => acl.CanRead(It.IsAny <IPropertyType>())).Returns(true);
            var acls = new AccessControlListFactory(null, (allorsObject, user) => aclMock.Object);

            var result = (C1)fetch.Get(c2A, acls);

            Assert.Equal(result, c1A);

            result = (C1)fetch.Get(c2B, acls);
            Assert.Equal(result, c1B);
        }
コード例 #2
0
ファイル: PathTests.cs プロジェクト: lulzzz/allors2
        public void One2ManyWithPropertyTypeIds()
        {
            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 c1a = new C1Builder(this.Session)
                      .WithC1AllorsString("c1A")
                      .WithC1C2One2Many(c2A)
                      .Build();

            var c1b = new C1Builder(this.Session)
                      .WithC1AllorsString("c1B")
                      .WithC1C2One2Many(c2B)
                      .WithC1C2One2Many(c2C)
                      .Build();

            this.Session.Derive(true);

            var path = new Fetch(MetaC1.Instance.C1C2One2Manies, MetaC2.Instance.C2AllorsString);

            var aclMock = new Mock <IAccessControlList>();

            aclMock.Setup(acl => acl.CanRead(It.IsAny <IPropertyType>())).Returns(true);
            var acls = new AccessControlListFactory(null, (allorsObject, user) => aclMock.Object);

            var result = (ISet <object>)path.Get(c1a, acls);

            Assert.Equal(1, result.Count);
            Assert.True(result.Contains("c2A"));

            result = (ISet <object>)path.Get(c1b, acls);
            Assert.Equal(2, result.Count);
            Assert.True(result.Contains("c2B"));
            Assert.True(result.Contains("c2C"));
        }
コード例 #3
0
        public void Execute(PullResponseBuilder response)
        {
            if (this.pull.Extent == null && !this.pull.ExtentRef.HasValue)
            {
                throw new Exception("Either an Extent or an ExtentRef is required.");
            }

            var extent  = this.pull.Extent ?? this.extentService.Get(this.pull.ExtentRef.Value);
            var objects = extent.Build(this.session, this.pull.Arguments).ToArray();

            if (this.pull.Results != null)
            {
                foreach (var result in this.pull.Results)
                {
                    var name = result.Name;

                    var fetch = result.Fetch;
                    if (fetch == null && result.FetchRef.HasValue)
                    {
                        fetch = this.fetchService.Get(result.FetchRef.Value);
                    }

                    if (fetch != null)
                    {
                        var include = fetch.Include ?? fetch.Step?.End.Include;

                        if (fetch.Step != null)
                        {
                            var aclCache = new AccessControlListFactory(this.user);

                            var propertyType = fetch.Step.End.PropertyType;

                            objects = propertyType.IsOne ?
                                      objects.Select(v => fetch.Step.Get(v, aclCache)).Where(v => v != null).Cast <IObject>().Distinct().ToArray() :
                                      objects.SelectMany(v => ((Extent)fetch.Step.Get(v, aclCache)).ToArray()).Distinct().ToArray();

                            name = name ?? propertyType.PluralName;
                        }

                        name = name ?? extent.ObjectType.PluralName;

                        if (result.Skip.HasValue || result.Take.HasValue)
                        {
                            var paged = result.Skip.HasValue ? objects.Skip(result.Skip.Value) : objects;
                            if (result.Take.HasValue)
                            {
                                paged = paged.Take(result.Take.Value);
                            }

                            paged = paged.ToArray();

                            response.AddValue(name + "_total", extent.Build(this.session, this.pull.Arguments).Count);
                            response.AddCollection(name, paged, include);
                        }
                        else
                        {
                            response.AddCollection(name, objects, include);
                        }
                    }
                    else
                    {
                        name = name ?? extent.ObjectType.PluralName;
                        response.AddCollection(name, objects);
                    }
                }
            }
            else
            {
                var name = extent.ObjectType.PluralName;
                response.AddCollection(name, objects);
            }
        }
コード例 #4
0
ファイル: PullInstantiate.cs プロジェクト: lulzzz/allors2
        public void Execute(PullResponseBuilder response)
        {
            var @object = this.session.Instantiate(this.pull.Object);

            var objectType = this.pull.ObjectType as IComposite;
            var @class     = @object.Strategy?.Class;

            if (@class != null && objectType != null)
            {
                if (!objectType.IsAssignableFrom(@class))
                {
                    return;
                }
            }

            if (this.pull.Results != null)
            {
                foreach (var result in this.pull.Results)
                {
                    var name = result.Name;

                    var fetch = result.Fetch;
                    if (fetch == null && result.FetchRef.HasValue)
                    {
                        fetch = this.fetchService.Get(result.FetchRef.Value);
                    }

                    if (fetch != null)
                    {
                        var include = fetch.Include ?? fetch.Step?.End.Include;

                        if (fetch.Step != null)
                        {
                            var aclCache = new AccessControlListFactory(this.user);

                            var propertyType = fetch.Step.End.PropertyType;

                            if (fetch.Step.IsOne)
                            {
                                name = name ?? propertyType.SingularName;

                                @object = (IObject)fetch.Step.Get(@object, aclCache);
                                response.AddObject(name, @object, include);
                            }
                            else
                            {
                                name = name ?? propertyType.PluralName;

                                var stepResult = fetch.Step.Get(@object, aclCache);
                                var objects = stepResult is HashSet <object> set?set.Cast <IObject>().ToArray() : ((Extent)stepResult).ToArray();

                                if (result.Skip.HasValue || result.Take.HasValue)
                                {
                                    var paged = result.Skip.HasValue ? objects.Skip(result.Skip.Value) : objects;
                                    if (result.Take.HasValue)
                                    {
                                        paged = paged.Take(result.Take.Value);
                                    }

                                    paged = paged.ToArray();

                                    response.AddValue(name + "_total", objects.Length);
                                    response.AddCollection(name, paged, include);
                                }
                                else
                                {
                                    response.AddCollection(name, objects, include);
                                }
                            }
                        }
                        else
                        {
                            name = name ?? this.pull.ObjectType?.Name ?? @object.Strategy.Class.SingularName;
                            response.AddObject(name, @object, include);
                        }
                    }
                    else
                    {
                        name = name ?? this.pull.ObjectType?.Name ?? @object.Strategy.Class.SingularName;
                        response.AddObject(name, @object);
                    }
                }
            }
            else
            {
                var name = this.pull.ObjectType?.Name ?? @object.Strategy.Class.SingularName;
                response.AddObject(name, @object);
            }
        }