private static List <StepItem> TestCaseItemToObj(XmlNode testCaseItem)
        {
            List <StepItem> stepItem = new List <StepItem>();

            XmlNodeList nodeList = testCaseItem.ChildNodes;

            foreach (XmlNode node in nodeList)
            {
                StepItem item = new StepItem();
                String   tag  = ((XmlElement)node).Name;
                if (tag == "request")
                {
                    item.IsRequest   = true;
                    item.Name        = node.InnerText;
                    item.RowItemList = new List <RowItem>();
                }
                else if (tag == "response")
                {
                    item.IsRequest = false;
                    XmlNode responseNameNode = ((XmlElement)node).FirstChild;;
                    item.Name = (responseNameNode != null) ? responseNameNode.InnerText : "";

                    XmlNodeList responseItemList = ((XmlElement)node).GetElementsByTagName("item");
                    ResponseItemToObj(item, responseItemList);
                }
                stepItem.Add(item);
            }

            return(stepItem);
        }
Beispiel #2
0
        public Boolean Go(ITestContext context, String serverURI, TestCaseItem tcItem, int value)
        {
            Request request = Request.NewGet();

            //Uri uri = new Uri(new Uri(serverURI), flowTest.ResourceURI);
            Uri uri = new Uri(serverURI);

            request.URI = uri;

            if (RequestBuilder != null)
            {
                request = RequestBuilder.Build(request);
            }

            request.Respond += delegate(object sender, ResponseEventArgs e)
            {
                context.ResponseQueue.Offer(e.Response);
            };

            context.RequestQueue.Offer(request);
            context.Verbose.AppendFormat("{0}({1})\t--------->\t            ", request.Type, request.CodeString);

            StepItem stepItem = new StepItem();

            stepItem.IsRequest   = true;
            stepItem.Name        = request.Method.ToString() + " Request ";
            stepItem.IsPassed    = true;
            stepItem.RowItemList = new List <RowItem>();
            tcItem.StepItemList.Add(stepItem);

            tcItem.stepOperation(request.Method.ToString() + " Request", value);

            request.Send();
            return(true);
        }
Beispiel #3
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);
        }
Beispiel #4
0
 public Boolean Check(Message msg, Message context, StepItem stepItem)
 {
     _reasons.Clear();
     _rowItems.Clear();
     foreach (ICheck check in _groupedChecks)
     {
         if (!check.Check(msg, context, stepItem))
         {
             _reasons.Add(check.Reason);
             _rowItems.Add(check.BaseItemInfo);
         }
     }
     stepItem.RowItemList.AddRange(_rowItems);
     return(_reasons.Count == 0);
 }
Beispiel #5
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);
                }
            }
        }
        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);
            }
        }
Beispiel #7
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);
        }
Beispiel #8
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);
        }
Beispiel #9
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);
        }
Beispiel #10
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);
        }