2 // Author: Atsushi Enomoto <atsushi@ximian.com>
4 // Copyright (C) 2010 Novell, Inc (http://www.novell.com)
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:
14 // The above copyright notice and this permission notice shall be
15 // included in all copies or substantial portions of the Software.
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.
26 using System.Collections.Generic;
27 using System.Collections.ObjectModel;
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;
36 namespace MonoTests.System.ServiceModel.Discovery
39 public class AnnouncementClientTest
42 public void DefaultValues ()
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");
56 [ExpectedException (typeof (InvalidOperationException))]
57 [Category ("NotWorking")]
58 public void AnnonceOnlineOfflineNoEndpointAddress ()
60 var ac = new AnnouncementClient (new AnnouncementEndpoint () { Binding = new BasicHttpBinding () });
61 var edm = new EndpointDiscoveryMetadata ();
63 ac.AnnounceOnline (edm);
70 [ExpectedException (typeof (InvalidOperationException))]
71 [Category ("NotWorking")]
72 public void AnnonceOnlineOfflineNoBinding ()
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.
81 // looks like EndpointAddress is *ignored*
82 public void AnnonceOnlineOfflineAddressSchemeMismatch ()
84 var ac = new AnnouncementClient (new UdpAnnouncementEndpoint () { Address = new EndpointAddress ("http://localhost:37564")});
85 var edm = new EndpointDiscoveryMetadata ();
87 ac.AnnounceOnline (edm);
88 ac.AnnounceOffline (edm);
95 [ExpectedException (typeof (ArgumentException))]
96 [Category ("NotWorking")]
97 public void AnnonceOnlineOfflineAddressSchemeMismatch2 ()
99 var ac = new AnnouncementClient (new AnnouncementEndpoint () { Binding = new BasicHttpBinding (), Address = new EndpointAddress ("soap.udp://localhost:37564")});
100 var edm = new EndpointDiscoveryMetadata ();
102 ac.AnnounceOnline (edm);
109 [ExpectedException (typeof (InvalidOperationException))]
110 [Category ("NotWorking")]
111 public void AnnonceOnlineOfflineHttpMessageVersionMismatch ()
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 ();
116 ac.AnnounceOnline (edm);
122 EndpointAddress http_address = new EndpointAddress ("http://localhost:37564");
125 [ExpectedException (typeof (EndpointNotFoundException))]
126 [Category ("NotWorking")]
127 public void AnnonceOnlineOfflineHttpWSA10 ()
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 ();
133 ac.AnnounceOnline (edm);