Summary

Class:WireMock.RequestMessage
Assembly:WireMock.Net
File(s):C:\Users\Stef\Documents\GitHub\WireMock.Net\src\WireMock.Net\RequestMessage.cs
Covered lines:49
Uncovered lines:1
Coverable lines:50
Total lines:127
Line coverage:98%
Branch coverage:90%

Metrics

MethodCyclomatic complexity  NPath complexity  Sequence coverage  Branch coverage  
.ctor(...)4410080
GetParameter(...)32100100

File(s)

C:\Users\Stef\Documents\GitHub\WireMock.Net\src\WireMock.Net\RequestMessage.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using JetBrains.Annotations;
 5using WireMock.Util;
 6using WireMock.Validation;
 7using System.Text;
 8
 9namespace WireMock
 10{
 11    /// <summary>
 12    /// The request.
 13    /// </summary>
 14    public class RequestMessage
 15    {
 16        /// <summary>
 17        /// Gets the url.
 18        /// </summary>
 319        public string Url { get; }
 20
 21        /// <summary>
 22        /// Gets the DateTime.
 23        /// </summary>
 1324        public DateTime DateTime { get; set; }
 25
 26        /// <summary>
 27        /// Gets the path.
 28        /// </summary>
 3229        public string Path { get; }
 30
 31        /// <summary>
 32        /// Gets the method.
 33        /// </summary>
 1734        public string Method { get; }
 35
 36        /// <summary>
 37        /// Gets the headers.
 38        /// </summary>
 1339        public IDictionary<string, string> Headers { get; }
 40
 41        /// <summary>
 42        /// Gets the cookies.
 43        /// </summary>
 344        public IDictionary<string, string> Cookies { get; }
 45
 46        /// <summary>
 47        /// Gets the query.
 48        /// </summary>
 7449        public IDictionary<string, WireMockList<string>> Query { get; } = new Dictionary<string, WireMockList<string>>()
 50
 51        /// <summary>
 52        /// Gets the bodyAsBytes.
 53        /// </summary>
 154        public byte[] BodyAsBytes { get; }
 55
 56        /// <summary>
 57        /// Gets the body.
 58        /// </summary>
 1359        public string Body { get; }
 60
 61        /// <summary>
 62        /// Gets the body encoding.
 63        /// </summary>
 064        public Encoding BodyEncoding { get; }
 65
 66        /// <summary>
 67        /// Initializes a new instance of the <see cref="RequestMessage"/> class.
 68        /// </summary>
 69        /// <param name="url">The original url.</param>
 70        /// <param name="verb">The verb.</param>
 71        /// <param name="bodyAsBytes">The bodyAsBytes byte[].</param>
 72        /// <param name="body">The body string.</param>
 73        /// <param name="bodyEncoding">The body encoding</param>
 74        /// <param name="headers">The headers.</param>
 75        /// <param name="cookies">The cookies.</param>
 5676        public RequestMessage([NotNull] Uri url, [NotNull] string verb, [CanBeNull] byte[] bodyAsBytes = null, [CanBeNul
 5677        {
 5678            Check.NotNull(url, nameof(url));
 5679            Check.NotNull(verb, nameof(verb));
 80
 5681            Url = url.ToString();
 5682            Path = url.AbsolutePath;
 5683            Method = verb.ToLower();
 5684            BodyAsBytes = bodyAsBytes;
 5685            Body = body;
 5686            BodyEncoding = bodyEncoding;
 5687            Headers = headers;
 5688            Cookies = cookies;
 89
 5690            string query = url.Query;
 5691             if (!string.IsNullOrEmpty(query))
 592            {
 593                 if (query.StartsWith("?"))
 594                {
 595                    query = query.Substring(1);
 596                }
 97
 598                Query = query.Split('&').Aggregate(
 599                    new Dictionary<string, WireMockList<string>>(),
 5100                    (dict, term) =>
 16101                    {
 16102                        var parts = term.Split('=');
 16103                        var key = parts[0];
 16104                         if (!dict.ContainsKey(key))
 12105                        {
 12106                            dict.Add(key, new WireMockList<string>());
 12107                        }
 5108
 16109                         if (parts.Length == 2)
 15110                            dict[key].Add(parts[1]);
 5111
 16112                        return dict;
 16113                    });
 5114            }
 56115        }
 116
 117        /// <summary>
 118        /// The get a query parameter.
 119        /// </summary>
 120        /// <param name="key">The key.</param>
 121        /// <returns>The query parameter.</returns>
 122        public List<string> GetParameter(string key)
 7123        {
 7124             return Query.ContainsKey(key) ? Query[key] : null;
 7125        }
 126    }
 127}