From ed3428e2e049880c3a8d95a2132be78d229ebe85 Mon Sep 17 00:00:00 2001 From: "Babanazar Kamyljanov [SSW]" <138548013+babakamyljanovssw@users.noreply.github.com> Date: Fri, 24 May 2024 08:54:29 +0800 Subject: [PATCH] =?UTF-8?q?Update=20Rule=20=E2=80=9Cwrite-integration-test?= =?UTF-8?q?s-to-validate-your-web-links/rule=E2=80=9D=20(#8593)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update Rule “write-integration-tests-to-validate-your-web-links/rule” * Update Rule “write-integration-tests-to-validate-your-web-links/rule” * Update Rule “write-integration-tests-to-validate-your-web-links/rule” --- .../rule.md | 96 +++++++++---------- 1 file changed, 45 insertions(+), 51 deletions(-) diff --git a/rules/write-integration-tests-to-validate-your-web-links/rule.md b/rules/write-integration-tests-to-validate-your-web-links/rule.md index a9f8ec0256e..1510936a352 100644 --- a/rules/write-integration-tests-to-validate-your-web-links/rule.md +++ b/rules/write-integration-tests-to-validate-your-web-links/rule.md @@ -12,70 +12,64 @@ created: 2020-03-11T22:50:56.000Z archivedreason: null guid: dfa6be65-2251-442d-8a9e-ead15d505dce --- - If you store your URL references in the application settings, you can create integration tests to validate them. -![Figure: URL for link stored in application settings](testURLSettings.gif) +![Figure: URL for link stored in application settings](testURLSettings.gif) **Sample Code: How to test the URL** - - ```cs [Test] - public void urlRulesToBetterInterfaces() - { - HttpStatusCode result = WebAccessTester.GetWebPageStatusCode(Settings.Default.urlRulesToBetterInterfaces); - Assert.IsTrue(result == HttpStatusCode.OK, result.ToString()); - } +public void urlRulesToBetterInterfaces() +{ + HttpStatusCode result = WebAccessTester.GetWebPageStatusCode(Settings.Default.urlRulesToBetterInterfaces); + Assert.IsTrue(result == HttpStatusCode.OK, result.ToString()); +} ``` - - **Sample Code: Method used to verify the Page** - - ```cs public class WebAccessTester - { - - public static HttpStatusCode GetWebPageStatusCode(string url) - { - HttpWebRequest req = ((HttpWebRequest)(WebRequest.Create(url))); - req.Proxy = new WebProxy(); - req.Proxy.Credentials = CredentialCache.DefaultCredentials; - HttpWebResponse resp = null; - try - { - resp = ((HttpWebResponse)(req.GetResponse())); - if (resp.StatusCode == HttpStatusCode.OK) - { - if (url.ToLower().IndexOf("redirect") == -1 && url.ToLower().IndexOf(resp.ResponseUri.AbsolutePath.ToLower()) == -1) - { - return HttpStatusCode.NotFound; - } - } - } - catch (System.Exception ex) - {JavaScript - while (!(ex == null)) - { - Console.WriteLine(ex.ToString()); - Console.WriteLine("INNER EXCEPTION"); - ex = ex.InnerException; - } - } - finally - { - if (!(resp == null)) - { - resp.Close(); - } - } - return resp.StatusCode; - } - } +{ + public static HttpStatusCode GetWebPageStatusCode(string url) + { + HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); + req.Proxy = new WebProxy(); + req.Proxy.Credentials = CredentialCache.DefaultCredentials; + HttpWebResponse resp = null; + + try + { + resp = (HttpWebResponse)req.GetResponse(); + if (resp.StatusCode == HttpStatusCode.OK) + { + if (url.ToLower().IndexOf("redirect") == -1 && url.ToLower().IndexOf(resp.ResponseUri.AbsolutePath.ToLower()) == -1) + { + return HttpStatusCode.NotFound; + } + } + } + catch (System.Exception ex) + { + while (!(ex == null)) + { + Console.WriteLine(ex.ToString()); + Console.WriteLine("INNER EXCEPTION"); + ex = ex.InnerException; + } + } + finally + { + if (!(resp == null)) + { + resp.Close(); + } + } + + return resp.StatusCode; + } +} ```