3 // Atsushi Enomoto <atsushi@ximian.com>
5 // Copyright (C) 2011 Novell, Inc. http://www.novell.com
7 // Permission is hereby granted, free of charge, to any person obtaining
8 // a copy of this software and associated documentation files (the
9 // "Software"), to deal in the Software without restriction, including
10 // without limitation the rights to use, copy, modify, merge, publish,
11 // distribute, sublicense, and/or sell copies of the Software, and to
12 // permit persons to whom the Software is furnished to do so, subject to
13 // the following conditions:
15 // The above copyright notice and this permission notice shall be
16 // included in all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 using System.Collections.Generic;
29 using System.Reflection;
30 using System.ServiceModel;
31 using System.ServiceModel.Description;
32 using NUnit.Framework;
34 namespace MonoTests.System.ServiceModel
37 public class ServiceKnownTypeAttributeTest
40 public void MethodName ()
42 var cd = ContractDescription.GetContract (typeof (IService));
43 var types = cd.Operations.First ().KnownTypes;
44 Assert.AreEqual (1, types.Count, "#1");
45 Assert.AreEqual (typeof (Bar), types [0], "#2");
49 [ExpectedException (typeof (InvalidOperationException))]
50 public void MethodName2 ()
52 ContractDescription.GetContract (typeof (IService2));
56 [ExpectedException (typeof (InvalidOperationException))]
57 public void MethodName3 ()
59 ContractDescription.GetContract (typeof (IService3));
63 [ExpectedException (typeof (InvalidOperationException))]
64 public void MethodName4 ()
66 ContractDescription.GetContract (typeof (IService4));
71 public string S { get; set; }
74 public class Bar : Foo
76 public string T { get; set; }
81 static IEnumerable<Type> GetTypes (ICustomAttributeProvider provider)
83 yield return typeof (Bar);
87 static Type GetTypes2 (ICustomAttributeProvider provider)
93 static IEnumerable<Type> GetTypes3 ()
95 yield return typeof (Bar);
99 public IEnumerable<Type> GetTypes4 ()
101 yield return typeof (Bar);
105 [ServiceKnownType ("GetTypes", typeof (TypeProvider))]
107 public interface IService
113 [ServiceKnownType ("GetTypes2", typeof (TypeProvider))]
115 public interface IService2
121 [ServiceKnownType ("GetTypes3", typeof (TypeProvider))]
123 public interface IService3
129 [ServiceKnownType ("GetTypes4", typeof (TypeProvider))]
131 public interface IService4