Exemplo n.º 1
0
        /// <summary>
        /// Compare expected headers
        /// </summary>
        public HeadersTestResult CompareHeaders(out string error)
        {
            //todo fazer loop em cima do response.headers.
            error = null;

            HeadersTestResult headersTestResult = HelperGenericHttpTester.CompareHeaders(this.ResponseDataExpected, this.ResponseDataReceived, out error);

            return(headersTestResult);
        }
Exemplo n.º 2
0
        public static HeadersTestResult CompareHeaders(ResponseData ResponseDataExpected, ResponseData ResponseDataReceived, out string error)
        {
            error = null;
            try
            {
                HeadersTestResult headersTestResult = new HeadersTestResult();
                foreach (var header in ResponseDataExpected.Headers)
                {
                    if (header.Key.StartsWith("-"))
                    {
                        string aux = header.Key.Substring(1, header.Key.Length - 1);

                        if (ResponseDataReceived.Headers.ContainsKey(aux))
                        {
                            headersTestResult.headersOK.Add(aux);
                        }
                        else
                        {
                            headersTestResult.headersNotFoundInResponse.Add(aux);
                        }
                        continue;
                    }
                    else
                    {
                        string headerValueInResponse = "";
                        ResponseDataReceived.Headers.TryGetValue(header.Key, out headerValueInResponse);

                        if (string.IsNullOrEmpty(headerValueInResponse))
                        {
                            //response dont have my header.
                            headersTestResult.headersNotFoundInResponse.Add(header.Key);
                            continue;
                        }
                        else
                        {
                            //response has my header
                            if (headerValueInResponse.Trim() == header.Value.Trim())
                            {
                                headersTestResult.headersOK.Add(header.Value);
                            }
                            else
                            {
                                headersTestResult.headersWrongValue.Add(header.Value);
                            }
                        }
                    }
                }

                return(headersTestResult);
            }
            catch (Exception ex)
            {
                error = ex.Message;
            }
            return(null);
        }