Ejemplo n.º 1
0
        /// <summary>
        /// Validate that the property value match the given regex.  Null or empty values are allowed.
        /// </summary>
        /// <param name="instance"></param>
        /// <param name="fieldValue"></param>
        /// <returns><c>true</c> if the field is OK</returns>
        public override bool IsValid(object instance, object fieldValue)
        {
            if (fieldValue != null && fieldValue.ToString() != "")
            {
                var value = fieldValue.ToString();

                if (value.Length > 0)
                {
                    if (value.Length != 36)
                    {
                        return(false);
                    }
                    if (RegexRule.IsMatch(value))
                    {
                        if (acceptEmptyGuid)
                        {
                            return(true);
                        }
                        return(value != Guid.Empty.ToString());
                    }
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        public void MustIgnoreCase()
        {
            sut.Initialize(new FilterRuleSettings {
                Expression = Regex.Escape("http://www.test.org/path/file.txt?param=123")
            });

            Assert.IsTrue(sut.IsMatch(new Request {
                Url = "hTtP://wWw.TeSt.OrG/pAtH/fIlE.tXt?PaRaM=123"
            }));
            Assert.IsTrue(sut.IsMatch(new Request {
                Url = "HtTp://WwW.tEst.oRg/PaTh/FiLe.TxT?pArAm=123"
            }));

            sut.Initialize(new FilterRuleSettings {
                Expression = Regex.Escape("HTTP://WWW.TEST.ORG/PATH/FILE.TXT?PARAM=123")
            });

            Assert.IsTrue(sut.IsMatch(new Request {
                Url = "hTtP://wWw.TeSt.OrG/pAtH/fIlE.tXt?PaRaM=123"
            }));
            Assert.IsTrue(sut.IsMatch(new Request {
                Url = "HtTp://WwW.tEst.oRg/PaTh/FiLe.TxT?pArAm=123"
            }));
        }