Lagt till response URL validerare
git-tfs-id: [https://tfs.rsv.se/tfs/LoadTestCollection]$/VSTT-Plugins;C1338
Showing
1 changed file
with
39 additions
and
1 deletions
... | @@ -9,6 +9,7 @@ using System.Text; | ... | @@ -9,6 +9,7 @@ using System.Text; |
9 | using System.Threading.Tasks; | 9 | using System.Threading.Tasks; |
10 | using Microsoft.VisualStudio.TestTools.WebTesting; | 10 | using Microsoft.VisualStudio.TestTools.WebTesting; |
11 | using System.ComponentModel; | 11 | using System.ComponentModel; |
12 | using System.Text.RegularExpressions; | ||
12 | 13 | ||
13 | namespace LIL_VSTT_Plugins | 14 | namespace LIL_VSTT_Plugins |
14 | { | 15 | { |
... | @@ -37,4 +38,41 @@ namespace LIL_VSTT_Plugins | ... | @@ -37,4 +38,41 @@ namespace LIL_VSTT_Plugins |
37 | } | 38 | } |
38 | } | 39 | } |
39 | } | 40 | } |
40 | } | 41 | |
42 | [DisplayName("Validate Response URL")] | ||
43 | [Description("(C) Mårten\r\nValiderar att en Response URL har ett visst värde eller inte.")] | ||
44 | public class ValidateResponseURL : ValidationRule | ||
45 | { | ||
46 | Regex rxRegExp = null; | ||
47 | |||
48 | [DisplayName("Regular expression"), DefaultValue(""), Description("Uttrycket som ska matcha Response URL")] | ||
49 | public string strRegExp { get; set; } | ||
50 | |||
51 | [DisplayName("Pass if found"), DefaultValue(false), Description("Om uttrycket matchar ska testet failas eller inte?")] | ||
52 | public bool boolPassIfFound { get; set; } | ||
53 | |||
54 | public override void Validate(object sender, ValidationEventArgs e) | ||
55 | { | ||
56 | e.IsValid = false; | ||
57 | e.Message = "Default triggades. False! Check the code!!"; | ||
58 | |||
59 | if (rxRegExp == null) | ||
60 | { | ||
61 | rxRegExp = new Regex(strRegExp); | ||
62 | } | ||
63 | if (rxRegExp.IsMatch(e.Response.ResponseUri.AbsoluteUri)) | ||
64 | { | ||
65 | e.IsValid = boolPassIfFound; | ||
66 | e.Message = "" + e.Response.ResponseUri.AbsoluteUri + " matchade uttrycket!"; | ||
67 | } | ||
68 | else | ||
69 | { | ||
70 | e.IsValid = !boolPassIfFound; | ||
71 | e.Message = "" + e.Response.ResponseUri.AbsoluteUri + " matchade inte uttrycket!"; | ||
72 | } | ||
73 | |||
74 | } | ||
75 | |||
76 | } | ||
77 | |||
78 | } | ... | ... |
-
Please register or sign in to post a comment