Transaction now has limited support for PromotableSinglePhaseEnlistment
[mono.git] / mcs / class / System.ServiceModel.Discovery / Test / System.ServiceModel.Discovery / AnnouncementClientTest.cs
1 //
2 // Author: Atsushi Enomoto <atsushi@ximian.com>
3 //
4 // Copyright (C) 2010 Novell, Inc (http://www.novell.com)
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining
7 // a copy of this software and associated documentation files (the
8 // "Software"), to deal in the Software without restriction, including
9 // without limitation the rights to use, copy, modify, merge, publish,
10 // distribute, sublicense, and/or sell copies of the Software, and to
11 // permit persons to whom the Software is furnished to do so, subject to
12 // the following conditions:
13 // 
14 // The above copyright notice and this permission notice shall be
15 // included in all copies or substantial portions of the Software.
16 // 
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 //
25 using System;
26 using System.Collections.Generic;
27 using System.Collections.ObjectModel;
28 using System.Linq;
29 using System.ServiceModel;
30 using System.ServiceModel.Channels;
31 using System.ServiceModel.Description;
32 using System.ServiceModel.Discovery;
33 using System.ServiceModel.Dispatcher;
34 using NUnit.Framework;
35
36 namespace MonoTests.System.ServiceModel.Discovery
37 {
38         [TestFixture]
39         public class AnnouncementClientTest
40         {
41                 [Test]
42                 public void DefaultValues ()
43                 {
44                         // default constructor causes IOE unless there is default configuration...
45                         var ac = new AnnouncementClient (new AnnouncementEndpoint ());
46                         Assert.AreEqual (ac.ChannelFactory.Endpoint, ac.Endpoint, "#1");
47                         Assert.AreEqual ("http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01", ac.Endpoint.Contract.Namespace, "#2");
48                         Assert.AreEqual (2, ac.Endpoint.Contract.Operations.Count, "#2-2");
49                         Assert.IsTrue (ac.Endpoint.Contract.Operations.Any (od => od.Messages.Any (md => md.Action == "http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01/Hello")), "#2-3");
50                         Assert.IsTrue (ac.Endpoint.Contract.Operations.Any (od => od.Messages.Any (md => md.Action == "http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01/Bye")), "#2-4");
51                         Assert.IsNull (ac.Endpoint.Binding, "#3");
52                         Assert.IsNull (ac.Endpoint.Address, "#4");
53                 }
54
55                 [Test]
56                 [ExpectedException (typeof (InvalidOperationException))]
57                 [Category ("NotWorking")]
58                 public void AnnonceOnlineOfflineNoEndpointAddress ()
59                 {
60                         var ac = new AnnouncementClient (new AnnouncementEndpoint () { Binding = new BasicHttpBinding () });
61                         var edm = new EndpointDiscoveryMetadata ();
62                         try {
63                                 ac.AnnounceOnline (edm);
64                         } finally {
65                                 ac.Close ();
66                         }
67                 }
68
69                 [Test]
70                 [ExpectedException (typeof (InvalidOperationException))]
71                 [Category ("NotWorking")]
72                 public void AnnonceOnlineOfflineNoBinding ()
73                 {
74                         var ac = new AnnouncementClient (new AnnouncementEndpoint () { Address = new EndpointAddress ("http://localhost:37564")});
75                         var edm = new EndpointDiscoveryMetadata ();
76                         ac.AnnounceOnline (edm);
77                         // attempt to close the client causes another CommunicationObjectFaultedException - looks like it fails to allow Close() at faulted state unlike other objects.
78                 }
79
80                 [Test]
81                 // looks like EndpointAddress is *ignored*
82                 public void AnnonceOnlineOfflineAddressSchemeMismatch ()
83                 {
84                         var ac = new AnnouncementClient (new UdpAnnouncementEndpoint () { Address = new EndpointAddress ("http://localhost:37564")});
85                         var edm = new EndpointDiscoveryMetadata ();
86                         try {
87                                 ac.AnnounceOnline (edm);
88                                 ac.AnnounceOffline (edm);
89                         } finally {
90                                 ac.Close ();
91                         }
92                 }
93
94                 [Test]
95                 [ExpectedException (typeof (ArgumentException))]
96                 [Category ("NotWorking")]
97                 public void AnnonceOnlineOfflineAddressSchemeMismatch2 ()
98                 {
99                         var ac = new AnnouncementClient (new AnnouncementEndpoint () { Binding = new BasicHttpBinding (), Address = new EndpointAddress ("soap.udp://localhost:37564")});
100                         var edm = new EndpointDiscoveryMetadata ();
101                         try {
102                                 ac.AnnounceOnline (edm);
103                         } finally {
104                                 ac.Close ();
105                         }
106                 }
107
108                 [Test]
109                 [ExpectedException (typeof (InvalidOperationException))]
110                 [Category ("NotWorking")]
111                 public void AnnonceOnlineOfflineHttpMessageVersionMismatch ()
112                 {
113                         var ac = new AnnouncementClient (new AnnouncementEndpoint () { Binding = new BasicHttpBinding () { SendTimeout = TimeSpan.FromSeconds (10), ReceiveTimeout = TimeSpan.FromSeconds (10) }, Address = http_address });
114                         var edm = new EndpointDiscoveryMetadata ();
115                         try {
116                                 ac.AnnounceOnline (edm);
117                         } finally {
118                                 ac.Close ();
119                         }
120                 }
121
122                 EndpointAddress http_address = new EndpointAddress ("http://localhost:37564");
123
124                 [Test]
125                 [ExpectedException (typeof (EndpointNotFoundException))]
126                 [Category ("NotWorking")]
127                 public void AnnonceOnlineOfflineHttpWSA10 ()
128                 {
129                         var binding = new CustomBinding (new HttpTransportBindingElement ()) { SendTimeout = TimeSpan.FromSeconds (10), ReceiveTimeout = TimeSpan.FromSeconds (10) };
130                         var ac = new AnnouncementClient (new AnnouncementEndpoint () { Binding = binding, Address = http_address });
131                         var edm = new EndpointDiscoveryMetadata ();
132                         try {
133                                 ac.AnnounceOnline (edm);
134                         } finally {
135                                 ac.Close ();
136                         }
137                 }
138         }
139 }