2 // DataContractSerializerTest.cs
8 // Copyright (C) 2013-2014 Xamarin Inc http://www.xamarin.com
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 // This test code contains tests for attributes in System.Runtime.Serialization
34 using System.Collections.Generic;
37 using NUnit.Framework;
38 using System.Reflection;
39 using System.Globalization;
40 using System.Runtime.Serialization;
44 namespace MonoTests.System.Runtime.Serialization
46 [KnownType (typeof(MyObject[]))]
48 public class MyObject2
51 public object NameList;
54 [KnownType(typeof(string[]))]
59 public object NameList;
63 public class DataContractSerializerTestBugs {
68 public void SerializeMyObject ()
70 var attrs = (KnownTypeAttribute[])typeof(MyObject).
71 GetCustomAttributes (typeof(KnownTypeAttribute), true);
73 for (int i = 0; i < attrs.Length; i ++) {
74 Console.WriteLine (attrs [i].Type);
77 var ser = new DataContractSerializer (typeof(MyObject));
83 var s = "<MyObject xmlns=\"http://schemas.datacontract.org/2004/07/MonoTests.System.Runtime.Serialization\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">\n" +
84 " <NameList i:type=\"a:ArrayOfstring\" xmlns:a=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">\n" +
85 " <a:string>Name1</a:string>\n" +
86 " <a:string>Name2</a:string>\n" +
90 //<MyObject xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/ServiceTest">
92 var ser = new DataContractSerializer(typeof(MyObject));
93 ser.ReadObject (XmlReader.Create(new StringReader(s)));
107 public class ClassWithFlagsEnum
109 public FlagsEnum Flags = FlagsEnum.All;
114 public void FlagsEnumTest ()
116 var ser = new DataContractSerializer (typeof (ClassWithFlagsEnum));
118 using (var m = new MemoryStream ()) {
119 ser.WriteObject (m, new ClassWithFlagsEnum ());
120 var data = m.ToArray ();
121 var s = Encoding.UTF8.GetString (data, 0, (int) data.Length);
122 Assert.IsTrue (s.Contains ("<Flags>All</Flags>"));