public static void SetupEachTest()
        {
            // Before each test execution we reinitialize fake DAL and businessLogic
            // so tests won't conflict between themselves
            fakeDataAccessLayer = Substitute.For <TestedMethod.IDataAccessLayer>();
            businessLogic       = new TestedMethod.BusinessLogic(fakeDataAccessLayer);
            innovator           = ItemHelper.CreateInnovator();

            fakeDataAccessLayer.NewItem(Arg.Any <string>(), Arg.Any <string>())
            .Returns(@params => ItemHelper.CreateItem((string)@params[0], (string)@params[1]));

            fakeDataAccessLayer.NewResult(Arg.Any <string>())
            .Returns(@params => innovator.newResult((string)@params[0]));

            // We use applyProcessor List to store fake AML responces
            applyProcessor = InitializeApplyProcessor();
            fakeDataAccessLayer.ApplyItem(Arg.Any <Item>())
            .Returns(@params =>
            {
                Item paramItem = (Item)@params[0];
                foreach (Func <Item, Item> processor in applyProcessor)
                {
                    Item result = processor(paramItem);
                    if (result != null)
                    {
                        return(result);
                    }
                }
                return(null);
            });
        }
        /// <inheritdoc/>
        /// <summary>
        /// Returns direct URL to file if it is a File item, otherwise
        /// builds url from items
        /// </summary>
        public override Item DoApply(Item root)
        {
            // populate properties from xml
            XmlPropertyAttribute.BindXml(root.node, this);

            // log info
            Log(nameof(DoApply), $"Generating URL for {Type} ID {Id})");

            // generate url
            var url = Type == "File"
                ? Innovator.getFileUrl(Id, UrlType.None)
                : $"{BaseUrl}/default.aspx?StartItem={Type}:{Id}";

            // return result
            return(Innovator.newResult(url));
        }
        /// <inheritdoc />
        /// <summary>
        /// Check if user is an (possibly indirect) member of an identity group
        /// </summary>
        /// <param name="body">Method XML body item</param>
        /// <returns>'true' as string result if membership matches</returns>
        public override Item DoApply(Item body)
        {
            XmlPropertyAttribute.BindXml(body.node, this);

            var userId = Innovator.getUserID();

            var userAlias = Innovator.newItem("Alias", "get");

            userAlias.setAttribute("select", "related_id");
            userAlias.setProperty("source_id", userId);
            userAlias = Innovator.ApplyItem(userAlias);

            var identityId = userAlias.getProperty("related_id");

            return(Innovator.newResult(CheckIfMemberOfIdentity(identityId) ? "true" : "false"));
        }
Beispiel #4
0
        /// <inheritdoc />
        /// <summary>
        /// Check if user is an (possibly indirect) member of an identity group
        /// </summary>
        /// <param name="body">Method XML body item</param>
        /// <returns>'true' as string result if membership matches</returns>
        public override Item DoApply(Item body)
        {
            XmlPropertyAttribute.BindXml(body.node, this);

            var userId = Innovator.getUserID();

            var userAlias = Innovator.newItem("Alias", "get");

            userAlias.setAttribute("select", "related_id");
            userAlias.setProperty("source_id", userId);
            userAlias = Innovator.ApplyItem(userAlias);

            var ids = new List <string> {
                userAlias.getProperty("related_id")
            };

            // not the fastest, but it works.
            // should be optimized by asking for batches of identities.
            // (see below for fast recursive SQL .. that Aras doesn't permit in ApplySQL.)
            while (ids.Any())
            {
                var id = ids.Last();
                ids.RemoveAt(ids.Count - 1);

                var identityItem = Innovator.newItem("Identity", "get");
                identityItem.setAttribute("select", "keyed_name");

                var memberRelation = identityItem.createRelationship("Member", "get");
                memberRelation.setAttribute("select", "keyed_name");
                memberRelation.setProperty("related_id", id);
                identityItem = Innovator.ApplyItem(identityItem);

                if (identityItem.Enumerate()
                    .Any(i => i.getProperty("keyed_name") == IdentityName))
                {
                    return(Innovator.newResult("true"));
                }

                ids.AddRange(identityItem.Enumerate().Select(i => i.getID()));
            }

            return(Innovator.newResult("false"));
        }
 public Item NewResult(string data)
 {
     return(Innovator.newResult(data));
 }