Esempio n. 1
0
 /// <summary>Test that two objects are equal and raise an exception if the result is false</summary>
 /// <param name="expected">expected object. Can be a string, number, array...</param>
 /// <param name="current">current object. Can be a string, number, array...</param>
 /// <param name="failmessage"></param>
 public void Equals(Object expected, Object current, string failmessage = null)
 {
     if (!Utils.ObjectEquals(expected, current))
     {
         throw new ApplicationException("Assert.Equals failed!\n" + (String.IsNullOrEmpty(failmessage) ? "exp=<" + Utils.Truncate(Utils.ToStrings(expected)) + "> got=<" + Utils.Truncate(Utils.ToStrings(current)) + ">" : failmessage));
     }
 }
Esempio n. 2
0
        protected void InvokeAssert <T>(DelegateRet <T> action, object expected, bool match)
        {
            T result = InvokeReturn(action);

            if (match ^ Utils.ObjectEquals(result, expected))
            {
                throw new ApplicationException(
                          string.Format("{0}\nexp{1}<{2}>\ngot=<{3}> ",
                                        GetErrorPrefix(action.Method.Name),
                                        match ? "=" : "!=",
                                        Utils.ToStrings(expected),
                                        Utils.ToStrings(result)
                                        )
                          );
            }
        }
Esempio n. 3
0
        protected void InvokeWaitFor <T>(DelegateRet <T> action, T expected, bool match)
        {
            T result = default(T);

            _error  = null;
            _thread = new System.Threading.Thread((System.Threading.ThreadStart) delegate {
                while (!_canceled && (match ^ Utils.ObjectEquals(result, expected)))
                {
                    try {
                        result = action();
                    } catch (ThreadAbortException) {
                        break;
                    } catch (NotSupportedException) {
                        _error = "Method not supported by the Selenium .Net web driver";
                    } catch (System.Exception ex) {
                        _error = ex.GetType().Name + ": " + ex.Message;
                    }
                    Thread.Sleep(100);
                    if (_onwait != null)
                    {
                        _onwait();
                    }
                }
            });
            _thread.Start();
            bool succed = _thread.Join(_timeout + 1000);

            this.CheckCanceled();
            if (!succed || _error != null)
            {
                var sb = new StringBuilder();
                sb.Append(GetErrorPrefix(action.Method.Name));
                if (expected != null)
                {
                    sb.Append(" Expected" + (match ? "=" : "!=") + "<" + expected.ToString() + "> result=<" + string.Format("{0}", result) + ">.");
                }
                if (!succed)
                {
                    sb.Append(" Timed out after " + _timeout + " ms.");
                }
                if (_error != null)
                {
                    sb.Append(_error);
                }
                throw new ApplicationException(sb.ToString());
            }
        }
Esempio n. 4
0
        protected String InvokeVerify <T>(DelegateRet <T> action, object expected, bool match)
        {
            T result = InvokeReturn(action);

            if (match ^ Utils.ObjectEquals(result, expected))
            {
                return(string.Format("KO, {0} exp{1}<{2}> got<{3}> ",
                                     GetErrorPrefix(action.Method.Name),
                                     match ? "=" : "!=",
                                     Utils.ToStrings(expected),
                                     Utils.ToStrings(result)
                                     ));
            }
            else
            {
                return("OK");
            }
        }
Esempio n. 5
0
 /// <summary>Test that two objects are not equal and raise an exception if the result is false</summary>
 /// <param name="expected">expected object. Can be a string, number, array...</param>
 /// <param name="current">current object. Can be a string, number, array...</param>
 /// <param name="failmessage">Message to return if the verification fails...</param>
 public string NotEquals(Object expected, Object current, string failmessage = null) {
     if (Utils.ObjectEquals(expected, current))
         return String.IsNullOrEmpty(failmessage) ? "KO, Verify.NotEquals failed! exp=<" + Utils.Truncate(Utils.ToStrings(expected)) + "> got=<" + Utils.Truncate(Utils.ToStrings(current)) + ">" : failmessage;
     return "OK";
 }