2 // ReceivedTest.cs - NUnit Test Cases for Received
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 ReceivedTest
: Assertion
{
24 public void Constructor_Uri ()
26 Uri uri
= new Uri ("http://www.go-mono.com/");
27 Received recv
= new Received (uri
);
28 AssertNotNull ("Received (uri)", recv
);
32 [ExpectedException (typeof (ArgumentNullException
))]
33 public void Constructor_UriNull ()
36 Received recv
= new Received (nullUri
);
40 [ExpectedException (typeof (ArgumentNullException
))]
41 public void Constructor_XmlElementNull ()
43 XmlElement nullXml
= null;
44 Received recv
= new Received (nullXml
);
48 public void Properties ()
50 string actor
= "http://www.go-mono.com/";
51 Uri uri
= new Uri (actor
);
52 Received recv
= new Received (uri
);
54 AssertEquals ("Actor", actor
, recv
.Actor
.AbsoluteUri
);
55 // compare longs not objects !!!
56 AllTests
.AssertEquals ("Delay", 0, recv
.Delay
);
57 // we dont check default value because it's UtcNow (too late ;-)
58 DateTime testDate
= DateTime
.FromFileTime (0xDEADC0DE); // 12/31/1600
59 recv
.Value
= testDate
;
60 AssertEquals ("Value", testDate
, recv
.Value
);
64 public void Roundtrips ()
66 string actor
= "http://www.go-mono.com/";
67 Uri uri
= new Uri (actor
);
68 Received recv
= new Received (uri
);
69 recv
.Value
= DateTime
.FromFileTime (0xDEADC0DE); // 12/31/1600
71 XmlDocument doc
= new XmlDocument ();
72 XmlElement xel
= recv
.GetXml (doc
);
73 Assertion
.AssertEquals ("Xml", "<wsu:Received xmlns:wsu=\"http://schemas.xmlsoap.org/ws/2002/07/utility\">1600-12-31T19:06:13Z</wsu:Received>", xel
.OuterXml
);
76 Received recv2
= new Received (xel
);
77 Assertion
.Fail ("Expected TimestampFormatException but got none");
79 catch (TimestampFormatException e
) {
80 // not logical but as documented
81 if (e
.Message
!= TimestampFormatException
.MissingActorAttributeInReceivedElement
)
82 Assertion
.Fail ("Invalid TimestampFormatException.Message -> MissingActorAttributeInReceivedElement");
85 Assertion
.Fail ("Expected TimestampFormatException but got: " + e
.ToString ());
89 Received recv3
= new Received (uri
);
91 Assertion
.Fail ("Expected TimestampFormatException but got none");
93 catch (TimestampFormatException e
) {
94 // not logical but as documented
95 if (e
.Message
!= TimestampFormatException
.MissingActorAttributeInReceivedElement
)
96 Assertion
.Fail ("Invalid TimestampFormatException.Message -> MissingActorAttributeInReceivedElement");
99 Assertion
.Fail ("Expected TimestampFormatException but got: " + e
.ToString ());
103 public void TestDelay ()
105 string actor
= "http://www.go-mono.com/";
106 Uri uri
= new Uri (actor
);
107 Received recv
= new Received (uri
);
109 recv
.Value
= DateTime
.FromFileTime (0xDEADC0DE); // 12/31/1600
111 XmlDocument doc
= new XmlDocument ();
112 XmlElement xel
= recv
.GetXml (doc
);
113 // Actor isn't present
114 AssertEquals ("Xml", "<wsu:Received Delay=\"60\" xmlns:wsu=\"http://schemas.xmlsoap.org/ws/2002/07/utility\">1600-12-31T19:06:13Z</wsu:Received>", xel
.OuterXml
);
116 string xml
= "<wsu:Received Actor=\"http://www.go-mono.com/\" Delay=\"60\" xmlns:wsu=\"http://schemas.xmlsoap.org/ws/2002/07/utility\">1600-12-31T19:06:13Z</wsu:Received>";
119 // FIXME: Shouldn't need this - Bug in WSE ?
120 xel
.SetAttribute (WSTimestamp
.AttributeNames
.Actor
, actor
);
121 Received recv2
= new Received (xel
);
122 AssertEquals ("Actor", recv
.Actor
.AbsoluteUri
, recv2
.Actor
.AbsoluteUri
);
123 AssertEquals ("Delay", recv
.Delay
, recv2
.Delay
);
124 // compare DateTime not objects !!!
125 AllTests
.AssertEquals ("Value", recv
.Value
, recv2
.Value
);
127 Received recv3
= new Received (uri
);
128 recv3
.LoadXml (doc
.DocumentElement
);
129 AssertEquals ("Actor", recv
.Actor
.AbsoluteUri
, recv3
.Actor
.AbsoluteUri
);
130 AssertEquals ("Delay", recv
.Delay
, recv3
.Delay
);
131 // compare DateTime not objects !!!
132 AllTests
.AssertEquals ("Value", recv
.Value
, recv3
.Value
);