public void LocksHackedImages(string src, PortableHtmlSchemaErorr error)
        {
            var html =
                @"<div><img src=""" + src + @"""></div>";

            testSchema(html, false, PortableHtmlSchemaErorr.NonXml);
        }
        /// <summary>
        ///     Fluent-метод применения ошибки
        /// </summary>
        /// <param name="error"></param>
        /// <param name="el"></param>
        /// <param name="a"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        public PortableHtmlContext SetError(PortableHtmlSchemaErorr error, XElement el = null, XAttribute a = null,
                                            Exception e = null)
        {
            var desc = new PortableHtmlSchemaErorrDescription(error, el, a, e);

            return(SetError(desc));
        }
示例#3
0
 /// <summary>
 /// </summary>
 /// <param name="error"></param>
 /// <param name="el"></param>
 /// <param name="a"></param>
 /// <param name="e"></param>
 public PortableHtmlSchemaErorrDescription(PortableHtmlSchemaErorr error, XElement el, XAttribute a, Exception e)
 {
     Error = error;
     if (null != el)
     {
         Element = el;
         var eli = el as IXmlLineInfo;
         if (eli.HasLineInfo())
         {
             Line   = eli.LineNumber;
             Column = eli.LinePosition;
         }
         XPath = el.GetXPath();
     }
     else if (null != a)
     {
         Attribute = a;
         Element   = a.Parent;
         var eli = a.Parent as IXmlLineInfo;
         if (null != eli && eli.HasLineInfo())
         {
             Line   = eli.LineNumber;
             Column = eli.LinePosition;
         }
         XPath = a.GetXPath();
     }
     Exception = e;
 }
        private void testSchema(object srcHtml, bool isValid = true, PortableHtmlSchemaErorr error = PortableHtmlSchemaErorr.None, Type exceptionType = null, bool exactState = true)
        {
            var result = (srcHtml is string || null == srcHtml)? PortableHtmlSchema.Validate((string)srcHtml):PortableHtmlSchema.Validate((XElement)srcHtml);

            if (isValid && !result.Ok)
            {
                Console.WriteLine(result.SchemaError);
            }
            Assert.AreEqual(isValid, result.Ok, "Общий статус валидации неверен");
            if (error == PortableHtmlSchemaErorr.None || exactState)
            {
                Assert.AreEqual(error, result.SchemaError, "Статус ошибки валидации неверен");
            }
            else
            {
                Assert.True(0 != (error & result.SchemaError));
            }
            if (null == exceptionType)
            {
                return;
            }
            Assert.NotNull(result.Exception, "Ожидалось исключение");
            Assert.AreEqual(exceptionType, result.Exception.GetType(), "Исключение имеет неверный тип");
            if (PortableHtmlVerificationStrategy.ForcedResult == result.Strategy)
            {
                if (!result.Ok)
                {
                    Assert.AreEqual(1, result.Errors.Count, "Много ошибок для ForceResult");
                }
            }
            if (PortableHtmlVerificationStrategy.ForcedElementResult == result.Strategy)
            {
                if (!result.Ok)
                {
                    var groupped = result.Errors.GroupBy(_ => _.Element);
                    Assert.True(groupped.All(_ => _.Count() == 1), "Множественные ошибки для элемента при ForceElementResult");
                }
            }
        }
 public void RootDivElementRequiredCover(string srcHtml, bool isValid, PortableHtmlSchemaErorr error)
 {
     testSchema(XElement.Parse(srcHtml), isValid, error);
 }
 public void RootDivElementRequired(string srcHtml, bool isValid, PortableHtmlSchemaErorr error)
 {
     testSchema(srcHtml, isValid, error);
 }
		/// <summary>
		///     Fluent-метод применения ошибки
		/// </summary>
		/// <param name="error"></param>
		/// <param name="el"></param>
		/// <param name="a"></param>
		/// <param name="e"></param>
		/// <returns></returns>
		public PortableHtmlContext SetError(PortableHtmlSchemaErorr error, XElement el = null, XAttribute a = null,
		                                    Exception e = null){
			var desc = new PortableHtmlSchemaErorrDescription(error, el, a, e);
			return SetError(desc);
		}