예제 #1
0
        public void EnvironmentDictionaryVerification(HostType hostType)
        {
            using (ApplicationDeployer deployer = new ApplicationDeployer())
            {
                string applicationUrl = deployer.Deploy(hostType, Configuration);

                List <KeyValuePair <string, string[]> > additionalHeaders = new List <KeyValuePair <string, string[]> >();
                additionalHeaders.Add(new KeyValuePair <string, string[]>("CustomHeader1", new string[] { "CustomHeaderValue1" }));

                string targetUrl       = applicationUrl + "/Test/?query=value";
                string getResponseText = HttpClientUtility.GetResponseTextFromUrl(targetUrl, additionalHeaders);
                Uri    targetUri       = new Uri(targetUrl);
                Dictionary <string, string> owinDictionary = ParseResponse(getResponseText);

                #region Utility function
                Func <string, bool> validatePath = (httpMethod) =>
                {
                    if (hostType == HostType.IIS)
                    {
                        WebDeployer webDeployer          = (WebDeployer)deployer.Application;
                        string      virtualDirectoryName = webDeployer.Application.Path.TrimStart(new char[] { '/' });
                        if (owinDictionary["owin.RequestPath"] != "/Test/" || owinDictionary["owin.RequestPathBase"] != "/" + virtualDirectoryName)
                        {
                            Assert.True(false, string.Format("{0} environment dictionary verification failed. At least one of the values returned by the server does not match the expected value. String returned by server : {1}", httpMethod, getResponseText));
                        }
                    }
                    else
                    {
                        if (owinDictionary["owin.RequestPath"].TrimStart(new char[] { '/' }) != targetUri.AbsolutePath.TrimStart(new char[] { '/' }) ||
                            !string.IsNullOrWhiteSpace(owinDictionary["owin.RequestPathBase"]))
                        {
                            Assert.True(false, string.Format("{0} environment dictionary verification failed. At least one of the values returned by the server does not match the expected value. String returned by server : {1}", httpMethod, getResponseText));
                        }
                    }

                    return(true);
                };
                #endregion

                //GET
                validatePath("GET");

                if (owinDictionary["CustomHeader1"] != "CustomHeaderValue1" || !owinDictionary["Host"].Contains(targetUri.Host) ||
                    owinDictionary["owin.RequestMethod"] != "GET" || owinDictionary["owin.RequestProtocol"] != "HTTP/1.1" || owinDictionary["owin.RequestQueryString"] != targetUri.Query.TrimStart(new char[] { '?' }) ||
                    owinDictionary["owin.RequestScheme"] != targetUri.Scheme || owinDictionary["owin.Version"] != "1.0")
                {
                    Assert.True(false, string.Format("GET environment dictionary verification failed. At least one of the values returned by the server does not match the expected value. String returned by server : {0}", getResponseText));
                }

                //POST
                string postResponseText = HttpClientUtility.PostResponseTextFromUrl(targetUrl, additionalHeaders);
                owinDictionary = ParseResponse(postResponseText);
                validatePath("POST");

                if (owinDictionary["CustomHeader1"] != "CustomHeaderValue1" || !owinDictionary["Host"].Contains(targetUri.Host) ||
                    owinDictionary["owin.RequestMethod"] != "POST" || owinDictionary["owin.RequestProtocol"] != "HTTP/1.1" ||
                    owinDictionary["owin.RequestQueryString"] != targetUri.Query.TrimStart(new char[] { '?' }) ||
                    owinDictionary["owin.RequestScheme"] != targetUri.Scheme || owinDictionary["owin.Version"] != "1.0")
                {
                    Assert.True(false, string.Format("POST environment dictionary verification failed. At least one of the values returned by the server does not match the expected value. String returned by server : {0}", postResponseText));
                }
            }
        }
예제 #2
0
        public void Static_DefaultFilesDefaultSetup(HostType hostType)
        {
            using (ApplicationDeployer deployer = new ApplicationDeployer())
            {
                string applicationUrl = deployer.Deploy(hostType, FolderWithDefaultFileConfiguration);

                HttpResponseMessage response = null;

                /*GET requests*/
                //Directory with no default file - request path ending with '/'
                HttpClientUtility.GetResponseTextFromUrl(applicationUrl + "RequirementFiles/", out response);
                Assert.Equal <HttpStatusCode>(HttpStatusCode.NotFound, response.StatusCode);

                //Directory with no default file - request path not ending with '/'
                HttpClientUtility.GetResponseTextFromUrl(applicationUrl + "RequirementFiles", out response);
                Assert.Equal <HttpStatusCode>(HttpStatusCode.NotFound, response.StatusCode);

                //Directory with a default file - request path ending with a '/'
                var responseText = HttpClientUtility.GetResponseTextFromUrl(applicationUrl + "RequirementFiles/Dir1/", out response);
                Assert.Equal <HttpStatusCode>(HttpStatusCode.OK, response.StatusCode);
                Assert.Equal <bool>(true, responseText.Contains(@"Dir1\Default.html"));

                //Directory with a default file - request path not ending with a '/'
                responseText = HttpClientUtility.GetResponseTextFromUrl(applicationUrl + "RequirementFiles/Dir1", out response);
                Assert.Equal <HttpStatusCode>(HttpStatusCode.OK, response.StatusCode);
                Assert.Equal <bool>(true, responseText.Contains(@"Dir1\Default.html"));

                //Directory with a default file - request path ending with a '/' & case sensitivity check
                responseText = HttpClientUtility.GetResponseTextFromUrl(applicationUrl + "reQuirementFiles/dir1/", out response);
                Assert.Equal <HttpStatusCode>(HttpStatusCode.OK, response.StatusCode);
                Assert.Equal <bool>(true, responseText.Contains(@"Dir1\Default.html"));

                /*HEAD requests*/
                //Directory with no default file - request path ending with '/'
                responseText = HttpClientUtility.HeadResponseTextFromUrl(applicationUrl + "RequirementFiles/", out response);
                Assert.Equal <HttpStatusCode>(HttpStatusCode.NotFound, response.StatusCode);

                //Directory with no default file - request path not ending with '/'
                responseText = HttpClientUtility.HeadResponseTextFromUrl(applicationUrl + "RequirementFiles", out response);
                Assert.Equal <HttpStatusCode>(HttpStatusCode.NotFound, response.StatusCode);

                //Directory with a default file - request path ending with a '/'
                responseText = HttpClientUtility.HeadResponseTextFromUrl(applicationUrl + "RequirementFiles/Dir1/", out response);
                Assert.Equal <HttpStatusCode>(HttpStatusCode.OK, response.StatusCode);
                Assert.Equal <string>(string.Empty, responseText);

                //Directory with a default file - request path not ending with a '/'
                responseText = HttpClientUtility.HeadResponseTextFromUrl(applicationUrl + "RequirementFiles/Dir1", out response);
                Assert.Equal <HttpStatusCode>(HttpStatusCode.OK, response.StatusCode);
                Assert.Equal <string>(string.Empty, responseText);

                //Directory with a default file - request path ending with a '/' & case sensitivity check
                responseText = HttpClientUtility.HeadResponseTextFromUrl(applicationUrl + "reQuirementFiles/dir1/", out response);
                Assert.Equal <HttpStatusCode>(HttpStatusCode.OK, response.StatusCode);
                Assert.Equal <string>(string.Empty, responseText);

                /*POST requests - no file to be served*/
                //Directory with no default file - request path ending with '/'
                HttpClientUtility.PostResponseTextFromUrl(applicationUrl + "RequirementFiles/", out response);
                Assert.Equal <HttpStatusCode>(HttpStatusCode.NotFound, response.StatusCode);

                //Directory with a default file - request path not ending with a '/'
                HttpClientUtility.PostResponseTextFromUrl(applicationUrl + "RequirementFiles/Dir1/", out response);
                Assert.Equal <HttpStatusCode>(HttpStatusCode.NotFound, response.StatusCode);
            }
        }