WebTestDetail.cs
3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//*************************************************************************************************
// WebTestDetail.cs
// Owner: Mahipal Kante
//
// Details of WebTest
//
// Copyright(c) Microsoft Corporation, 2010
//*************************************************************************************************
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EnvDTE80;
using EnvDTE;
using Microsoft.VisualStudio.TestTools.WebTesting;
namespace WebTest.WebService.Plugin.ResultTab
{
/// <summary>
/// Details of a Declarative WebTest project Item
/// </summary>
public class WebTestDetail
{
/// <summary>
///
/// </summary>
/// <param name="fullPath"></param>
/// <param name="applicationObject"></param>
public WebTestDetail(string fullPath, DTE2 applicationObject)
{
this.FullPath = fullPath;
this._applicationObject = applicationObject;
}
/// <summary>
/// Web Test object
/// </summary>
public DeclarativeWebTest WebTest
{
get
{
if (webTest == null || (new FileInfo(FullPath).LastWriteTime > LastSavedTimeStamp))
{
webTest = DeclarativeWebTestSerializer.Open(FullPath);
LastSavedTimeStamp = new FileInfo(FullPath).LastWriteTime;
}
return webTest;
}
set
{
webTest = value;
LastSavedTimeStamp = new FileInfo(FullPath).LastWriteTime;
}
}
/// <summary>
/// Path to the WebTest file
/// </summary>
public string FullPath
{
get;
set;
}
/// <summary>
/// LastSavedTimeStamp
/// </summary>
public DateTime LastSavedTimeStamp
{
get;
set;
}
/// <summary>
/// ProjectItem of DTE
/// </summary>
public ProjectItem ProjectItem
{
get;
set;
}
/// <summary>
/// If there are pending changes, save first, as we are going to make our
/// changes to the file directly.
/// </summary>
public void PrepareToSave()
{
if (this.ProjectItem != null && this.ProjectItem.Document != null)
{
this.ProjectItem.Document.Close(vsSaveChanges.vsSaveChangesPrompt);
}
}
/// <summary>
/// Save WebTest to file
/// </summary>
public void Save()
{
DeclarativeWebTestSerializer.Save(this.WebTest, this.FullPath);
this.LastSavedTimeStamp = DateTime.Now;
if (this.ProjectItem != null)
{
Window window = this.ProjectItem.Open();
window.Activate();
}
}
/// <summary>
/// Parse parameters from all items of Web Test
/// </summary>
/// <returns></returns>
public List<string> GetParameterList()
{
List<string> list = new List<string>();
DeclarativeWebTest w = WebTest;
for (int i = 1; i <= w.Items.Count; i++)
{
WebTestRequest requestInWebTest = webTest.GetItem(i) as WebTestRequest;
if (requestInWebTest != null)
{
foreach (ExtractionRuleReference reference in requestInWebTest.ExtractionRuleReferences)
{
list.Add(reference.ContextParameterName);
}
}
}
return list;
}
private DTE2 _applicationObject;
private DeclarativeWebTest webTest = null;
}
}