forked from NancyFx/Nancy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNodeWrapper.cs
More file actions
66 lines (59 loc) · 2.48 KB
/
Copy pathNodeWrapper.cs
File metadata and controls
66 lines (59 loc) · 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
66
namespace Nancy.Testing
{
using CsQuery.Implementation;
/// <summary>
/// Simple wrapper around a <see cref="DomElement"/>.
/// </summary>
public class NodeWrapper
{
private readonly DomElement element;
/// <summary>
/// Initializes a new instance of the <see cref="NodeWrapper"/> class, for
/// the provided <paramref name="element"/>.
/// </summary>
/// <param name="element">The dom element that should be wrapped.</param>
public NodeWrapper(DomElement element)
{
this.element = element;
}
/// <summary>
/// Tests for the presence of an attribute with the specified name.
/// </summary>
/// <param name="name">The name of the attribute to test for.</param>
/// <returns>True if the node contains an attribute with the specified name, false otherwise.</returns>
public bool HasAttribute(string name)
{
return this.element.HasAttribute(name);
}
public IndexHelper<string, string> Attributes
{
get { return new IndexHelper<string, string>(x => this.element.Attributes[x]); }
}
/// <summary>
/// Gets the inner text of the node.
/// </summary>
/// <value>A <see cref="string"/> containing the inner text of the node.</value>
public string InnerText
{
get { return this.element.InnerText; }
}
/// <summary>
/// Performs an implicit conversion from <see cref="DomElement"/> to <see cref="Nancy.Testing.NodeWrapper"/>.
/// </summary>
/// <param name="node">The <see cref="DomElement"/> that should be cast.</param>
/// <returns>An <see cref="NodeWrapper"/> instance, that contains the results of the cast.</returns>
public static implicit operator NodeWrapper(DomElement node)
{
return new NodeWrapper(node);
}
/// <summary>
/// Performs an implicit conversion from <see cref="Nancy.Testing.NodeWrapper"/> to <see cref="DomElement"/>.
/// </summary>
/// <param name="wrapper">The <see cref="NodeWrapper"/> that should be cast.</param>
/// <returns>A <see cref="DomElement"/> instance, that contains the results of the cast.</returns>
public static implicit operator DomElement(NodeWrapper wrapper)
{
return wrapper.element;
}
}
}