Merge pull request #268 from pcc/menudeactivate
[mono.git] / mcs / class / System.Runtime.Serialization / Test / System.Runtime.Serialization / DataContractSerializerTest_NullableWithDictionary.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.261
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 Client.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 IdField;
40         
41         [System.Runtime.Serialization.OptionalFieldAttribute()]
42         private Client.EvalServiceReference.EvalItem[] itemsListField;
43         
44         [System.Runtime.Serialization.OptionalFieldAttribute()]
45         private System.Collections.Generic.Dictionary<string, Client.EvalServiceReference.EvalItem> itemsMapField;
46         
47         [global::System.ComponentModel.BrowsableAttribute(false)]
48         public System.Runtime.Serialization.ExtensionDataObject ExtensionData {
49             get {
50                 return this.extensionDataField;
51             }
52             set {
53                 this.extensionDataField = value;
54             }
55         }
56         
57         [System.Runtime.Serialization.DataMemberAttribute()]
58         public string Id {
59             get {
60                 return this.IdField;
61             }
62             set {
63                 if ((object.ReferenceEquals(this.IdField, value) != true)) {
64                     this.IdField = value;
65                     this.RaisePropertyChanged("Id");
66                 }
67             }
68         }
69         
70         [System.Runtime.Serialization.DataMemberAttribute()]
71         public Client.EvalServiceReference.EvalItem[] itemsList {
72             get {
73                 return this.itemsListField;
74             }
75             set {
76                 if ((object.ReferenceEquals(this.itemsListField, value) != true)) {
77                     this.itemsListField = value;
78                     this.RaisePropertyChanged("itemsList");
79                 }
80             }
81         }
82         
83         [System.Runtime.Serialization.DataMemberAttribute()]
84         public System.Collections.Generic.Dictionary<string, Client.EvalServiceReference.EvalItem> itemsMap {
85             get {
86                 return this.itemsMapField;
87             }
88             set {
89                 if ((object.ReferenceEquals(this.itemsMapField, value) != true)) {
90                     this.itemsMapField = value;
91                     this.RaisePropertyChanged("itemsMap");
92                 }
93             }
94         }
95         
96         public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
97         
98         protected void RaisePropertyChanged(string propertyName) {
99             System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
100             if ((propertyChanged != null)) {
101                 propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
102             }
103         }
104     }
105     
106     [System.Diagnostics.DebuggerStepThroughAttribute()]
107     [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
108     [System.Runtime.Serialization.DataContractAttribute(Name="EvalItem", Namespace="http://schemas.datacontract.org/2004/07/WcfServiceLibrary1")]
109     [System.SerializableAttribute()]
110     public partial class EvalItem : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged {
111         
112         [System.NonSerializedAttribute()]
113         private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
114         
115         [System.Runtime.Serialization.OptionalFieldAttribute()]
116         private string ItemField;
117         
118         [System.Runtime.Serialization.OptionalFieldAttribute()]
119         private System.Nullable<System.DateTime> ItemTimeField;
120         
121         [System.Runtime.Serialization.OptionalFieldAttribute()]
122         private System.Nullable<Client.EvalServiceReference.EvalType> etypeField;
123         
124         [global::System.ComponentModel.BrowsableAttribute(false)]
125         public System.Runtime.Serialization.ExtensionDataObject ExtensionData {
126             get {
127                 return this.extensionDataField;
128             }
129             set {
130                 this.extensionDataField = value;
131             }
132         }
133         
134         [System.Runtime.Serialization.DataMemberAttribute()]
135         public string Item {
136             get {
137                 return this.ItemField;
138             }
139             set {
140                 if ((object.ReferenceEquals(this.ItemField, value) != true)) {
141                     this.ItemField = value;
142                     this.RaisePropertyChanged("Item");
143                 }
144             }
145         }
146         
147         [System.Runtime.Serialization.DataMemberAttribute()]
148         public System.Nullable<System.DateTime> ItemTime {
149             get {
150                 return this.ItemTimeField;
151             }
152             set {
153                 if ((this.ItemTimeField.Equals(value) != true)) {
154                     this.ItemTimeField = value;
155                     this.RaisePropertyChanged("ItemTime");
156                 }
157             }
158         }
159         
160         [System.Runtime.Serialization.DataMemberAttribute()]
161         public System.Nullable<Client.EvalServiceReference.EvalType> etype {
162             get {
163                 return this.etypeField;
164             }
165             set {
166                 if ((this.etypeField.Equals(value) != true)) {
167                     this.etypeField = value;
168                     this.RaisePropertyChanged("etype");
169                 }
170             }
171         }
172         
173         public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
174         
175         protected void RaisePropertyChanged(string propertyName) {
176             System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
177             if ((propertyChanged != null)) {
178                 propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
179             }
180         }
181     }
182     
183     [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
184     [System.Runtime.Serialization.DataContractAttribute(Name="EvalType", Namespace="http://schemas.datacontract.org/2004/07/WcfServiceLibrary1")]
185     public enum EvalType : int {
186         
187         [System.Runtime.Serialization.EnumMemberAttribute()]
188         SIMPLE = 1,
189         
190         [System.Runtime.Serialization.EnumMemberAttribute()]
191         COMPLEX = 2,
192         
193         [System.Runtime.Serialization.EnumMemberAttribute()]
194         NONE = 3,
195     }
196     
197     [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
198     [System.ServiceModel.ServiceContractAttribute(ConfigurationName="EvalServiceReference.IEvalService")]
199     public interface IEvalService {
200         
201         [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IEvalService/SubmitEval", ReplyAction="http://tempuri.org/IEvalService/SubmitEvalResponse")]
202         void SubmitEval(Client.EvalServiceReference.Eval eval);
203         
204         [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IEvalService/GetEvals", ReplyAction="http://tempuri.org/IEvalService/GetEvalsResponse")]
205         Client.EvalServiceReference.Eval[] GetEvals();
206         
207         [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IEvalService/RemoveEval", ReplyAction="http://tempuri.org/IEvalService/RemoveEvalResponse")]
208         void RemoveEval(string id);
209     }
210     
211     [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
212     public interface IEvalServiceChannel : Client.EvalServiceReference.IEvalService, System.ServiceModel.IClientChannel {
213     }
214     
215     [System.Diagnostics.DebuggerStepThroughAttribute()]
216     [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
217     public partial class EvalServiceClient : System.ServiceModel.ClientBase<Client.EvalServiceReference.IEvalService>, Client.EvalServiceReference.IEvalService {
218         
219         public EvalServiceClient() {
220         }
221         
222         public EvalServiceClient(string endpointConfigurationName) : 
223                 base(endpointConfigurationName) {
224         }
225         
226         public EvalServiceClient(string endpointConfigurationName, string remoteAddress) : 
227                 base(endpointConfigurationName, remoteAddress) {
228         }
229         
230         public EvalServiceClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : 
231                 base(endpointConfigurationName, remoteAddress) {
232         }
233         
234         public EvalServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
235                 base(binding, remoteAddress) {
236         }
237         
238         public void SubmitEval(Client.EvalServiceReference.Eval eval) {
239             base.Channel.SubmitEval(eval);
240         }
241         
242         public Client.EvalServiceReference.Eval[] GetEvals() {
243             return base.Channel.GetEvals();
244         }
245         
246         public void RemoveEval(string id) {
247             base.Channel.RemoveEval(id);
248         }
249     }
250 }
251
252
253 namespace MonoTests.System.Runtime.Serialization
254 {
255         [TestFixture]
256         public class SerializeNullableWithDictionaryTest
257         {
258
259                 [Test]
260                 public void TestNullableWithDictionary()
261                 {
262                         string Name      = "GetEvalsResult";
263                         string Wrapper   = "GetEvalsResponse";
264                         string Namespace = "http://tempuri.org/";
265                         
266                         Type type = typeof(Client.EvalServiceReference.Eval[]);
267                         IEnumerable<Type> know_types = new List<Type>();
268                         
269                         // This is the XML generated by WCF Server
270                         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:Id>8215784f-bf5f-4df8-b239-34a0a029a54e</a:Id>          <a:itemsList>            <a:EvalItem>              <a:Item>Item on List 3</a:Item>              <a:ItemTime>2012-03-04T04:04:00</a:ItemTime>              <a:etype>COMPLEX</a:etype>            </a:EvalItem>            <a:EvalItem i:nil=\"true\" />          </a:itemsList>          <a:itemsMap xmlns:b=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">            <b:KeyValueOfstringEvalItemo8PfwX7N>              <b:Key>Item3</b:Key>              <b:Value>                <a:Item>Item 2 on Map</a:Item>                <a:ItemTime i:nil=\"true\" />                <a:etype>NONE</a:etype>              </b:Value>            </b:KeyValueOfstringEvalItemo8PfwX7N>            <b:KeyValueOfstringEvalItemo8PfwX7N>              <b:Key />              <b:Value i:nil=\"true\" />            </b:KeyValueOfstringEvalItemo8PfwX7N>          </a:itemsMap>        </a:Eval>      </GetEvalsResult>    </GetEvalsResponse>";
271                         
272                         Client.EvalServiceReference.Eval[] evals = null;
273                         
274                         StringBuilder stringBuilder = new StringBuilder ();
275                         
276                         var ds = new DataContractSerializer (type, Name, Namespace, know_types);
277                         
278                         using (var xr = XmlDictionaryReader.CreateDictionaryReader ( XmlReader.Create (new StringReader (xml))))
279                         {       
280                                 xr.ReadStartElement (Wrapper, Namespace);
281
282                                 for (xr.MoveToContent (); xr.NodeType == XmlNodeType.Element; xr.MoveToContent ()) {
283                                         XmlQualifiedName key = new XmlQualifiedName (xr.LocalName, xr.NamespaceURI);
284                                         
285                                 if ( Name == key.Name && Namespace == key.Namespace)
286                                         break;
287                                 }
288                                         
289                                 evals = (Client.EvalServiceReference.Eval[])ds.ReadObject (xr, true);                           
290                         }
291                         
292                         using (var xw = XmlDictionaryWriter.CreateDictionaryWriter ( XmlWriter.Create( new StringWriter(stringBuilder)))) {
293                                 ds.WriteObject (xw, evals);
294                         }
295                         
296                         string actualXml = stringBuilder.ToString ();
297                         
298                         Assert.AreEqual (evals.Length, 1, "evals.Length missmatch");
299                         
300                         Client.EvalServiceReference.Eval eval = evals[0];
301                         
302                         Assert.AreEqual (eval.Id, "8215784f-bf5f-4df8-b239-34a0a029a54e", "eval.Id missmatch");
303                         Assert.AreEqual (eval.itemsList.Length, 2, "eval.itemsList.Length missmatch");
304                         
305                         Client.EvalServiceReference.EvalItem evalItem = eval.itemsList[0];
306                         
307                         Assert.AreEqual (evalItem.Item, "Item on List 3", "evalItem.Item missmatch");
308                         Assert.AreEqual (evalItem.ItemTime , DateTime.Parse("2012-03-04T04:04:00"), "evalItem.ItemTime missmatch");
309                         Assert.AreEqual (evalItem.etype, Client.EvalServiceReference.EvalType.COMPLEX, "evalItem.etype missmatch");
310                         
311                         Client.EvalServiceReference.EvalItem evalItem2 = eval.itemsList[1];
312                         
313                         Assert.IsNull (evalItem2, "evalItem2 missmatch");
314                         
315                         Assert.AreEqual (eval.itemsMap.Count, 2, "eval.itemsMap.Count missmatch");
316                         
317                         Client.EvalServiceReference.EvalItem evalItem3 = eval.itemsMap["Item3"];
318                         
319                         Assert.AreEqual (evalItem3.Item, "Item 2 on Map", "evalItem3.Item missmatch");
320                         Assert.IsNull (evalItem3.ItemTime, "evalItem3.ItemTime missmatch");
321                         Assert.AreEqual (evalItem3.etype,  Client.EvalServiceReference.EvalType.NONE, "evalItem3.etype missmatch");
322                         
323                         Client.EvalServiceReference.EvalItem evalItem4 = eval.itemsMap[""];
324                         
325                         Assert.IsNull(evalItem4, "Item 2 on Map", "evalItem4");
326                         
327                         Client.EvalServiceReference.Eval[] evals2 = null;
328                         
329                         using (var xr = XmlDictionaryReader.CreateDictionaryReader ( XmlReader.Create (new StringReader (actualXml))))
330                         {
331                                 evals2 = (Client.EvalServiceReference.Eval[])ds.ReadObject (xr, true);  
332                         }
333                         
334                         Assert.AreEqual (evals2.Length, 1, "evals2.Length missmatch");
335                         
336                         Client.EvalServiceReference.Eval eval2 = evals2[0];
337                         
338                         Assert.AreEqual (eval2.Id, "8215784f-bf5f-4df8-b239-34a0a029a54e", "eval2.Id missmatch");
339                         Assert.AreEqual (eval2.itemsList.Length, 2, "eval2.itemsList.Length missmatch");
340                         
341                         Client.EvalServiceReference.EvalItem eval2Item = eval2.itemsList[0];
342                         
343                         Assert.AreEqual (eval2Item.Item, "Item on List 3", "eval2Item.Item missmatch");
344                         Assert.AreEqual (eval2Item.ItemTime , DateTime.Parse("2012-03-04T04:04:00"), "eval2Item.ItemTime missmatch");
345                         Assert.AreEqual (eval2Item.etype, Client.EvalServiceReference.EvalType.COMPLEX, "eval2Item.etype missmatch");
346                         
347                         Client.EvalServiceReference.EvalItem eval2Item2 = eval2.itemsList[1];
348                         
349                         Assert.IsNull (eval2Item2,  "eval2Item2 missmatch");
350                         
351                         Assert.AreEqual (eval2.itemsMap.Count, 2, "eval2.itemsMap.Count missmatch");
352                         
353                         Client.EvalServiceReference.EvalItem eval2Item3 = eval2.itemsMap["Item3"];
354                         
355                         Assert.AreEqual (eval2Item3.Item, "Item 2 on Map", "eval2Item3.Item missmatch");
356                         Assert.IsNull (eval2Item3.ItemTime, "eval2Item3.ItemTime missmatch");
357                         Assert.AreEqual (eval2Item3.etype,  Client.EvalServiceReference.EvalType.NONE,  "eval2Item3.etype missmatch");
358                         
359                         Client.EvalServiceReference.EvalItem eval2Item4 = eval.itemsMap[""];
360                         
361                         Assert.IsNull(eval2Item4, "eval2Item4 missmatch");
362                 }
363         }
364 }
365