/// <summary>
        /// Lookup in own map.
        /// </summary>
        /// <param name="prefix"></param>
        /// <returns></returns>
        private IEnumerable <string> FromMap(string prefix)
        {
            var ns = new ManyOf <string>();

            if (this.map.ContainsKey(prefix))
            {
                ns = new ManyOf <string>(this.map[prefix]);
            }
            return(ns);
        }
        /// <summary>
        /// Lookup in other contexts.
        /// </summary>
        /// <param name="prefix">prefix to find</param>
        /// <returns>list with one or no result</returns>
        private IEnumerable <string> FromContexts(string prefix)
        {
            IEnumerable <string> ns = new ManyOf <string>();

            foreach (IScalar <IXmlNamespaceResolver> ctx in this.contexts)
            {
                string uri = ctx.Value().LookupNamespace(prefix);
                if (uri != null)
                {
                    ns = new ManyOf <string>(uri);
                }
            }
            return(ns);
        }
        public IEnumerator <Exception> GetEnumerator()
        {
            var schemas = new XmlSchemaSet();

            schemas.Add("", XmlReader.Create(new StringReader(this.schema.Value())));
            IEnumerable <Exception> errors = new ManyOf <Exception>();

            this.xml.Value().Validate(
                schemas,
                (obj, ex) => errors = new Joined <Exception>(errors, ex.Exception)
                );

            return(errors.GetEnumerator());
        }
 /// <summary>
 /// A mapped Dictionary that does not enumerate the dicitonary
 /// </summary>
 /// <param name="func">key, value, out</param>
 /// <param name="origin"></param>
 public MappedDictionary(Func <string, Func <string>, Out> func, IDictionary <string, string> origin) : base(new ScalarOf <IEnumerable <Out> >(
                                                                                                                 () =>
 {
     IEnumerable <Out> result = new ManyOf <Out>();
     foreach (var key in origin.Keys)
     {
         result = new Atoms.Enumerable.Joined <Out>(
             result,
             func(key, () => origin[key])
             );
     }
     return(result);
 }),
                                                                                                             false)
 { }
Beispiel #5
0
 /// <summary>
 /// A filtered Dictionary that does not enumerate the dictionary
 /// </summary>
 public FilteredDictionary(Func <string, Func <string>, bool> func, IDictionary <string, string> origin) : base(() =>
 {
     IEnumerable <IKvp> result = new ManyOf <IKvp>();
     foreach (var key in origin.Keys)
     {
         if (func(key, () => origin[key]))
         {
             result = new Yaapii.Atoms.Enumerable.Joined <IKvp>(result,
                                                                new KvpOf(key, () => origin[key])
                                                                );
         }
     }
     return(new MapOf(result));
 },
                                                                                                                false
                                                                                                                )
 { }
        private async Task <CommandResult> LinkAccounts(CommandContext context)
        {
            ManyOf <User> users = await context.ParseArgs <ManyOf <User> >();

            if (users.Values.Count < 2)
            {
                return new CommandResult {
                           Response = "Must link at least 2 accounts"
                }
            }
            ;
            bool success = await _linkedAccountRepo.Link(users.Values.Select(u => u.Id).ToImmutableHashSet());

            return(new CommandResult
            {
                Response = success ? "Accounts successfully linked" : "Accounts were already linked"
            });
        }
        /// <summary>
        /// Lookup in XML specification.
        /// </summary>
        /// <param name="prefix">prefix to find</param>
        /// <returns>list with one or no result</returns>
        private IEnumerable <string> FromXMLSpec(string prefix)
        {
            IEnumerable <string> ns;

            if (prefix.Equals(XML_NS_PREFIX))                     //Defined by the XML specification to be "xml"
            {
                ns = new ManyOf <string>(XML_NS_URI);             //Defined by the XML specification
            }
            else if (prefix.Equals(XMLNS_ATTRIBUTE))              //Defined by the XML specification to be "xmlns"
            {
                ns = new ManyOf <string>(XMLNS_ATTRIBUTE_NS_URI); //Defined by the XML specification
            }
            else
            {
                ns = new ManyOf <string>(NULL_NS_URI);
            }
            return(ns);
        }
        ///// <summary>
        ///// Fetches only root node.
        ///// The root node is found if <paramref name="root"/> contains "*" or the root node name.
        ///// </summary>
        ///// <param name="root">Root node name</param>
        ///// <param name="dom">Document</param>
        ///// <returns>Found nodes</returns>
        //private IEnumerable<XmlNode> RootOnly(string root, XmlNode dom)
        //{
        //    var rootElem = new XmlDocumentOf(dom).Value().DocumentElement;
        //    var targets = new ManyOf<XmlNode>();  // empty list

        //    if (
        //        root != null &&
        //        rootElem != null &&
        //        ("*".Equals(root) || rootElem.Name.Equals(root))
        //    )
        //    {
        //        targets = new ManyOf<XmlNode>(rootElem);
        //    }
        //    return targets;
        //}

        /// <summary>
        /// Get roots to start searching from.
        /// The root nodes are the <paramref name="nodes"/> if there are any or the document root node.
        /// </summary>
        /// <param name="dom">Document</param>
        /// <param name="nodes">Current nodes</param>
        /// <returns>Root nodes to start searching from</returns>
        private IEnumerable <XNode> Roots(XNode dom, IEnumerable <XNode> nodes)
        {
            IEnumerable <XNode> roots = nodes;

            // Return document root if there are no nodes.
            if (new LengthOf(nodes).Value() == 0)
            {
                roots = new ManyOf <XNode>(
                    new XmlDocumentOf(
                        dom
                        ).Value().Document);
            }

            // DocumentElement may be null. Then remove it from the list.
            roots =
                new Filtered <XNode>(
                    (node) => node != null,
                    roots
                    );

            return(roots);
        }
        public void SendsMultipleHeaderValues(string expected)
        {
            var port = new AwaitedPort(new TestPort()).Value();
            IEnumerable <string> headers = new ManyOf <string>();

            using (var server =
                       new HttpMock(port,
                                    new FkWire(req =>
            {
                headers = new Accept.Of(req);
                return(new Response.Of(200, "OK"));
            })
                                    ).Value()
                   )
            {
                new AspNetCoreWire(
                    new AspNetCoreClients(),
                    new TimeSpan(0, 1, 0)
                    ).Response(
                    new Get(
                        new Scheme("http"),
                        new Host("localhost"),
                        new Port(server.Port),
                        new Headers(
                            new KvpOf("Accept", "application/json"),
                            new KvpOf("Accept", "application/xml"),
                            new KvpOf("Accept", "text/plain")
                            )
                        )
                    ).Wait(30000);
            }
            Assert.Contains(
                expected,
                new Yaapii.Atoms.Text.Joined(", ", headers).AsString()
                );
        }