コード例 #1
0
        private static string MatchIgnoredParameters(HttpRequestExpectation expected, string actualPath)
        {
            if (expected.Url.IndexOf(IgnoreParameter, StringComparison.Ordinal) == -1) return actualPath;

            var segments = Regex.Split(expected.Url, IgnoreParameter);
            for (var i = 0; i < segments.Length; i++)
            {
                if (segments[i] == "") continue;
                var segmentEnd = actualPath.IndexOf(segments[i], StringComparison.Ordinal) + segments[i].Length;
                var nextSegmentStart = actualPath.Length;
                if (segments.Length != i + 1)
                {
                    if (segments[i + 1] != "")
                    {
                        nextSegmentStart = actualPath.IndexOf(segments[i + 1], StringComparison.Ordinal);
                    }
                }

                var parameterLength = nextSegmentStart - segmentEnd;

                if (parameterLength <= 0)
                {
                    continue;
                }

                var parameter = actualPath.Substring(segmentEnd, parameterLength);

                actualPath = actualPath.Replace(parameter, IgnoreParameter);
            }
            return actualPath;
        }
コード例 #2
0
 private static bool RequestAndExpectedHttpMethodAndPathsMatch(IOwinContext context, HttpRequestExpectation requestExpectation, string actualBody)
 {
     return
         requestExpectation.MatchesActualPath(context.Request.Uri.GetComponents(UriComponents.PathAndQuery, UriFormat.Unescaped)) &&
         requestExpectation.MatchesActualHttpMethod(context.Request.Method) &&
         requestExpectation.MatchesActualBody(actualBody);
 }
コード例 #3
0
 public static bool MatchesActualHttpMethod(this HttpRequestExpectation expected, string actualHttpMethod)
 {
     return(actualHttpMethod.Equals(expected.Method.ToString(), StringComparison.OrdinalIgnoreCase));
 }
コード例 #4
0
 private static bool RequestAndExpectedHttpMethodAndPathsMatch(IOwinContext context, HttpRequestExpectation requestExpectation)
 {
     return
         (requestExpectation.MatchesActualPath(context.Request.Uri.GetComponents(UriComponents.PathAndQuery, UriFormat.Unescaped)) &&
          requestExpectation.MatchesActualHttpMethod(context.Request.Method) &&
          requestExpectation.MatchesActualBody(context.Request.Body));
 }
コード例 #5
0
        public static bool MatchesActualPath(this HttpRequestExpectation expected, string actualPath)
        {
            var newPath = MatchIgnoredParameters(expected, actualPath);

            return(newPath.Equals(expected.Url));
        }
コード例 #6
0
 public static bool MatchBodyAccordingToPattern(this HttpRequestExpectation expected, string actualBody)
 {
     return(expected.BodyMatching.MatchBody(expected.Body, actualBody));
 }
コード例 #7
0
 public static bool MatchesActualBody(this HttpRequestExpectation expected, string actualBody)
 {
     return(string.IsNullOrEmpty(expected.Body) || actualBody.Equals(expected.Body));
 }