2 // TimestampTest.cs - NUnit Test Cases for Timestamp
5 // Sebastien Pouliot (spouliot@motus.com)
7 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
10 using NUnit
.Framework
;
11 using Microsoft
.Web
.Services
.Timestamp
;
15 // note: due to compiler confusion between classes and namespace (like Timestamp)
16 // I renamed the test namespace from "MonoTests.Microsoft.Web.Services.Timestamp"
17 // to "MonoTests.MS.Web.Services.Timestamp".
18 namespace MonoTests
.MS
.Web
.Services
.Timestamp
{
21 public class TimestampTest
: Assertion
{
23 // compiler conflict between namespace Timestamp and class Timestamp
24 private Microsoft
.Web
.Services
.Timestamp
.Timestamp ts
;
26 private static string empty
= "<wsu:Timestamp xmlns:wsu=\"http://schemas.xmlsoap.org/ws/2002/07/utility\" />";
27 private static string test1
= "<wsu:Timestamp xmlns:wsu=\"http://schemas.xmlsoap.org/ws/2002/07/utility\"><wsu:Created>2001-09-13T08:42:00Z</wsu:Created><wsu:Expires>2001-10-13T09:00:00Z</wsu:Expires></wsu:Timestamp>";
28 private static string test2
= "<wsu:Timestamp xmlns:wsu=\"http://schemas.xmlsoap.org/ws/2002/07/utility\"><wsu:Created>2001-09-13T08:42:00Z</wsu:Created><wsu:Expires>2001-10-13T09:00:00Z</wsu:Expires><wsu:Received Actor=\"http://x.com/\" Delay=\"60000\">2001-09-13T08:44:00Z</wsu:Received></wsu:Timestamp>";
29 private static string test3
= "<wsu:Timestamp xmlns:wsu=\"http://schemas.xmlsoap.org/ws/2002/07/utility\"><wsu:Created wsu:Id=\"createdId\">2001-09-13T08:42:00Z</wsu:Created><wsu:Expires wsu:Id=\"expiresId\">2001-10-13T09:00:00Z</wsu:Expires><wsu:Received Actor=\"http://x.com/\" Delay=\"60000\">2001-09-13T08:44:00Z</wsu:Received></wsu:Timestamp>";
30 private static string test4
= "<wsu:Timestamp wsu:Id=\"timestampId\" xmlns:wsu=\"http://schemas.xmlsoap.org/ws/2002/07/utility\"><wsu:Created wsu:Id=\"createdId\">2001-09-13T08:42:00Z</wsu:Created><wsu:Expires wsu:Id=\"expiresId\">2001-10-13T09:00:00Z</wsu:Expires><wsu:Received Actor=\"http://x.com/\" Delay=\"60000\" wsu:Id=\"receivedId\">2001-09-13T08:44:00Z</wsu:Received></wsu:Timestamp>";
35 ts
= new Microsoft
.Web
.Services
.Timestamp
.Timestamp ();
39 public void Properties ()
42 DateTime testTime
= DateTime
.UtcNow
;
45 AssertEquals ("Created (default)", DateTime
.MinValue
, ts
.Created
);
46 AssertEquals ("Expires (default)", DateTime
.MaxValue
, ts
.Expires
);
47 AllTests
.AssertEquals ("TTL (default)", 300000, ts
.Ttl
);
50 AllTests
.AssertEquals ("TTL (test)", 1, ts
.Ttl
);
52 AllTests
.AssertEquals ("TTL (0)", 0, ts
.Ttl
);
53 AssertEquals ("Expires (0)", DateTime
.MaxValue
, ts
.Expires
);
54 AssertNotNull ("Receivers", ts
.Receivers
);
55 AssertEquals ("Receivers.Count", 0, ts
.Receivers
.Count
);
59 [ExpectedException (typeof (ArgumentException
))]
60 public void Ttl_Negative ()
66 [ExpectedException (typeof (TimestampFormatException
))]
67 public void CheckInvalid ()
69 // default object is incomplete
73 // Note: All valid (no exception are thrown) but all EXPIRED !
75 public void CheckValid ()
77 XmlDocument doc
= new XmlDocument ();
79 ts
.LoadXml (doc
.DocumentElement
);
83 ts
.LoadXml (doc
.DocumentElement
);
87 ts
.LoadXml (doc
.DocumentElement
);
91 ts
.LoadXml (doc
.DocumentElement
);
98 XmlDocument doc
= new XmlDocument ();
99 XmlElement xel
= ts
.GetXml (doc
);
101 AssertEquals ("Xml", empty
, xel
.OuterXml
);
103 ts
.Ttl
= 60000; // one minute
104 xel
= ts
.GetXml (doc
);
105 // TTL has no change in XML
106 AssertEquals ("Xml", empty
, xel
.OuterXml
);
110 [ExpectedException (typeof (ArgumentNullException
))]
111 public void LoadXml_Null ()
117 [ExpectedException (typeof (ArgumentException
))]
118 public void LoadXml_BadElement ()
120 XmlDocument doc
= new XmlDocument ();
121 // bad element (Timestamp case is invalid)
122 doc
.LoadXml ("<wsu:timeStamp xmlns:wsu=\"http://schemas.xmlsoap.org/ws/2002/07/utility\" />");
123 ts
.LoadXml (doc
.DocumentElement
);
127 [ExpectedException (typeof (ArgumentException
))]
128 public void LoadXml_BadNamespace ()
130 XmlDocument doc
= new XmlDocument ();
131 // bad namespace (invalid year in URL)
132 doc
.LoadXml ("<wsu:Timestamp xmlns:wsu=\"http://schemas.xmlsoap.org/ws/2003/07/utility\" />");
133 ts
.LoadXml (doc
.DocumentElement
);
136 // sample taken from http://msdn.microsoft.com/library/en-us/dnglobspec/html/ws-security.asp
138 public void LoadXml ()
140 XmlDocument doc
= new XmlDocument ();
142 ts
.LoadXml (doc
.DocumentElement
);
144 XmlElement xel
= ts
.GetXml (doc
);
145 AssertEquals ("Xml", test1
, xel
.OuterXml
);
146 AssertEquals ("Xml Actor", "", ts
.Actor
);
147 AssertEquals ("Xml Created", "2001-09-13T08:42:00Z", ts
.Created
.ToString (WSTimestamp
.TimeFormat
));
148 AssertEquals ("Xml Expires", "2001-10-13T09:00:00Z", ts
.Expires
.ToString (WSTimestamp
.TimeFormat
));
149 AssertEquals ("Xml Receivers.Count", 0, ts
.Receivers
.Count
);
150 AllTests
.AssertEquals ("Xml Ttl", 300000, ts
.Ttl
);
153 // sample taken from http://msdn.microsoft.com/library/en-us/dnglobspec/html/ws-security.asp
155 public void LoadXmlWithOneIntermediary ()
157 XmlDocument doc
= new XmlDocument ();
159 ts
.LoadXml (doc
.DocumentElement
);
161 XmlElement xel
= ts
.GetXml (doc
);
162 AssertEquals ("Xml", test2
, xel
.OuterXml
);
163 AssertEquals ("Xml Actor", "", ts
.Actor
); // Actor is part of <Received> element
164 AssertEquals ("Xml Created", "2001-09-13T08:42:00Z", ts
.Created
.ToString (WSTimestamp
.TimeFormat
));
165 AssertEquals ("Xml Expires", "2001-10-13T09:00:00Z", ts
.Expires
.ToString (WSTimestamp
.TimeFormat
));
166 AssertEquals ("Xml Receivers.Count", 1, ts
.Receivers
.Count
);
167 AllTests
.AssertEquals ("Xml Ttl", 300000, ts
.Ttl
);
170 // WSE supports wsu:Id for Created and Expires elements
172 public void LoadXmlWithCreatedAndExpiresIds ()
174 XmlDocument doc
= new XmlDocument ();
176 ts
.LoadXml (doc
.DocumentElement
);
178 XmlElement xel
= ts
.GetXml (doc
);
179 AssertEquals ("Xml", test3
, xel
.OuterXml
);
180 AssertEquals ("Xml Actor", "", ts
.Actor
); // Actor is part of <Received> element
181 AssertEquals ("Xml Created", "2001-09-13T08:42:00Z", ts
.Created
.ToString (WSTimestamp
.TimeFormat
));
182 AssertEquals ("Xml Expires", "2001-10-13T09:00:00Z", ts
.Expires
.ToString (WSTimestamp
.TimeFormat
));
183 AssertEquals ("Xml Receivers.Count", 1, ts
.Receivers
.Count
);
184 AllTests
.AssertEquals ("Xml Ttl", 300000, ts
.Ttl
);
187 // WSE _doesn't_ support wsu:Id for Timestamp and Received elements
189 public void LoadXmlWithAllIds ()
191 XmlDocument doc
= new XmlDocument ();
193 ts
.LoadXml (doc
.DocumentElement
);
195 XmlElement xel
= ts
.GetXml (doc
);
196 // FIXME (WSE) AssertEquals ("Xml", test4, xel.OuterXml);
197 AssertEquals ("Xml Actor", "", ts
.Actor
); // Actor is part of <Received> element
198 AssertEquals ("Xml Created", "2001-09-13T08:42:00Z", ts
.Created
.ToString (WSTimestamp
.TimeFormat
));
199 AssertEquals ("Xml Expires", "2001-10-13T09:00:00Z", ts
.Expires
.ToString (WSTimestamp
.TimeFormat
));
200 AssertEquals ("Xml Receivers.Count", 1, ts
.Receivers
.Count
);
201 AllTests
.AssertEquals ("Xml Ttl", 300000, ts
.Ttl
);