public static string GetUrlPostContents(string url, NameValueCollection nameValueCollection) { try { using (WebClient webClient = new WebClient()) { string str1 = url.Substring(0, url.LastIndexOf("/")); byte[] resp = webClient.UploadValues(url, "POST", nameValueCollection); string str2 = Encoding.UTF8.GetString(resp); if (!str2.Contains("<base")) { str2 = str2.Replace("<head>", "<head><base href=\"{0}\">".FormatWith(str1)); } return(str2); } } catch (Exception ex) { throw Exceptional.Create <Exception>("The following error occured while connecting to:\n{0}\nError:\n{1}", url, ex.Message); } }
private static void VerifyWithException(Action action) { try { action(); } catch (Exception ex) { var webEx = ex.InnerException as WebException; if (webEx != null && webEx.Status == WebExceptionStatus.ConnectFailure) { throw Exceptional.Create <Exception>(ex, "Unable to connect to the hosted/remote server. Please check your connection. \r\n\r\n"); } if (webEx != null && webEx.Response != null && (webEx.Response as HttpWebResponse).StatusCode == HttpStatusCode.NotFound) { throw Exceptional.Create <Exception>(ex, "Please verify your code for the following steps. \r\n {0} \r\n {1} \r\n\r\n", "1. ApprovalTests.Core.Asp.Mvc.UnitTestBootStrap.Register() added in Global.asax.cs", "2. Test class is inherited from ApprovalTests.Asp.Mvc.TestableController<T>"); } else { throw; } } }
private static void VerifyWithException(Action action) { try { action(); } catch (Exception ex) { var webEx = ex.InnerException as WebException; if (webEx != null && webEx.Status == WebExceptionStatus.ConnectFailure) { throw Exceptional.Create <Exception>(ex, "Unable to connect to the hosted/remote server. Please check your connection. \r\n\r\n"); } if (webEx != null && webEx.Response != null && (webEx.Response as HttpWebResponse).StatusCode == HttpStatusCode.NotFound) { var message = @"404 Error: Page not Found. ApprovalTests.Asp needs a bootstrap to work. Please verify your Global.asax.cs file has the following code protected void Application_Start() { ... UnitTestBootStrap.RegisterWithDebugCondition(); } See an Example Test at: https://github.com/approvals/Approvals.Net.Asp/blob/master/ApprovalTests.Asp.Tests/Mvc/MvcTest.cs "; throw new Exception(message, ex); } else { throw; } } }