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 public void AnnonceOnlineOfflineNoEndpointAddress ()
59 var ac = new AnnouncementClient (new AnnouncementEndpoint () { Binding = new BasicHttpBinding () });
60 var edm = new EndpointDiscoveryMetadata ();
62 ac.AnnounceOnline (edm);
69 [ExpectedException (typeof (InvalidOperationException))]
70 public void AnnonceOnlineOfflineNoBinding ()
72 var ac = new AnnouncementClient (new AnnouncementEndpoint () { Address = new EndpointAddress ("http://localhost:37564")});
73 var edm = new EndpointDiscoveryMetadata ();
74 ac.AnnounceOnline (edm);
75 // attempt to close the client causes another CommunicationObjectFaultedException - looks like it fails to allow Close() at faulted state unlike other objects.
79 // looks like EndpointAddress is *ignored*
80 public void AnnonceOnlineOfflineAddressSchemeMismatch ()
82 var ac = new AnnouncementClient (new UdpAnnouncementEndpoint () { Address = new EndpointAddress ("http://localhost:37564")});
83 var edm = new EndpointDiscoveryMetadata ();
85 ac.AnnounceOnline (edm);
86 ac.AnnounceOffline (edm);
93 [ExpectedException (typeof (ArgumentException))]
94 public void AnnonceOnlineOfflineAddressSchemeMismatch2 ()
96 var ac = new AnnouncementClient (new AnnouncementEndpoint () { Binding = new BasicHttpBinding (), Address = new EndpointAddress ("soap.udp://localhost:37564")});
97 var edm = new EndpointDiscoveryMetadata ();
99 ac.AnnounceOnline (edm);
106 [ExpectedException (typeof (InvalidOperationException))]
107 public void AnnonceOnlineOfflineHttpMessageVersionMismatch ()
109 var ac = new AnnouncementClient (new AnnouncementEndpoint () { Binding = new BasicHttpBinding () { SendTimeout = TimeSpan.FromSeconds (10), ReceiveTimeout = TimeSpan.FromSeconds (10) }, Address = http_address });
110 var edm = new EndpointDiscoveryMetadata ();
112 ac.AnnounceOnline (edm);
118 EndpointAddress http_address = new EndpointAddress ("http://localhost:37564");
121 [ExpectedException (typeof (EndpointNotFoundException))]
122 public void AnnonceOnlineOfflineHttpWSA10 ()
124 var binding = new CustomBinding (new HttpTransportBindingElement ()) { SendTimeout = TimeSpan.FromSeconds (10), ReceiveTimeout = TimeSpan.FromSeconds (10) };
125 var ac = new AnnouncementClient (new AnnouncementEndpoint () { Binding = binding, Address = http_address });
126 var edm = new EndpointDiscoveryMetadata ();
128 ac.AnnounceOnline (edm);