Ejemplo n.º 1
0
 protected void AppendBaseItem(RowItem baseItem)
 {
     if (_baseItems == null)
     {
         _baseItems = new List <RowItem>();
     }
     _baseItems.Add(baseItem);
 }
Ejemplo n.º 2
0
        public Boolean Check(Message msg, Message context, StepItem stepItem)
        {
            Boolean success;

            if (_expected == null)
            {
                success = msg.HasOption(OptionType);
                if (!success)
                {
                    Reason = "得到的响应没有" + Option.ToString(OptionType);

                    RowItem bi = new RowItem();
                    bi.Name      = Option.ToString(OptionType);
                    bi.ErrorInfo = "得到的响应没有" + Option.ToString(OptionType);
                    bi.IsPassed  = false;
                    bi.Parent    = null;
                    BaseItemInfo = bi;
                }
            }
            else
            {
                Option actual = msg.GetFirstOption(OptionType);
                success = _expected.Equals(actual);
                if (!success)
                {
                    Reason = String.Format("期望{0}的值为\"{1}\",但得到\"{2}\"", Option.ToString(OptionType),
                                           _expected, actual == null ? "" : actual.ToString());

                    RowItem bi = new RowItem();
                    bi.Name = Option.ToString(OptionType);
                    if (actual != null)
                    {
                        bi.ErrorInfo = String.Format("期望{0}的值为\"{1}\",但得到\"{2}\"", Option.ToString(OptionType),
                                                     _expected, actual.ToString());
                    }
                    else
                    {
                        bi.ErrorInfo = String.Format("期望{0}的值为\"{1}\",但没得到数据", Option.ToString(OptionType), _expected);
                    }
                    bi.ErrorInfo = String.Format("期望{0}的值为\"{1}\",但得到\"{2}\"", Option.ToString(OptionType),
                                                 _expected, actual == null ? "" : actual.ToString());
                    bi.Expected  = _expected.ToString();
                    bi.Received  = actual == null ? "" : actual.ToString();
                    bi.IsPassed  = false;
                    bi.Parent    = null;
                    BaseItemInfo = bi;
                    // stepItem.RowItemList.Add(BaseItemInfo);
                }
            }


            return(success);
        }
Ejemplo n.º 3
0
        public Boolean Go(ITestContext context, String serverURI, TestCaseItem tcItem, int value)
        {
            Request  request  = context.RequestQueue.Poll(1000);
            Response response = context.ResponseQueue.Poll(2000);

            if (response == null)
            {
                context.Verbose.Append("           \t          \t            ");
                _summeries = new String[] { "Timeout" };

                StepItem stepItem = new StepItem();
                //stepItem.RowItemList = new List<RowItem>();
                stepItem.IsPassed  = false;
                stepItem.IsRequest = false;
                //stepItem.Name = response.Type.ToString() + " Response Code=" + response.Code.ToString();
                stepItem.Name        = this.ToString();
                stepItem.RowItemList = new List <RowItem>();
                RowItem rowItem = new RowItem();
                rowItem.ErrorInfo = "Time out";
                rowItem.IsPassed  = false;
                rowItem.Name      = this.ToString();
                stepItem.RowItemList.Add(rowItem);
                tcItem.StepItemList.Add(stepItem);
                tcItem.stepOperation("Time out", value);

                return(false);
            }
            else
            {
                context.Verbose.AppendFormat("           \t<---------\t{0}(code={1})", response.Type, response.Code);
                StepItem stepItem = new StepItem();
                stepItem.RowItemList = new List <RowItem>();
                stepItem.IsRequest   = false;
                stepItem.Name        = response.Type.ToString() + " Response";
                tcItem.StepItemList.Add(stepItem);
                tcItem.stepOperation(response.Type.ToString() + " Response", value);
                if (ResponseCheck != null)
                {
                    return(ResponseCheck.Check(response, request, stepItem));
                }
                else
                {
                    return(true);
                }
            }
        }
Ejemplo n.º 4
0
        protected Boolean HasContentType(Response response)
        {
            Boolean success = response.HasOption(OptionType.ContentType);

            if (!success)
            {
                AppendReason("Response without Content-Type");

                RowItem bi = new RowItem();
                bi.Name      = "Content-Type";
                bi.ErrorInfo = "Response without Content-Type";
                bi.Parent    = null;
                bi.IsPassed  = false;
                AppendBaseItem(bi);
            }
            return(success);
        }
Ejemplo n.º 5
0
        protected Boolean CheckInt(Int32 expected, Int32 actual, String fieldName)
        {
            Boolean success = expected == actual;

            if (!success)
            {
                AppendReason(String.Format("Expected {0}: {1}, but received: {2}", fieldName, expected, actual));

                RowItem bi = new RowItem();
                bi.Name      = "fieldName";
                bi.ErrorInfo = String.Format("Expected {0}: {1}, but received: {2}", fieldName, expected, actual);
                bi.Expected  = expected.ToString();
                bi.Received  = actual.ToString();
                bi.Parent    = null;
                bi.IsPassed  = false;
                AppendBaseItem(bi);
            }
            return(success);
        }
Ejemplo n.º 6
0
        protected Boolean CheckType(MessageType expectedMessageType, MessageType actualMessageType)
        {
            Boolean success = expectedMessageType.Equals(actualMessageType);

            if (!success)
            {
                AppendReason(String.Format("Expected type {0}, but received {1}", expectedMessageType, actualMessageType));

                RowItem bi = new RowItem();
                bi.Name      = "type";
                bi.ErrorInfo = String.Format("Expected type {0}, but received {1}", expectedMessageType, actualMessageType);
                bi.Expected  = expectedMessageType.ToString();
                bi.Received  = actualMessageType.ToString();
                bi.Parent    = null;
                bi.IsPassed  = false;
                AppendBaseItem(bi);
            }
            return(success);
        }
Ejemplo n.º 7
0
        private static void ResponseItemToObj(StepItem item, XmlNodeList responseItemList)
        {
            item.RowItemList = new List <RowItem>();
            foreach (XmlNode node in responseItemList)
            {
                RowItem     row      = new RowItem();
                XmlNodeList nameList = ((XmlElement)node).GetElementsByTagName("names");
                row.Name = nameList != null && nameList.Count > 0 ? nameList.Item(0).InnerText : "";

                XmlNodeList expectedList = ((XmlElement)node).GetElementsByTagName("expected");
                row.Expected = expectedList != null && expectedList.Count > 0 ? expectedList.Item(0).InnerText : "";

                XmlNodeList receivedList = ((XmlElement)node).GetElementsByTagName("received");
                row.Received = receivedList != null && receivedList.Count > 0 ? receivedList.Item(0).InnerText : "";

                XmlNodeList errorinfoList = ((XmlElement)node).GetElementsByTagName("errorinfo");
                row.ErrorInfo = errorinfoList != null && errorinfoList.Count > 0 ? errorinfoList.Item(0).InnerText : "";
                item.RowItemList.Add(row);
            }
        }
Ejemplo n.º 8
0
        public Boolean Check(Message msg, Message context, StepItem stepItem)
        {
            Boolean success = msg.ID == context.ID;

            if (!success)
            {
                Reason = String.Format("期望message ID的值为{0},但得到\"{1}\"", context.ID, msg.ID);
                RowItem bi = new RowItem();
                bi.ErrorInfo = String.Format("期望message ID的值为{0},但得到\"{1}\"", context.ID, msg.ID);
                bi.Expected  = context.ID.ToString();
                bi.Received  = msg.ID.ToString();
                bi.Name      = "message ID";
                bi.IsPassed  = false;
                bi.Parent    = null;
                BaseItemInfo = bi;
                //stepItem.RowItemList.Add(BaseItemInfo);
            }

            return(success);
        }
Ejemplo n.º 9
0
        public Boolean Check(Message msg, Message context, StepItem stepItem)
        {
            Boolean success = (msg.Payload != null && msg.Payload.Length > 0) || (msg.PayloadString != null && msg.PayloadString.Length > 0);

            if (!success)
            {
                Reason = "期望PayLoad(任意值),但没有获得任意数据";
                RowItem bi = new RowItem();
                bi.ErrorInfo = "期望PayLoad(任意值),但没有获得任意数据";
                bi.Expected  = "PayLoad(任意值)";
                //bi.Received = msg.ID.ToString();
                bi.Received  = "";
                bi.Name      = "PayLoad";
                bi.IsPassed  = false;
                bi.Parent    = null;
                BaseItemInfo = bi;
            }

            return(success);
        }
Ejemplo n.º 10
0
        public Boolean Check(Message msg, Message context, StepItem stepItem)
        {
            Boolean success = (msg.Token != null && msg.Token.Length > 0) || (msg.TokenString != null && msg.TokenString.Length > 0);

            if (!success)
            {
                Reason = "期望Token(任意值),但没有获得任意数据";
                RowItem bi = new RowItem();
                bi.ErrorInfo = "期望Token(任意值),但没有获得任意数据";
                bi.Expected  = "Token(任意值)";
                bi.Received  = msg.ID.ToString();
                bi.Name      = "Token";
                bi.IsPassed  = false;
                bi.Parent    = null;
                BaseItemInfo = bi;
                //stepItem.RowItemList.Add(BaseItemInfo);
            }

            return(success);
        }
Ejemplo n.º 11
0
        public Boolean Check(Message msg, Message context, StepItem stepItem)
        {
            T actual = GetValue(msg);

            String expected;
            String received;

            Boolean success      = false;
            Type    type         = null;
            Type    expectedType = Expected.GetType();

            if (actual != null)
            {
                type = actual.GetType();
                if (type == typeof(byte[]))
                {
                    success = this.ValueEqual(actual, Expected);
                }
                else if (type == typeof(string))
                {
                    success = this.ValueEqual(actual, Expected);
                }
                else
                {
                    success = Expected.Equals(actual);
                }
            }
            if (!success)
            {
                if (expectedType == typeof(byte[]))
                {
                    expected = this.ToString(Expected);
                }
                else
                {
                    expected = Expected.ToString();
                }

                if (actual == null)
                {
                    received = "";
                }
                else if (type == typeof(byte[]))
                {
                    received = this.ToString(actual);
                }
                else
                {
                    received = actual.ToString();
                }
                #region MyRegion
                Reason = String.Format("期望{0}的值为\"{1}\",但得到\"{2}\"", Field, expected, received);
                RowItem bi = new RowItem();
                bi.ErrorInfo = String.Format("期望{0}的值为\"{1}\",但得到\"{2}\"", Field, expected, received);
                bi.Expected  = expected;
                bi.Name      = Field;
                bi.IsPassed  = false;
                bi.Parent    = null;
                bi.Received  = received;
                BaseItemInfo = bi;
                #endregion
            }

            return(success);
        }