XmlMessageEditor.cs
2.48 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
//*************************************************************************************************
// XmlMessageEditor.cs
// Owner: Mahipal Kante
//
// Web Test Plugin for editing XML string type Web Service Requests
//
// Copyright(c) Microsoft Corporation, 2010
//*************************************************************************************************
using Microsoft.VisualStudio.TestTools.WebTesting;
using WebTest.WebService.Plugin.ResultTab;
using WebTest.WebService.Plugin.Runtime;
namespace WebTest.WebService.Plugin.MessageEditors
{
/// <summary>
/// Editor for generic text based hierarchical messages such as XML, JSON etc
/// </summary>
public class XmlMessageEditor : IStringHttpBodyEditorPlugin
{
public XmlMessageEditor()
{
}
/// <summary>
/// Determine if this plugin supports a content type.
/// </summary>
/// <param name="contentType">The content type to test.</param>
/// <returns>Returns true if the plugin supports the specified content type.</returns>
public bool SupportsContentType(string contentType)
{
return (ContentHandlerFactory.GetHandler(contentType) != null);
}
/// <summary>
/// Create a UserControl to edit the specified bytes. This control will be hosted in the
/// plugin dialog which provides OK and Cancel buttons.
/// </summary>
/// <param name="contentType">The content type of the BinaryHttpBody.</param>
/// <param name="initialValue">
/// The bytes to edit. The bytes are the payload of a BinaryHttpBody.
/// </param>
/// <returns>A UserControl capable of displaying and editing the byte array
/// value of the specified content type.
/// </returns>
public object CreateEditor(string contentType, string initialValue)
{
contentHandler = ContentHandlerFactory.GetHandler(contentType);
contentHandler.MessageString = initialValue;
messageEditor = new MessageEditor(contentHandler);
return messageEditor;
}
/// <summary>
/// Gets the edited bytes after the OK button is clicked on the plugin dialog.
/// </summary>
public string GetNewValue()
{
messageEditor.UpdateContent();
return contentHandler.MessageString;
}
private MessageEditor messageEditor;
private ContentHandler contentHandler = null;
}
}