Beispiel #1
0
        public static XmlElement TestCaseRequestToNode(TestCaseRequest tcRequest, XmlDocument doc)
        {
            XmlElement tcrElement = doc.CreateElement("testCaseRequest");

            XmlElement methodElement = doc.CreateElement("method");

            methodElement.InnerText = tcRequest.Method;
            tcrElement.AppendChild(methodElement);

            XmlElement messageTypeElement = doc.CreateElement("messageType");

            messageTypeElement.InnerText = tcRequest.MessageType;
            tcrElement.AppendChild(messageTypeElement);

            XmlElement payLoadElement = doc.CreateElement("payLoad");

            payLoadElement.InnerText = tcRequest.PayLoad;
            tcrElement.AppendChild(payLoadElement);

            XmlElement tokenElement = doc.CreateElement("token");

            tokenElement.InnerText = tcRequest.Token;
            tcrElement.AppendChild(tokenElement);

            XmlElement optionType = doc.CreateElement("optionType");

            tcrElement.AppendChild(optionType);

            OptionTypesToNode(tcRequest.OptionType, doc, optionType);

            return(tcrElement);
        }
Beispiel #2
0
        public static TestCaseRequest StepToTestCaseRequest(RequestBuildStep step)
        {
            TestCaseRequest tcRequest = new TestCaseRequest();

            tcRequest.IsRequest = true;
            IRequestBuilder builder = step.RequestBuilder;

            if (builder is GroupBuilder)
            {
                foreach (IRequestBuilder rb in builder as GroupBuilder)
                {
                    BuildTestCaseRequest(rb, tcRequest);
                }
            }
            else
            {
                BuildTestCaseRequest(builder, tcRequest);
            }
            return(tcRequest);
        }
Beispiel #3
0
        public static void BuildTestCaseRequest(IRequestBuilder builder, TestCaseRequest tcRequest)
        {
            if (builder is MethodBuilder)
            {
                tcRequest.Method = (builder as MethodBuilder).Method.ToString();
            }
            else if (builder is MessageTypeBuilder)
            {
                tcRequest.MessageType = (builder as MessageTypeBuilder).MessageType.ToString();
            }
            else if (builder is TokenBuilder)
            {
                tcRequest.Token = Utils.ToHexString((builder as TokenBuilder).Token);
            }
            else if (builder is PayloadBuilder)
            {
                PayloadBuilder pb = builder as PayloadBuilder;
                if (pb.Payload != null)
                {
                    tcRequest.PayLoad = Utils.ToHexString(pb.Payload);
                }
                else
                {
                    tcRequest.PayLoad = pb.PayloadString;
                }
                tcRequest.OptionType.Content_Format = pb.ContentType.ToString();
            }

            else if (builder is OptionBuilder)
            {
                OptionBuilder ob = builder as OptionBuilder;
                switch (ob.OptionType)
                {
                case OptionType.UriPath:
                    tcRequest.OptionType.UriPath = ob.StringValue;
                    break;

                case OptionType.UriQuery:
                    tcRequest.OptionType.UriQuery = ob.StringValue;
                    break;

                case OptionType.Accept:
                    tcRequest.OptionType.Accept = ob.IntValue.ToString();
                    break;

                case OptionType.ContentType:
                    tcRequest.OptionType.Content_Format = ob.IntValue.ToString();
                    break;

                case OptionType.ETag:
                    tcRequest.OptionType.ETag = ob.RawValue == null ? ob.StringValue : Utils.ToHexString(ob.RawValue);
                    break;

                case OptionType.IfMatch:
                    tcRequest.OptionType.If_Match = ob.RawValue == null ? ob.StringValue : Utils.ToHexString(ob.RawValue);
                    break;

                case OptionType.IfNoneMatch:
                    tcRequest.OptionType.If_None_Match = "TRUE";
                    break;

                case OptionType.Observe:
                    //tcRequest.OptionType.Observe = ob.IntValue.ToString();
                    tcRequest.OptionType.Observe = ob.IntValue == null ? (ob.StringValue == null ? "" : ob.StringValue) : ob.IntValue.ToString();
                    break;

                case OptionType.Block2:
                    //tcRequest.OptionType.Block2 = ob.IntValue.ToString();
                    tcRequest.OptionType.Block2 = ob.IntValue == null ? (ob.StringValue == null ? "" : ob.StringValue) : ob.IntValue.ToString();
                    break;

                case OptionType.Block1:
                    //tcRequest.OptionType.Block1 = ob.IntValue.ToString();
                    tcRequest.OptionType.Block1 = ob.IntValue == null ? (ob.StringValue == null ? "" : ob.StringValue) : ob.IntValue.ToString();
                    break;

                case OptionType.LocationPath:
                    tcRequest.OptionType.Location_Path = ob.StringValue.ToString();
                    break;

                case OptionType.LocationQuery:
                    tcRequest.OptionType.Location_Query = ob.StringValue.ToString();
                    break;

                case OptionType.MaxAge:
                    //tcRequest.OptionType.Max_Age = ob.IntValue.ToString();
                    tcRequest.OptionType.Max_Age = ob.IntValue == null ? (ob.StringValue == null ? "" : ob.StringValue) : ob.IntValue.ToString();
                    break;

                case OptionType.ProxyScheme:
                    tcRequest.OptionType.Proxy_Scheme = "TRUE";
                    break;

                case OptionType.ProxyUri:
                    tcRequest.OptionType.Proxy_Uri = ob.StringValue.ToString();
                    break;

                case OptionType.Token:
                    tcRequest.Token = ob.StringValue.ToString();
                    break;

                case OptionType.UriHost:
                    tcRequest.OptionType.Uri_Host = ob.StringValue.ToString();
                    break;

                case OptionType.UriPort:
                    //tcRequest.OptionType.Uri_Port = ob.IntValue.ToString();
                    tcRequest.OptionType.Uri_Port = ob.IntValue == null ? (ob.StringValue == null ? "" : ob.StringValue) : ob.IntValue.ToString();
                    break;
                }
            }
        }
Beispiel #4
0
        public static TestCaseBase NodeToTestCaseBase(XmlNode reNode)
        {
            TestCaseBase tcb;

            if (reNode.Name == "testCaseRequest")
            {
                TestCaseRequest tcrq = new TestCaseRequest();
                tcb           = tcrq;
                tcb.IsRequest = true;

                XmlNodeList xnMethod = ((XmlElement)reNode).GetElementsByTagName("method");
                if (xnMethod != null)
                {
                    tcrq.Method = xnMethod.Item(0).InnerText;
                }
            }
            else
            {
                TestCaseResponse tcrs = new TestCaseResponse();
                tcb           = tcrs;
                tcb.IsRequest = false;

                XmlNodeList xnCode = ((XmlElement)reNode).GetElementsByTagName("code");
                if (xnCode != null)
                {
                    tcrs.Code = xnCode.Item(0).InnerText;
                }
                XmlNodeList xnSameMID = ((XmlElement)reNode).GetElementsByTagName("sameMID");
                if (xnSameMID != null && xnSameMID.Count > 0)
                {
                    tcrs.SameMID = xnSameMID.Item(0).InnerText;
                }
            }

            XmlNodeList xnMessageType = ((XmlElement)reNode).GetElementsByTagName("messageType");

            if (xnMessageType != null && xnMessageType.Count > 0)
            {
                tcb.MessageType = xnMessageType.Item(0).InnerText;
            }

            XmlNodeList xnPayLoad = ((XmlElement)reNode).GetElementsByTagName("payLoad");

            if (xnPayLoad != null && xnPayLoad.Count > 0)
            {
                tcb.PayLoad = xnPayLoad.Item(0).InnerText;
            }

            XmlNodeList xnToken = ((XmlElement)reNode).GetElementsByTagName("token");

            if (xnToken != null && xnToken.Count > 0)
            {
                tcb.Token = xnToken.Item(0).InnerText;
            }

            OptionTypes ots = new OptionTypes();

            XmlNodeList xnlOptionTypeList = ((XmlElement)reNode).GetElementsByTagName("optionType");

            if (xnlOptionTypeList != null && xnlOptionTypeList.Count > 0)
            {
                XmlNode xnlOptionType = xnlOptionTypeList.Item(0);
                ots = NodeToOptionTypes(xnlOptionType);
            }
            tcb.OptionType = ots;

            return(tcb);
        }