public void Matches_ProxyValues(object[] input, string pattern, bool expected)
        {
            var p      = new AttributeValueList(new List <object>(input));
            var actual = p.Matches(pattern);

            Assert.Equal(expected, actual);
        }
        public void Any_ProxyValues_MatchesAny()
        {
            var input = new object[] { "abc", "123", "456" };
            var p     = new AttributeValueList(new List <object>(input));

            Assert.True(p.Any());
        }
示例#3
0
        /// <summary>
        /// Checks whether the pattern approximately matches (~=) any member of the
        /// multi-valued source.
        /// Warning: locally, this does a lower-invariant .Match(). This may not line
        /// up with LDAP implementations. Take local, unit test results with a grain of salt.
        /// </summary>
        /// <param name="source">The multi-valued source to match against.</param>
        /// <param name="pattern">The pattern to match (ex: some*thing).</param>
        /// <returns>True, if it matches.</returns>
        public static bool Approx(this AttributeValueList source, string pattern)
        {
            if (source == null)
            {
                return(false);
            }

            if (pattern == "*")
            {
                return(true); // existence check operator
            }

            return(source.Any(e => Approx(e.ToString(), pattern)));
        }
示例#4
0
        protected internal void ValidateTypeConvertAndSet <T>(
            T model,
            AttributeValueList ldapFieldData,
            PropertyInfo prop,
            string ldapName
            )
            where T : IEntry
        {
            var ptype = prop.PropertyType;

            Type[] genArgs = ptype.BaseType
                             .GetGenericArguments()
                             .Where(a => !a.IsGenericParameter)
                             .ToArray();;
            Type[] baseLdapTypes = new[] {
                typeof(BaseLdapManyType <,>),
                typeof(BaseLdapType <,>)
            };
            if (ptype.BaseType.IsGenericType &&
                baseLdapTypes.Any(t =>
                                  genArgs.Count() == t.GetGenericArguments().Count() &&
                                  TypesUtility.CanMakeGenericTypeAssignableFrom(t, genArgs, ptype)))
            {
                if (ldapFieldData == null)
                {
                    prop.SetValue(model, null);
                    return;
                }

                var converter = Activator.CreateInstance(genArgs[1]);
                var inst      = Activator.CreateInstance(ptype, ldapFieldData, converter);
                prop.SetValue(model, inst);
                return;
            }

            if (ldapFieldData == null || ldapFieldData.Count == 0)
            {
                prop.SetValue(model, null);
                return;
            }
            else if (ldapFieldData.Count == 1)
            {
                prop.SetValue(model, Coerce(prop.PropertyType, ldapFieldData[0]));
                return;
            }

            throw new FormatException(
                      $"Mapping to non-array type, but LDAP data is array: {ldapName} -> {prop.Name}.");
        }
示例#5
0
        public int Convert(AttributeValueList values)
        {
            if (values == null)
            {
                throw new InvalidOperationException("LdapInt value access from null property bag.");
            }

            if (values.Count == 0)
            {
                return(0);
            }

            if (values[0].GetType() == typeof(int))
            {
                return((int)values[0]);
            }
            return(int.Parse(values[0].ToString()));
        }
        public string Convert(AttributeValueList values)
        {
            if (values.Count > 0)
            {
                if (values[0] is string s)
                {
                    return(s);
                }
                if (values[0] is Byte[] b)
                {
                    return(Encoding.UTF8.GetString(b));
                }

                throw new FormatException(
                          $"Expected string or Byte[] but got type {values[0].GetType().Name}. Please create custom converter.");
            }

            return(null);
        }
示例#7
0
 public LdapInt(AttributeValueList raw) : base(raw, new IntConverter())
 {
 }
示例#8
0
 public LdapInt(AttributeValueList raw, IntConverter conv) : base(raw, conv)
 {
 }
示例#9
0
 public BaseLdapType(AttributeValueList raw, TConv conv)
 {
     this.Raw       = raw;
     this.Converted = conv.Convert(Raw);
 }
 public List <string> Convert(AttributeValueList values)
 {
     return(values == null
         ? null
         : values.Select(ConvertOne).ToList());
 }
示例#11
0
 public BaseLdapManyType(AttributeValueList raw, TConv conv)
     : base(conv.Convert(raw))
 {
     this.Raw = raw;
 }
示例#12
0
 public LdapStringList(AttributeValueList raw, StringListConverter conv)
     : base(raw, conv)
 {
 }
示例#13
0
 public LdapStringList(AttributeValueList raw)
     : this(raw, new StringListConverter())
 {
 }
示例#14
0
 public SpellableDatumBase()
 {
     attributes = new AttributeValueListImpl();
 }
示例#15
0
 public LdapString(AttributeValueList raw) : base(raw, new StringConverter())
 {
 }
示例#16
0
 /// <summary>
 /// Alias for .Matches("*").
 /// </summary>
 /// <param name="source">The multi-valued source.</param>
 /// <returns>True, if it matches.</returns>
 public static bool Any(this AttributeValueList source)
 => Matches(source, "*");