コード例 #1
0
        public void RegexOptionsParsing()
        {
            Assert.AreEqual(RegexOptions.Compiled | RegexOptions.CultureInvariant,
                            RuleAttributeFactory.ParsePatternFlags("cOmPiLed | CultureInvariant"));
            Assert.AreEqual(RegexOptions.Compiled | RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase,
                            RuleAttributeFactory.ParsePatternFlags("Compiled|IgnoreCase|IgnorePatternWhitespace"));

            // Ignore strange user ;)
            Assert.AreEqual(RegexOptions.Compiled | RegexOptions.IgnorePatternWhitespace,
                            RuleAttributeFactory.ParsePatternFlags("Compiled||  | |IgnorePatternWhitespace"));
        }
コード例 #2
0
        public void CreateAttributeFromClass()
        {
            NhvmClassAttributename attributename = new NhvmClassAttributename();

            attributename.Text = new string[] { "AssertAnimal" };
            Attribute found = RuleAttributeFactory.CreateAttributeFromClass(typeof(Suricato), attributename);

            Assert.IsNotNull(found);
            Assert.AreEqual(typeof(AssertAnimalAttribute), found.GetType());

            attributename.Text = new string[] { "AssertAnimalAttribute" };
            found = RuleAttributeFactory.CreateAttributeFromClass(typeof(Suricato), attributename);
            Assert.IsNotNull(found);
            Assert.AreEqual(typeof(AssertAnimalAttribute), found.GetType());
        }
コード例 #3
0
 public void SingleRegexOptionsParsing()
 {
     Assert.AreEqual(RegexOptions.Compiled, RuleAttributeFactory.ParsePatternSingleFlags("cOmPiLed"));
     Assert.AreEqual(RegexOptions.CultureInvariant, RuleAttributeFactory.ParsePatternSingleFlags("CultureInvariant"));
     Assert.AreEqual(RegexOptions.ECMAScript, RuleAttributeFactory.ParsePatternSingleFlags("ECMAScript"));
     Assert.AreEqual(RegexOptions.ExplicitCapture, RuleAttributeFactory.ParsePatternSingleFlags("ExplicitCapture"));
     Assert.AreEqual(RegexOptions.IgnoreCase, RuleAttributeFactory.ParsePatternSingleFlags("IgnoreCase"));
     Assert.AreEqual(RegexOptions.IgnorePatternWhitespace, RuleAttributeFactory.ParsePatternSingleFlags("IgnorePatternWhitespace"));
     Assert.AreEqual(RegexOptions.Multiline, RuleAttributeFactory.ParsePatternSingleFlags("Multiline"));
     Assert.AreEqual(RegexOptions.None, RuleAttributeFactory.ParsePatternSingleFlags("None"));
     Assert.AreEqual(RegexOptions.RightToLeft, RuleAttributeFactory.ParsePatternSingleFlags("RightToLeft"));
     Assert.AreEqual(RegexOptions.Singleline, RuleAttributeFactory.ParsePatternSingleFlags("Singleline"));
     try
     {
         RuleAttributeFactory.ParsePatternSingleFlags("Pizza");
     }
     catch (ValidatorConfigurationException)
     {
         // Ok
     }
 }
コード例 #4
0
        protected override void Initialize()
        {
            clazz =
                ReflectHelper.ClassForFullName(
                    TypeNameParser.Parse(meta.name, meta.rootMapping.@namespace, meta.rootMapping.assembly).ToString());
            classAttributes = meta.attributename == null
                                ? new List <Attribute>(0)
                                : new List <Attribute>(meta.attributename.Length);

            List <MemberInfo> lmembers = meta.property == null
                                ? new List <MemberInfo>(0)
                                : new List <MemberInfo>(meta.property.Length);

            if (meta.attributename != null)
            {
#if NETFX
                log.Debug("Looking for class attributes");
#else
                Log.Debug("Looking for class attributes");
#endif
                foreach (NhvmClassAttributename attributename in meta.attributename)
                {
#if NETFX
                    log.Info("Attribute to look for = " + GetText(attributename));
#else
                    Log.Info("Attribute to look for = {0}", GetText(attributename));
#endif
                    Attribute classAttribute = RuleAttributeFactory.CreateAttributeFromClass(clazz, attributename);
                    classAttributes.Add(classAttribute);
                }
            }

            if (meta.property != null)
            {
                foreach (NhvmProperty property in meta.property)
                {
                    MemberInfo currentMember = TypeUtils.GetPropertyOrField(clazz, property.name);

                    if (currentMember == null)
                    {
                        throw new InvalidPropertyNameException(property.name, clazz);
                    }

#if NETFX
                    log.Info("Looking for rules for property : " + property.name);
#else
                    Log.Info("Looking for rules for property: {0}", property.name);
#endif
                    lmembers.Add(currentMember);

                    // creation of member attributes
                    foreach (object rule in property.Items)
                    {
                        Attribute thisAttribute = RuleAttributeFactory.CreateAttributeFromRule(rule, meta.rootMapping.assembly,
                                                                                               meta.rootMapping.@namespace);

                        if (thisAttribute != null)
                        {
#if NETFX
                            log.Info(string.Format("Adding member {0} to dictionary with attribute {1}", currentMember.Name, thisAttribute));
#else
                            Log.Info("Adding member {0} to dictionary with attribute {1}", currentMember.Name, thisAttribute);
#endif
                            if (!membersAttributesDictionary.ContainsKey(currentMember))
                            {
                                membersAttributesDictionary.Add(currentMember, new List <Attribute>());
                            }

                            membersAttributesDictionary[currentMember].Add(thisAttribute);
                        }
                    }
                }
            }
            members = lmembers.ToArray();
        }