2 // TimestampInputFilterTest.cs - NUnit Test Cases for TimestampInputFilter
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
;
12 using Microsoft
.Web
.Services
.Timestamp
;
14 using System
.Web
.Services
.Protocols
;
17 // note: due to compiler confusion between classes and namespace (like Timestamp)
18 // I renamed the test namespace from "MonoTests.Microsoft.Web.Services.Timestamp"
19 // to "MonoTests.MS.Web.Services.Timestamp".
20 namespace MonoTests
.MS
.Web
.Services
.Timestamp
{
23 // 1. Inside the Web Services Enhancements Pipeline
24 // http://msdn.microsoft.com/library/en-us/dnwebsrv/html/insidewsepipe.asp
27 public class TimestampInputFilterTest
: Assertion
{
29 static string soapMinimal
= "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body /></soap:Envelope>";
30 static string soapExpiredEnvelope
= "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Header><wsu:Timestamp xmlns:wsu=\"http://schemas.xmlsoap.org/ws/2002/07/utility\"><wsu:Created>2002-11-14T19:03:27Z</wsu:Created><wsu:Expires>2002-11-14T19:08:27Z</wsu:Expires></wsu:Timestamp></soap:Header><soap:Body /></soap:Envelope>";
31 static string soapTimestampEnvelope
= "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Header><wsu:Timestamp xmlns:wsu=\"http://schemas.xmlsoap.org/ws/2002/07/utility\"><wsu:Created>2002-11-14T19:03:27Z</wsu:Created><wsu:Expires>2020-11-14T19:08:27Z</wsu:Expires></wsu:Timestamp></soap:Header><soap:Body /></soap:Envelope>";
34 public void NoTimestamp ()
36 SoapEnvelope env
= new SoapEnvelope ();
37 env
.LoadXml (soapMinimal
);
39 TimestampInputFilter tsInput
= new TimestampInputFilter ();
40 tsInput
.ProcessMessage (env
);
41 AssertEquals ("Envelope", soapMinimal
, env
.Envelope
.OuterXml
);
42 AllTests
.AssertEquals ("Created", DateTime
.MinValue
, env
.Context
.Timestamp
.Created
);
43 AllTests
.AssertEquals ("Expires", DateTime
.MaxValue
, env
.Context
.Timestamp
.Expires
);
47 public void ExpiredMessage ()
49 SoapEnvelope env
= new SoapEnvelope ();
50 env
.LoadXml (soapExpiredEnvelope
);
52 TimestampInputFilter tsInput
= new TimestampInputFilter ();
54 tsInput
.ProcessMessage (env
);
55 Fail ("Expected TimestampFault but got none");
57 catch (SoapHeaderException she
) {
58 // TimestampFault isn't public so we catch it's ancestor
59 if (she
.ToString ().StartsWith ("Microsoft.Web.Services.Timestamp.TimestampFault")) {
63 Fail ("Expected TimestampFault but got " + she
.ToString ());
66 Fail ("Expected TimestampFault but got " + e
.ToString ());
71 public void ValidMessage ()
73 SoapEnvelope env
= new SoapEnvelope ();
75 env
.LoadXml (soapTimestampEnvelope
);
77 TimestampInputFilter tsInput
= new TimestampInputFilter ();
78 tsInput
.ProcessMessage (env
);
79 AssertEquals ("Envelope", "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Header></soap:Header><soap:Body /></soap:Envelope>", env
.Envelope
.OuterXml
);
80 AssertEquals ("Created", "2002-11-14T19:03:27Z", env
.Context
.Timestamp
.Created
.ToString (WSTimestamp
.TimeFormat
));
81 AssertEquals ("Expires", "2020-11-14T19:08:27Z", env
.Context
.Timestamp
.Expires
.ToString (WSTimestamp
.TimeFormat
));