Bug2843Test.cs 13 KB

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