Merge pull request #249 from pcc/xgetinputfocus
[mono.git] / mcs / class / System.Runtime.Serialization / Test / System.Runtime.Serialization / Bug2843Test.cs
1 using System;
2 using System.Collections.Generic;
3 using System.IO;
4 using System.Runtime.Serialization;
5 using System.ServiceModel;
6 using System.ServiceModel.Channels;
7 using System.ServiceModel.Description;
8 using System.Xml;
9 using System.ServiceModel.Dispatcher;
10
11 using System.Text;
12 using NUnit.Framework;
13
14 //------------------------------------------------------------------------------
15 // <auto-generated>
16 //     This code was generated by a tool.
17 //     Runtime Version:4.0.30319.239
18 //
19 //     Changes to this file may cause incorrect behavior and will be lost if
20 //     the code is regenerated.
21 // </auto-generated>
22 //------------------------------------------------------------------------------
23
24 namespace Client2843.EvalServiceReference {
25     using System.Runtime.Serialization;
26     using System;
27     
28     
29     [System.Diagnostics.DebuggerStepThroughAttribute()]
30     [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
31     [System.Runtime.Serialization.DataContractAttribute(Name="Eval", Namespace="http://schemas.datacontract.org/2004/07/WcfServiceLibrary1")]
32     [System.SerializableAttribute()]
33     public partial class Eval : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged {
34         
35         [System.NonSerializedAttribute()]
36         private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
37         
38         [System.Runtime.Serialization.OptionalFieldAttribute()]
39         private string CommentsField;
40         
41         [System.Runtime.Serialization.OptionalFieldAttribute()]
42         private string IdField;
43         
44         [System.Runtime.Serialization.OptionalFieldAttribute()]
45         private string SubmitterField;
46         
47         [System.Runtime.Serialization.OptionalFieldAttribute()]
48         private System.Nullable<System.DateTime> TimeSubmittedField;
49         
50         [System.Runtime.Serialization.OptionalFieldAttribute()]
51         private System.Nullable<Client2843.EvalServiceReference.EvalType> etypeField;
52         
53         [System.Runtime.Serialization.OptionalFieldAttribute()]
54         private System.Nullable<Client2843.EvalServiceReference.EvalType> etype2Field;
55         
56         [global::System.ComponentModel.BrowsableAttribute(false)]
57         public System.Runtime.Serialization.ExtensionDataObject ExtensionData {
58             get {
59                 return this.extensionDataField;
60             }
61             set {
62                 this.extensionDataField = value;
63             }
64         }
65         
66         [System.Runtime.Serialization.DataMemberAttribute()]
67         public string Comments {
68             get {
69                 return this.CommentsField;
70             }
71             set {
72                 if ((object.ReferenceEquals(this.CommentsField, value) != true)) {
73                     this.CommentsField = value;
74                     this.RaisePropertyChanged("Comments");
75                 }
76             }
77         }
78         
79         [System.Runtime.Serialization.DataMemberAttribute()]
80         public string Id {
81             get {
82                 return this.IdField;
83             }
84             set {
85                 if ((object.ReferenceEquals(this.IdField, value) != true)) {
86                     this.IdField = value;
87                     this.RaisePropertyChanged("Id");
88                 }
89             }
90         }
91         
92         [System.Runtime.Serialization.DataMemberAttribute()]
93         public string Submitter {
94             get {
95                 return this.SubmitterField;
96             }
97             set {
98                 if ((object.ReferenceEquals(this.SubmitterField, value) != true)) {
99                     this.SubmitterField = value;
100                     this.RaisePropertyChanged("Submitter");
101                 }
102             }
103         }
104         
105         [System.Runtime.Serialization.DataMemberAttribute()]
106         public System.Nullable<System.DateTime> TimeSubmitted {
107             get {
108                 return this.TimeSubmittedField;
109             }
110             set {
111                 if ((this.TimeSubmittedField.Equals(value) != true)) {
112                     this.TimeSubmittedField = value;
113                     this.RaisePropertyChanged("TimeSubmitted");
114                 }
115             }
116         }
117         
118         [System.Runtime.Serialization.DataMemberAttribute()]
119         public System.Nullable<Client2843.EvalServiceReference.EvalType> etype {
120             get {
121                 return this.etypeField;
122             }
123             set {
124                 if ((this.etypeField.Equals(value) != true)) {
125                     this.etypeField = value;
126                     this.RaisePropertyChanged("etype");
127                 }
128             }
129         }
130         
131         [System.Runtime.Serialization.DataMemberAttribute()]
132         public System.Nullable<Client2843.EvalServiceReference.EvalType> etype2 {
133             get {
134                 return this.etype2Field;
135             }
136             set {
137                 if ((this.etype2Field.Equals(value) != true)) {
138                     this.etype2Field = value;
139                     this.RaisePropertyChanged("etype2");
140                 }
141             }
142         }
143         
144         public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
145         
146         protected void RaisePropertyChanged(string propertyName) {
147             System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
148             if ((propertyChanged != null)) {
149                 propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
150             }
151         }
152     }
153     
154     [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
155     [System.Runtime.Serialization.DataContractAttribute(Name="EvalType", Namespace="http://schemas.datacontract.org/2004/07/WcfServiceLibrary1")]
156     public enum EvalType : int {
157         
158         [System.Runtime.Serialization.EnumMemberAttribute()]
159         SIMPLE = 1,
160         
161         [System.Runtime.Serialization.EnumMemberAttribute()]
162         COMPLEX = 2,
163         
164         [System.Runtime.Serialization.EnumMemberAttribute()]
165         NONE = 3,
166     }
167     
168     [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
169     [System.ServiceModel.ServiceContractAttribute(ConfigurationName="EvalServiceReference.IEvalService")]
170     public interface IEvalService {
171         
172         [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IEvalService/SubmitEval", ReplyAction="http://tempuri.org/IEvalService/SubmitEvalResponse")]
173         void SubmitEval(Client2843.EvalServiceReference.Eval eval);
174         
175         [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IEvalService/GetEvals", ReplyAction="http://tempuri.org/IEvalService/GetEvalsResponse")]
176         Client2843.EvalServiceReference.Eval[] GetEvals();
177         
178         [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IEvalService/RemoveEval", ReplyAction="http://tempuri.org/IEvalService/RemoveEvalResponse")]
179         void RemoveEval(string id);
180     }
181     
182     [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
183     public interface IEvalServiceChannel : Client2843.EvalServiceReference.IEvalService, System.ServiceModel.IClientChannel {
184     }
185     
186     [System.Diagnostics.DebuggerStepThroughAttribute()]
187     [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
188     public partial class EvalServiceClient : System.ServiceModel.ClientBase<Client2843.EvalServiceReference.IEvalService>, Client2843.EvalServiceReference.IEvalService {
189         
190         public EvalServiceClient() {
191         }
192         
193         public EvalServiceClient(string endpointConfigurationName) : 
194                 base(endpointConfigurationName) {
195         }
196         
197         public EvalServiceClient(string endpointConfigurationName, string remoteAddress) : 
198                 base(endpointConfigurationName, remoteAddress) {
199         }
200         
201         public EvalServiceClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : 
202                 base(endpointConfigurationName, remoteAddress) {
203         }
204         
205         public EvalServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
206                 base(binding, remoteAddress) {
207         }
208         
209         public void SubmitEval(Client2843.EvalServiceReference.Eval eval) {
210             base.Channel.SubmitEval(eval);
211         }
212         
213         public Client2843.EvalServiceReference.Eval[] GetEvals() {
214             return base.Channel.GetEvals();
215         }
216         
217         public void RemoveEval(string id) {
218             base.Channel.RemoveEval(id);
219         }
220     }
221 }
222
223
224 namespace MonoTests.System.Runtime.Serialization
225 {
226         [TestFixture]
227         class Bug2843Test
228         {
229                 [Test]
230                 public void TestNullableEnum()
231                 {
232                         string Name      = "GetEvalsResult";
233                         string Wrapper   = "GetEvalsResponse";
234                         string Namespace = "http://tempuri.org/";
235                         
236                         Type type = typeof(Client2843.EvalServiceReference.Eval[]);
237                         IEnumerable<Type> know_types = new List<Type>();
238                         
239                         // This is the XML generated by WCF Server
240                         string xml = "<GetEvalsResponse xmlns=\"http://tempuri.org/\">      <GetEvalsResult xmlns:a=\"http://schemas.datacontract.org/2004/07/WcfServiceLibrary1\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">        <a:Eval>          <a:Comments>Comment 1</a:Comments>          <a:Id>04836718-41a7-45fe-8c0b-ac3fc613b0f8</a:Id>          <a:Submitter>Submitter 1</a:Submitter>          <a:TimeSubmitted i:nil=\"true\" />          <a:etype>SIMPLE</a:etype>          <a:etype2>COMPLEX</a:etype2>        </a:Eval>        <a:Eval>          <a:Comments>Comment 2</a:Comments>          <a:Id>fd17a406-4c2c-41ca-9a5d-1a1019d07535</a:Id>          <a:Submitter>Submitter 2</a:Submitter>          <a:TimeSubmitted>2012-02-26T13:41:00</a:TimeSubmitted>          <a:etype i:nil=\"true\" />          <a:etype2>COMPLEX</a:etype2>        </a:Eval>      </GetEvalsResult>    </GetEvalsResponse>";
241                         
242                         Client2843.EvalServiceReference.Eval[] evals = null;
243                         
244                         StringBuilder stringBuilder = new StringBuilder ();
245                         
246                         var ds = new DataContractSerializer (type, Name, Namespace, know_types);
247                         
248                         using (var xr = XmlDictionaryReader.CreateDictionaryReader ( XmlReader.Create (new StringReader (xml))))
249                         {       
250                                 xr.ReadStartElement (Wrapper, Namespace);
251
252                                 for (xr.MoveToContent (); xr.NodeType == XmlNodeType.Element; xr.MoveToContent ()) {
253                                         XmlQualifiedName key = new XmlQualifiedName (xr.LocalName, xr.NamespaceURI);
254                                         
255                                 if ( Name == key.Name && Namespace == key.Namespace)
256                                         break;
257                                 }
258                                         
259                                 evals = (Client2843.EvalServiceReference.Eval[])ds.ReadObject (xr, true);                               
260                         }
261                         
262                         using (var xw = XmlDictionaryWriter.CreateDictionaryWriter ( XmlWriter.Create( new StringWriter(stringBuilder)))) {
263                                 ds.WriteObject (xw, evals);
264                         }
265                         
266                         string actualXml = stringBuilder.ToString ();
267                         
268                         Assert.AreEqual (evals.Length, 2, "Comment 1" , "Eval 1 Comment missmatch");
269                         
270                         Client2843.EvalServiceReference.Eval ev1 = evals[0];
271                         Client2843.EvalServiceReference.Eval ev2 = evals[1];
272                         
273                         // Assert that object deserilized matches each value attribute.
274                         Assert.AreEqual (ev1.Comments, "Comment 1" , "ev1.Comments missmatch");
275                         Assert.AreEqual (ev1.Submitter, "Submitter 1", "ev1.Submitter missmatch");
276                         Assert.IsNull   (ev1.TimeSubmitted, "ev1.TimeSubmitted missmatch");
277                         Assert.AreEqual (ev1.etype, Client2843.EvalServiceReference.EvalType.SIMPLE, "ev1.etype missmatch");
278                         Assert.AreEqual (ev1.etype2, Client2843.EvalServiceReference.EvalType.COMPLEX, "ev1.etype2 missmatch");
279                         
280                         Assert.AreEqual (ev2.Comments, "Comment 2", "ev2.Comments missmatch");
281                         Assert.AreEqual (ev2.Submitter, "Submitter 2","ev2.Submitter missmatch");
282                         Assert.AreEqual (ev2.TimeSubmitted, DateTime.Parse("2012-02-26T13:41:00"), "ev2.TimeSubmitted missmatch");
283                         Assert.IsNull (ev2.etype, "ev2.etype missmatch");
284                         Assert.AreEqual (ev2.etype2, Client2843.EvalServiceReference.EvalType.COMPLEX, "ev2.etype2 missmatch");
285                         
286                         
287                         Client2843.EvalServiceReference.Eval[] evals2 = null;
288                         
289                         using (var xr = XmlDictionaryReader.CreateDictionaryReader ( XmlReader.Create (new StringReader (actualXml))))
290                         {
291                                 evals2 = (Client2843.EvalServiceReference.Eval[])ds.ReadObject (xr, true);      
292                         }
293                         
294                         Client2843.EvalServiceReference.Eval e1 = evals2[0];
295                         Client2843.EvalServiceReference.Eval e2 = evals2[1];
296                         
297                         Assert.AreEqual (e1.Comments, "Comment 1" , "e1.Comments missmatch");
298                         Assert.AreEqual (e1.Submitter, "Submitter 1", "e1.Submitter missmatch");
299                         Assert.IsNull   (e1.TimeSubmitted, "e1.TimeSubmitted missmatch");
300                         Assert.AreEqual (e1.etype, Client2843.EvalServiceReference.EvalType.SIMPLE, "e1.etype missmatch");
301                         Assert.AreEqual (e1.etype2, Client2843.EvalServiceReference.EvalType.COMPLEX, "e1.etype2 missmatch");
302                         
303                         Assert.AreEqual (e2.Comments, "Comment 2", "e2.Comments missmatch");
304                         Assert.AreEqual (e2.Submitter, "Submitter 2","e2.Submitter missmatch");
305                         Assert.AreEqual (e2.TimeSubmitted, DateTime.Parse("2012-02-26T13:41:00"), "e2.TimeSubmitted missmatch");
306                         Assert.IsNull   (e2.etype, "e2.etype missmatch");
307                         Assert.AreEqual (e2.etype2, Client2843.EvalServiceReference.EvalType.COMPLEX, "e2.etype2 missmatch");
308                 }
309         }
310 }