Esempio n. 1
0
        public static void VerifySelectOperationWithAutoRedirectMode(string requestUri, string operationName, UriAndMethodOperationSelector httpOperationSelector, bool shouldAutoRedirect)
        {
            string             matchedOperationName;
            bool               matchDifferByTrailingSlash;
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUri);
            bool               result  = httpOperationSelector.TrySelectOperation(request, out matchedOperationName, out matchDifferByTrailingSlash);

            Assert.IsTrue(result);
            Assert.AreEqual(matchedOperationName, operationName, String.Format("request {0} should match the operation {1}", requestUri, operationName));
            Assert.AreEqual(matchDifferByTrailingSlash, shouldAutoRedirect);

            Uri        originalUri = new Uri(requestUri);
            UriBuilder uriBuilder  = new UriBuilder(originalUri);

            uriBuilder.Path = originalUri.AbsolutePath.EndsWith("/") ? uriBuilder.Path.TrimEnd('/') : uriBuilder.Path + "/";
            Uri backSlashAlteredUri = uriBuilder.Uri;

            if (!shouldAutoRedirect)
            {
                matchedOperationName = httpOperationSelector.SelectOperation(request);
                Assert.AreEqual(matchedOperationName, operationName, String.Format("request {0} should match the operation {1}", requestUri, operationName));
            }
            else
            {
                ExceptionAssert.Throws <HttpResponseException>(
                    () => httpOperationSelector.SelectOperation(request),
                    (responseException) =>
                {
                    HttpResponseMessage expectedResponse = StandardHttpResponseMessageBuilder.CreateTemporaryRedirectResponse(request, originalUri, backSlashAlteredUri);
                    HttpAssert.AreEqual(expectedResponse, responseException.Response);
                });
            }
        }
Esempio n. 2
0
        public static void VerifySelectOperationWithIgnoreMode(string requestUri, string operationName, UriAndMethodOperationSelector httpOperationSelector)
        {
            HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, requestUri);
            string             matchedOperationName = httpOperationSelector.SelectOperation(message);

            Assert.AreEqual(matchedOperationName, operationName, String.Format("request {0} should match the operation {1}", requestUri, operationName));
        }