示例#1
0
        public static void Fail()
        {
            var    caller  = new StackTrace().GetFrame(1).GetMethod();
            string message = string.Format("FAILURE from {0}.{1}.", caller.Name, caller.DeclaringType.Name);

            JExpect.Fail(message);
        }
示例#2
0
        public JExpect ToContain(object elementObj)
        {
            Check.IsArray(this.obj);
            Check.IsNotNull(elementObj);
            var elementType = this.obj.GetType().GetElementType();

            if (!elementType.Equals(elementObj.GetType()))
            {
                JExpect.Fail(JErrorMessage.JEXPECT_VALUENOTMATCH, elementType.Name, elementObj.GetType().Name);
            }

            var  arrayObj = (Array)this.obj;
            bool contains = false;

            for (int i = 0; i < arrayObj.Length; i++)
            {
                if (arrayObj.GetValue(i).Equals(elementObj))
                {
                    contains = true;
                    break;
                }
            }

            if (((!this.not) && (!contains)) || (this.not && contains))
            {
                JExpect.Fail();
            }

            return(this);
        }
示例#3
0
        public JExpect ToBeNull()
        {
            if (((!this.not) && this.obj != null) ||
                (this.not && this.obj == null))
            {
                JExpect.Fail(JErrorMessage.JEXPECT_TOBENULLFAIL);
            }

            return(this);
        }
示例#4
0
        public JExpect ToEqual(object expect)
        {
            Check.IsNotNull(this.obj);
            Check.IsNotNull(expect);
            if ((!this.not) && (!obj.Equals(expect)) ||
                this.not && obj.Equals(expect))
            {
                JExpect.Fail();
            }

            return(this);
        }
示例#5
0
        public JExpect ToBeTruthy()
        {
            Check.IsBoolean(this.obj);
            var bObj = Convert.ToBoolean(this.obj);

            if (((!this.not) && (!bObj)) ||
                this.not && bObj)
            {
                JExpect.Fail();
            }

            return(this);
        }
示例#6
0
        public JExpect ToMatch(string regex)
        {
            Check.IsNotNull(this.obj);
            Check.IsNotNull(regex);
            var match = Regex.Match(Convert.ToString(this.obj), regex, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);

            if (((!this.not) && (!match.Success)) ||
                (this.not && match.Success))
            {
                JExpect.Fail();
            }

            return(this);
        }
示例#7
0
 public static void Fail(string message, params string[] args)
 {
     JExpect.Fail(string.Format(message, args));
 }