Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

version 1.0.4 commit

see Readme.htm for release notes
  • Loading branch information...
commit c703766e161ed498f60bd1bb77079c90a9d228c1 1 parent 95b9ce3
Bilal-S authored

Showing 77 changed files with 27,889 additions and 0 deletions. Show diff stats Hide diff stats

  1. +1 0  README
  2. +389 0 README.htm
  3. BIN  Release/WDDX.Net Internals.chm
  4. BIN  Release/WDDX.Net.chm
  5. BIN  Release/Wddx.Net.dll
  6. +58 0 WDDX Tests/AssemblyInfo.cs
  7. +788 0 WDDX Tests/UnitTests.cs
  8. +155 0 WDDX Tests/WDDX Tests.csproj
  9. +23 0 WDDX Tests/WDDX Tests.csproj.user
  10. +3 0  WDDX Tests/app.config
  11. +72 0 WDDX Tests/bin/Debug/TestResult.xml
  12. +101 0 WDDX Tests/bin/Debug/TestResult2.xml
  13. BIN  WDDX Tests/bin/Debug/WDDX Tests.dll
  14. +13 0 WDDX Tests/bin/Debug/WDDX Tests.dll.VisualState.xml
  15. +3 0  WDDX Tests/bin/Debug/WDDX Tests.dll.config
  16. BIN  WDDX Tests/bin/Debug/WDDX Tests.pdb
  17. BIN  WDDX Tests/bin/Debug/Wddx.Net.dll
  18. +7 0 WDDX Tests/bin/Debug/Wddx.Net.dll.VisualState.xml
  19. +3 0  WDDX Tests/bin/Debug/Wddx.Net.dll.config
  20. BIN  WDDX Tests/bin/Debug/Wddx.Net.pdb
  21. +680 0 WDDX Tests/bin/Debug/Wddx.Net.xml
  22. BIN  WDDX Tests/bin/Debug/nunit.framework.dll
  23. +10,407 0 WDDX Tests/bin/Debug/nunit.framework.xml
  24. BIN  WDDX Tests/bin/Release/WDDX Tests.dll
  25. +3 0  WDDX Tests/bin/Release/WDDX Tests.dll.config
  26. BIN  WDDX Tests/bin/Release/Wddx.Net.dll
  27. +680 0 WDDX Tests/bin/Release/Wddx.Net.xml
  28. BIN  WDDX Tests/bin/Release/nunit.framework.dll
  29. +10,407 0 WDDX Tests/bin/Release/nunit.framework.xml
  30. BIN  WDDX Tests/obj/Debug/ResolveAssemblyReference.cache
  31. +11 0 WDDX Tests/obj/Debug/WDDX Tests.csproj.FileListAbsolute.txt
  32. BIN  WDDX Tests/obj/Debug/WDDX Tests.dll
  33. BIN  WDDX Tests/obj/Debug/WDDX Tests.pdb
  34. BIN  WDDX Tests/obj/Release/ResolveAssemblyReference.cache
  35. +8 0 WDDX Tests/obj/Release/WDDX Tests.csproj.FileListAbsolute.txt
  36. BIN  WDDX Tests/obj/Release/WDDX Tests.dll
  37. BIN  WDDX.Net Internals.chm
  38. BIN  WDDX.Net.chm
  39. +72 0 WDDX.Net/ArrayDeserializer.cs
  40. +65 0 WDDX.Net/ArraySerializer.cs
  41. +51 0 WDDX.Net/AssemblyInfo.cs
  42. +297 0 WDDX.Net/BaseDeserializers.cs
  43. +295 0 WDDX.Net/BaseSerializers.cs
  44. +128 0 WDDX.Net/BinaryDeserializer.cs
  45. +57 0 WDDX.Net/BinarySerializer.cs
  46. +123 0 WDDX.Net/DataSetDeserializer.cs
  47. +124 0 WDDX.Net/DataSetSerializer.cs
  48. +53 0 WDDX.Net/Exceptions.cs
  49. +118 0 WDDX.Net/GenericSerializer.cs
  50. +19 0 WDDX.Net/IWddxElementDeserializer.cs
  51. +18 0 WDDX.Net/IWddxObjectSerializer.cs
  52. +78 0 WDDX.Net/StringDeserializer.cs
  53. +76 0 WDDX.Net/StringSerializer.cs
  54. +76 0 WDDX.Net/StructDeserializer.cs
  55. +77 0 WDDX.Net/StructSerializer.cs
  56. +163 0 WDDX.Net/WDDX.Net.csproj
  57. +680 0 WDDX.Net/WDDX.Net.xml
  58. +152 0 WDDX.Net/WddxDeserializer.cs
  59. +45 0 WDDX.Net/WddxElementDeserializerFactory.cs
  60. +110 0 WDDX.Net/WddxObjectSerializerFactory.cs
  61. +94 0 WDDX.Net/WddxSerializer.cs
  62. +127 0 WDDX.Net/WddxValidator.cs
  63. +3 0  WDDX.Net/app.config
  64. +680 0 WDDX.Net/bin/Debug/WDDX.Net.xml
  65. BIN  WDDX.Net/bin/Debug/Wddx.Net.dll
  66. +7 0 WDDX.Net/bin/Debug/Wddx.Net.dll.VisualState.xml
  67. +3 0  WDDX.Net/bin/Debug/Wddx.Net.dll.config
  68. BIN  WDDX.Net/bin/Debug/Wddx.Net.pdb
  69. +7 0 WDDX.Net/obj/Debug/WDDX.Net.csproj.FileListAbsolute.txt
  70. BIN  WDDX.Net/obj/Debug/Wddx.Net.dll
  71. BIN  WDDX.Net/obj/Debug/Wddx.Net.pdb
  72. +5 0 WDDX.Net/obj/Release/WDDX.Net.csproj.FileListAbsolute.txt
  73. BIN  WDDX.Net/obj/Release/Wddx.Net.dll
  74. +76 0 WDDX.Net/wddx_0100.dtd
  75. +169 0 WDDX.Net/wddx_0100.xsd
  76. +29 0 WDDX.sln
  77. BIN  WDDX.suo
1  README
... ... @@ -0,0 +1 @@
  1 +Please review the Readme.htm file for release notes.
389 README.htm
... ... @@ -0,0 +1,389 @@
  1 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2 + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3 +
  4 +<html xmlns="http://www.w3.org/1999/xhtml">
  5 + <head>
  6 + <title>WDDX.NET</title>
  7 +
  8 + <style type="text/css"> /*<![CDATA[*/ <!-- body,td,th{background:#FFF;font:10pt Verdana,Geneva,Arial,Helvetica,sans-serif;}
  9 + table{border-collapse:collapse;}
  10 + th{font-weight:bold;text-align:center;}
  11 + --> /*]]>*/
  12 + </style>
  13 + </head>
  14 + <body>
  15 + <h3>WDDX.Net</h3>
  16 + <p>
  17 + <strong>Version 1.0.4</strong>
  18 + </p>
  19 + <p>
  20 + <a href="mailto:jmueller@swiftk.com">Joel Mueller</a>
  21 + </p>
  22 + <p>
  23 + The only classes you need to know are WddxSerializer and
  24 + WddxDeserializer. Click <a href="WDDX.Net.chm">here</a> for
  25 + documentation. For those who want to play with the source, full
  26 + documentation on the internal API is also supplied <a
  27 + href="WDDX.Net%20Internals.chm">here</a>. See the "WDDX Tests"
  28 + project for usage samples and tests.
  29 + </p>
  30 + <p>
  31 + The following table compares the WDDX data types with the .NET
  32 + Common Language Runtime types that they map to.
  33 + </p>
  34 + <table border="1" cellspacing="0">
  35 + <tr>
  36 + <th>
  37 + WDDX
  38 + </th>
  39 + <th>
  40 + .NET CLR
  41 + </th>
  42 + </tr>
  43 + <tr>
  44 + <td>
  45 + null
  46 + </td>
  47 + <td>
  48 + A null object reference (null in C#, Nothing in VB.NET)
  49 + </td>
  50 + </tr>
  51 + <tr>
  52 + <td>
  53 + boolean
  54 + </td>
  55 + <td>
  56 + System.Boolean (bool in C#, Boolean in VB.NET)
  57 + </td>
  58 + </tr>
  59 + <tr>
  60 + <td>
  61 + number
  62 + </td>
  63 + <td align="middle">
  64 + One of the following, depending on what fits:
  65 + <table border="1" cellspacing="0">
  66 + <tr>
  67 + <th>
  68 + CLR
  69 + </th>
  70 + <th>
  71 + C#
  72 + </th>
  73 + <th>
  74 + VB.NET
  75 + </th>
  76 + </tr>
  77 + <tr>
  78 + <td>
  79 + System.Int16
  80 + </td>
  81 + <td>
  82 + short
  83 + </td>
  84 + <td>
  85 + Short
  86 + </td>
  87 + </tr>
  88 + <tr>
  89 + <td>
  90 + System.Int32
  91 + </td>
  92 + <td>
  93 + int
  94 + </td>
  95 + <td>
  96 + Integer
  97 + </td>
  98 + </tr>
  99 + <tr>
  100 + <td>
  101 + System.Int64
  102 + </td>
  103 + <td>
  104 + long
  105 + </td>
  106 + <td>
  107 + Long
  108 + </td>
  109 + </tr>
  110 + <tr>
  111 + <td>
  112 + System.Single
  113 + </td>
  114 + <td>
  115 + float
  116 + </td>
  117 + <td>
  118 + Single
  119 + </td>
  120 + </tr>
  121 + <tr>
  122 + <td>
  123 + System.Double
  124 + </td>
  125 + <td>
  126 + double
  127 + </td>
  128 + <td>
  129 + Double
  130 + </td>
  131 + </tr>
  132 + <tr>
  133 + <td>
  134 + System.Decimal
  135 + </td>
  136 + <td>
  137 + decimal
  138 + </td>
  139 + <td>
  140 + Decimal
  141 + </td>
  142 + </tr>
  143 + </table>
  144 + </td>
  145 + </tr>
  146 + <tr>
  147 + <td>
  148 + dateTime
  149 + </td>
  150 + <td>
  151 + System.DateTime (Date in VB.NET)
  152 + </td>
  153 + </tr>
  154 + <tr>
  155 + <td>
  156 + string
  157 + </td>
  158 + <td>
  159 + System.String (string in C#, String in VB.NET)
  160 + </td>
  161 + </tr>
  162 + <tr>
  163 + <td>
  164 + array
  165 + </td>
  166 + <td>
  167 + System.Collections.ArrayList (see notes below for details)
  168 + </td>
  169 + </tr>
  170 + <tr>
  171 + <td>
  172 + struct
  173 + </td>
  174 + <td>
  175 + System.Collections.Hashtable (see notes below for details)
  176 + </td>
  177 + </tr>
  178 + <tr>
  179 + <td>
  180 + recordset
  181 + </td>
  182 + <td>
  183 + System.Data.DataSet (see notes below for details)
  184 + </td>
  185 + </tr>
  186 + <tr>
  187 + <td>
  188 + binary
  189 + </td>
  190 + <td>
  191 + <p>
  192 + A System.Byte array (byte[] in C#, Byte() in VB.NET)
  193 + </p>
  194 + </td>
  195 + </tr>
  196 + <tr>
  197 + <td>
  198 + char
  199 + </td>
  200 + <td>
  201 + System.Char (char in C#, Char in VB.NET)
  202 + </td>
  203 + </tr>
  204 + </table>
  205 + <p>
  206 + * The precision of the System.Decimal type is not directly supported by
  207 + WDDX; when serialized if numbers have higher precision than 15 they will be first converted to Double.
  208 + </p>
  209 +
  210 +
  211 + <p>
  212 + <strong>New in 1.0.4:</strong>
  213 + </p>
  214 + <UL>
  215 + <li>updraded to .net framework 3 -- bilal</li>
  216 + <li>updated unit test to nunit 2.5 </li>
  217 + <li>corrected iso8601 date and time interpretation and unit tests. Hours are now correctly translated across time zones.</li>
  218 + <li>detected but did not fix validator IsValid() function -- known issue</li>
  219 + <li>introduced System.decimal for improvement precision for up to 15 digits after the decimal</li>
  220 +
  221 + </UL>
  222 +
  223 +
  224 + <p>
  225 + <strong>New in 1.0.3:</strong>
  226 + </p>
  227 +<UL>
  228 + <LI>Fixed a bug in string deserialization that could
  229 + result in an infinite loop in certain situations.
  230 + <LI>Updated unit tests to work with <A
  231 + href="http://nunit.sourceforge.net/">NUnit 2.0</A>.
  232 + <LI>Slight performance improvement when deserializing large
  233 +recordsets.</LI></UL>
  234 +<P><STRONG>New in 1.0.2:</STRONG> </P>
  235 + <ul>
  236 + <li>
  237 + Fixed minor deserialization bugs for dateTime and string
  238 + elements in large recordsets.
  239 + </li>
  240 + </ul>
  241 + <p>
  242 + <strong>New in 1.0.1:</strong>
  243 + </p>
  244 + <ul>
  245 + <li>
  246 + Fixed date parsing to&nbsp;properly
  247 + handle&nbsp;non-ISO8601 dates produced by ColdFusion.
  248 + <li>
  249 + Refactored for better error handling during
  250 + serialization.&nbsp;
  251 + <li>
  252 + Known issue - any non-ISO8601 dates (such as
  253 + 2002-7-2T8:3:0-5:0, without leading zeros) will cause XSD
  254 + validation to fail even though the parser can handle these
  255 + dates.&nbsp;For this reason, is it possible for
  256 + WddxDeserializer.IsValid() to return false on a packet that it
  257 + can successfully parse.
  258 + </li>
  259 + </ul>
  260 + <p>
  261 + <strong>New in 1.0:</strong>
  262 + </p>
  263 + <ul>
  264 + <li>
  265 + Support for NUnit 1.11 in the unit tests.
  266 + </li>
  267 + </ul>
  268 + <p>
  269 + <strong>New in RC2:</strong>
  270 + </p>
  271 + <ul>
  272 + <li>
  273 + Fixed a bug with serialization of database nulls from
  274 + a DataSet.
  275 + <li>
  276 + Made the addition of the XML document declaration optional,
  277 + with a default of false, as CFWDDX throws an error rather than
  278 + ignoring the XML declaration.
  279 + </li>
  280 + </ul>
  281 + <p>
  282 + <strong>New in RC1:</strong>
  283 + </p>
  284 + <ul>
  285 + <li>
  286 + Added support for WDDX validation via XSD. This is
  287 + supported in two ways - WddxDeserializer.IsValid() will determine if the WDDX
  288 + packet passed to it is valid WDDX without attempting to deserialize it, and is
  289 + extremely fast. There is also an option to validate the WDDX as it is being
  290 + deserialized; this option will cause the deserializer to throw an exception
  291 + detailing what exactly is wrong with any invalid WDDX that it encounters. Note
  292 + that the XSD in question is embedded into the WDDX.Net DLL, meaning that there
  293 + is only one file to work with, and no internet access is required to download
  294 + an external XSD.
  295 + <li>
  296 + Added support for the WDDX "char" element for escaped
  297 + control characters in strings.
  298 + <li>
  299 + Fixed dateTime serialization and deserialization to properly
  300 + convert to/from UTC time.
  301 + </li>
  302 + </ul>
  303 + <b>Serialization:</b>
  304 + <ul>
  305 + <li>
  306 + Can serialize to a string or a pre-existing
  307 + XmlTextWriter. The pre-existing XmlTextWriter can point to a string, a file, a
  308 + network stream, the Response stream in ASP.NET, database, etc...
  309 + <li>
  310 + Any object that implements the IDictionary interface
  311 + is serialized into a WDDX "struct" element. This includes the Hashtable, as
  312 + well as most other classes that contain name/value pairs.
  313 + <li>
  314 + Any object that implements the ICollection interface
  315 + is serialized into a WDDX "array" element. This includes all arrays of all
  316 + data types (jagged, single-, and multi-dimensional) as well as the ArrayList
  317 + class, and most other classes that contain a collection of items. Since WDDX
  318 + doesn't support true multi-dimensional arrays, they are currently flattened to
  319 + a one-dimensional array upon serialization.
  320 + <li>
  321 + A byte array is serialized as a WDDX "binary"
  322 + element.
  323 + <li>
  324 + A DataSet is serialized as a WDDX "recordset"
  325 + element. In the case of a DataSet that contains multiple DataTables, it is
  326 + serialized as a WDDX "struct" element that contains multiple "recordset"
  327 + elements. The name of each DataTable is the key into the struct.
  328 + <li>
  329 + Any object that doesn't fit a pre-defined serializer, but does
  330 + have properties or fields will be serialized as a WDDX "struct"
  331 + element, with the property names/values being the names and
  332 + values in the struct. If the object has no properties or
  333 + fields, the serializer will call the ToString() method of the
  334 + object, and serialize it as a WDDX "string" element.
  335 + </li>
  336 + </ul>
  337 + <b>Deserialization:</b>
  338 + <ul>
  339 + <li>
  340 + Can deserialize from a string or a pre-existing
  341 + XmlTextReader. The pre-existing XmlTextReader can point to a string, a file, a
  342 + network stream, a database, etc...
  343 + <li>
  344 + A WDDX "array" element is deserialized into an ArrayList
  345 + object. In the case of nested (or jagged) arrays, it will be an
  346 + ArrayList object containing other ArrayList objects. Note that
  347 + a single-dimensional ArrayList can be converted to an array of
  348 + native types using the following syntax (C#):<br >
  349 + <tt>int[] intArray =
  350 + (int[])theArrayList.ToArray(typeof(int));</tt>
  351 + <li>
  352 + A WDDX "struct" element is deserialized into a
  353 + Hashtable object.
  354 + <li>
  355 + A WDDX "recordset" element is deserialized into a
  356 + DataSet object. Data types and column names are preserved.
  357 + <li>
  358 + A WDDX "binary" element is deserialized into a byte array.
  359 + </li>
  360 + </ul>
  361 + <b>Still to be done:</b>
  362 + <ul>
  363 + <li>
  364 + Find a way to express ColdFusion's "loose"
  365 + interpretation of ISO8601 dates in XSD form, so that WDDX can be reliably
  366 + validated.
  367 + <li>
  368 + Implement support for the optional "type" attribute
  369 + supported by most WDDX elements. This would allow type preservation for better
  370 + round-trips, but would&nbsp;not benefit any non-.NET languages.&nbsp;
  371 + <li>
  372 + Convert multi-dimensional arrays to nested/jagged
  373 + arrays before serialization.
  374 + <li>
  375 + Optimize array deserialization to produce arrays of
  376 + native types when possible, instead of ArrayList objects.
  377 + <li>
  378 + The above items are more likely to be done if I know someone
  379 + out there needs/will use them. So if any of these sound good,
  380 + <a href="mailto:jmueller@swiftk.com">send me a note</a>!
  381 + </li>
  382 + </ul>
  383 + <p style="FONT-SIZE:10px">
  384 + LEGALESE: This library is provided without any warranty, expressed
  385 + or implied. I hope it's useful to you, but if it's not, well, you
  386 + get what you pay for.
  387 + </p>
  388 + </body>
  389 +</html>
BIN  Release/WDDX.Net Internals.chm
Binary file not shown
BIN  Release/WDDX.Net.chm
Binary file not shown
BIN  Release/Wddx.Net.dll
Binary file not shown
58 WDDX Tests/AssemblyInfo.cs
... ... @@ -0,0 +1,58 @@
  1 +using System.Reflection;
  2 +using System.Runtime.CompilerServices;
  3 +
  4 +//
  5 +// General Information about an assembly is controlled through the following
  6 +// set of attributes. Change these attribute values to modify the information
  7 +// associated with an assembly.
  8 +//
  9 +[assembly: AssemblyTitle("")]
  10 +[assembly: AssemblyDescription("")]
  11 +[assembly: AssemblyConfiguration("")]
  12 +[assembly: AssemblyCompany("")]
  13 +[assembly: AssemblyProduct("")]
  14 +[assembly: AssemblyCopyright("")]
  15 +[assembly: AssemblyTrademark("")]
  16 +[assembly: AssemblyCulture("")]
  17 +
  18 +//
  19 +// Version information for an assembly consists of the following four values:
  20 +//
  21 +// Major Version
  22 +// Minor Version
  23 +// Build Number
  24 +// Revision
  25 +//
  26 +// You can specify all the values or you can default the Revision and Build Numbers
  27 +// by using the '*' as shown below:
  28 +
  29 +[assembly: AssemblyVersion("1.0.*")]
  30 +
  31 +//
  32 +// In order to sign your assembly you must specify a key to use. Refer to the
  33 +// Microsoft .NET Framework documentation for more information on assembly signing.
  34 +//
  35 +// Use the attributes below to control which key is used for signing.
  36 +//
  37 +// Notes:
  38 +// (*) If no key is specified, the assembly is not signed.
  39 +// (*) KeyName refers to a key that has been installed in the Crypto Service
  40 +// Provider (CSP) on your machine. KeyFile refers to a file which contains
  41 +// a key.
  42 +// (*) If the KeyFile and the KeyName values are both specified, the
  43 +// following processing occurs:
  44 +// (1) If the KeyName can be found in the CSP, that key is used.
  45 +// (2) If the KeyName does not exist and the KeyFile does exist, the key
  46 +// in the KeyFile is installed into the CSP and used.
  47 +// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
  48 +// When specifying the KeyFile, the location of the KeyFile should be
  49 +// relative to the project output directory which is
  50 +// %Project Directory%\obj\<configuration>. For example, if your KeyFile is
  51 +// located in the project directory, you would specify the AssemblyKeyFile
  52 +// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
  53 +// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
  54 +// documentation for more information on this.
  55 +//
  56 +[assembly: AssemblyDelaySign(false)]
  57 +[assembly: AssemblyKeyFile("")]
  58 +[assembly: AssemblyKeyName("")]
788 WDDX Tests/UnitTests.cs
... ... @@ -0,0 +1,788 @@
  1 +using System;
  2 +using System.Collections;
  3 +using System.Data;
  4 +using System.Globalization;
  5 +
  6 +using Mueller.Wddx;
  7 +
  8 +using NUnit.Framework;
  9 +
  10 +namespace Mueller.Wddx.Tests
  11 +{
  12 + /// <summary>
  13 + /// This is an NUnit test suite.
  14 + /// Get NUnit here: http://nunit.sourceforge.net
  15 + /// </summary>
  16 + [TestFixture]
  17 + public class WddxTest
  18 + {
  19 + private string basicPacket = "<wddxPacket version=\"1.0\"><header /><data>{0}</data></wddxPacket>";
  20 +
  21 + public WddxTest() {}
  22 +
  23 + //added by bsoylu 9/20/2011
  24 + /// <summary>
  25 + /// Returns the correctly formatted date in ISO8601 format
  26 + /// </summary>
  27 + /// <param name="localDateTime">a datetime value in local time format.</param>
  28 +
  29 + private String ISO8601DateFormatter(DateTime localDateTime)
  30 + {
  31 + string IsoDateString = "";
  32 + string postfix = "";
  33 + TimeZone localZone = TimeZone.CurrentTimeZone;
  34 + TimeSpan localOffset;
  35 +
  36 + //get offset from our timezone to UTC
  37 + localOffset = localZone.GetUtcOffset(localDateTime);
  38 +
  39 + //format first part of the time
  40 + IsoDateString = localDateTime.ToString(@"yyyy-MM-dd\THH:mm:ss", DateTimeFormatInfo.InvariantInfo);
  41 + //check on hours postfix
  42 + postfix = localOffset.TotalHours.ToString();
  43 + //if there is a period replace with colon otherwise add :0
  44 + if (postfix.Contains("."))
  45 + {
  46 + postfix = postfix.Replace(".", ":");
  47 + }
  48 + else if (Math.Abs(localOffset.TotalHours) > 0) // if we have only zero difference than leave of offset
  49 + {
  50 + postfix += ":0";
  51 + }
  52 +
  53 +
  54 + return IsoDateString + postfix;
  55 + }
  56 +
  57 +
  58 + // *** ACTUAL TESTS BEGIN HERE ***
  59 +
  60 + /// <summary>
  61 + /// Tests serialization of the basic WDDX data types.
  62 + /// </summary>
  63 + [Test]
  64 + public void TestBasicTypeSerialization()
  65 + {
  66 + string testString = "This is a test.\nDo not panic.";
  67 + bool testBool = false;
  68 + int testInt = 10;
  69 + short testShort = 34;
  70 + long testLong = 345678923456789123;
  71 + float testFloat = -1.23f;
  72 + double testDouble = 34.672d;
  73 + decimal testDecimal = 32.4562203m;
  74 + DateTime testDate = new DateTime(2001, 6, 17, 12, 00, 30,System.DateTimeKind.Local); //we need to be specific so our parsing to and from UTC is correct
  75 +
  76 + string expectedString = String.Format(basicPacket, "<string>This is a test.<char code=\"0a\" />Do not panic.</string>");
  77 + string expectedBool = String.Format(basicPacket, "<boolean value=\"false\" />");
  78 + string expectedInt = String.Format(basicPacket, "<number>10</number>");
  79 + string expectedShort = String.Format(basicPacket, "<number>34</number>");
  80 + string expectedLong = String.Format(basicPacket, "<number>345678923456789123</number>");
  81 + string expectedFloat = String.Format(basicPacket, "<number>-1.23</number>");
  82 + string expectedDouble = String.Format(basicPacket, "<number>34.672</number>");
  83 + string expectedDecimal = String.Format(basicPacket, "<number>32.4562203</number>");
  84 + string expectedDate = String.Format(basicPacket, "<dateTime>" + ISO8601DateFormatter(testDate)+ "</dateTime>");
  85 + string expectedNull = String.Format(basicPacket, "<null />");
  86 +
  87 + WddxSerializer serializer = new WddxSerializer();
  88 +
  89 + string stringPacket = serializer.Serialize(testString);
  90 +
  91 + Assert.AreEqual(expectedString, stringPacket);
  92 +
  93 + string boolPacket = serializer.Serialize(testBool);
  94 + Assert.AreEqual(expectedBool, boolPacket);
  95 +
  96 + string intPacket = serializer.Serialize(testInt);
  97 + Assert.AreEqual(expectedInt, intPacket);
  98 +
  99 + string shortPacket = serializer.Serialize(testShort);
  100 + Assert.AreEqual(expectedShort, shortPacket);
  101 +
  102 + string longPacket = serializer.Serialize(testLong);
  103 + Assert.AreEqual(expectedLong, longPacket);
  104 +
  105 + string floatPacket = serializer.Serialize(testFloat);
  106 + Assert.AreEqual(expectedFloat, floatPacket);
  107 +
  108 + string doublePacket = serializer.Serialize(testDouble);
  109 + Assert.AreEqual(expectedDouble, doublePacket);
  110 +
  111 + string decimalPacket = serializer.Serialize(testDecimal);
  112 + Assert.AreEqual(expectedDecimal, decimalPacket);
  113 +
  114 + string datePacket = serializer.Serialize(testDate);
  115 + Assert.AreEqual(expectedDate, datePacket);
  116 +
  117 + string nullPacket = serializer.Serialize(null);
  118 + Assert.AreEqual(expectedNull, nullPacket);
  119 + }
  120 +
  121 + /// <summary>
  122 + /// Tests deserialization of basic data types.
  123 + /// </summary>
  124 + [Test]
  125 + public void TestBasicTypeDeserialization()
  126 + {
  127 + string expectedString = "This is a test.\nDo not panic.";
  128 + bool expectedBool = false;
  129 + int expectedInt = 10;
  130 + long expectedLong = 3147483647;
  131 + float expectedFloat = -1.23f;
  132 + DateTime expectedDate = new DateTime(2001, 6, 17, 12, 00, 30,System.DateTimeKind.Local);
  133 + DateTime expectedCFDate = new DateTime(2002, 6, 26, 5, 0, 0, System.DateTimeKind.Local);
  134 + //remove one hour from CF time to check on calculations -- bsoylu
  135 + TimeZone localZone = TimeZone.CurrentTimeZone;
  136 + TimeSpan localOffset =localZone.GetUtcOffset(expectedDate);
  137 + TimeSpan minusOneHr = new System.TimeSpan(-1, 0, 0);
  138 + expectedCFDate = expectedCFDate.Add(minusOneHr);
  139 +
  140 + string stringPacket = String.Format(basicPacket, "<string>This is a test.<char code=\"0a\" />Do not panic.</string>");
  141 + string booleanPacket = String.Format(basicPacket, "<boolean value=\"false\" />");
  142 + string intPacket = String.Format(basicPacket, "<number>10</number>");
  143 + string longPacket = String.Format(basicPacket, "<number>3147483647</number>");
  144 + string floatPacket = String.Format(basicPacket, "<number>-1.23</number>");
  145 + string datePacket = String.Format(basicPacket, "<dateTime>" + ISO8601DateFormatter(expectedDate) + "</dateTime>");
  146 + string datePacketNoTZ = String.Format(basicPacket, "<dateTime>2001-06-17T12:00:30</dateTime>"); //no time zone is assumed to be zulu in ColFusion, will be converted to local time
  147 + string bogusCFDate = String.Format(basicPacket, "<dateTime>2002-6-26T4:0:0" + localOffset.TotalHours + ":0</dateTime>");
  148 + string nullPacket = String.Format(basicPacket, "<null />");
  149 +
  150 + WddxDeserializer deserializer = new WddxDeserializer();
  151 +
  152 + string resultString = (string)deserializer.Deserialize(stringPacket);
  153 + Assert.AreEqual(expectedString, resultString);
  154 +
  155 + bool resultBool = (bool)deserializer.Deserialize(booleanPacket);
  156 + Assert.AreEqual(expectedBool, resultBool);
  157 +
  158 + int resultInt = (int)deserializer.Deserialize(intPacket);
  159 + Assert.AreEqual(expectedInt, resultInt);
  160 +
  161 + long resultLong = (long)deserializer.Deserialize(longPacket);
  162 + Assert.AreEqual(expectedLong, resultLong);
  163 +
  164 + float resultFloat = (float)deserializer.Deserialize(floatPacket);
  165 + Assert.AreEqual(expectedFloat, resultFloat);
  166 +
  167 + DateTime resultDate = (DateTime)deserializer.Deserialize(datePacket);
  168 + Assert.AreEqual(expectedDate, resultDate);
  169 +
  170 + DateTime resultDateNoTZ = (DateTime)deserializer.Deserialize(datePacketNoTZ);
  171 + Assert.AreEqual(expectedDate, resultDateNoTZ);
  172 +
  173 + DateTime resultCFDate = (DateTime)deserializer.Deserialize(bogusCFDate);
  174 + Assert.AreEqual(expectedCFDate, resultCFDate);
  175 +
  176 + object resultNull = deserializer.Deserialize(nullPacket);
  177 + Assert.IsNull(resultNull);
  178 + }
  179 +
  180 + /// <summary>
  181 + /// Tests serialization of basic one-dimensional arrays.
  182 + /// </summary>
  183 + [Test]
  184 + public void TestBasicArraySerialization()
  185 + {
  186 + int[] intArray = {1,2,3,4,5,6,7,8,9,10};
  187 + string[] stringArray =
  188 + {
  189 + // This is the official list of
  190 + // metasyntactic variable names,
  191 + // in order starting with "foo".
  192 + "foo",
  193 + "bar",
  194 + "baz",
  195 + "qux",
  196 + "quux",
  197 + "corge",
  198 + "grault",
  199 + "garply",
  200 + "waldo",
  201 + "fred",
  202 + "plugh",
  203 + "xyzzy",
  204 + "thud"
  205 + };
  206 +
  207 + string expectedInt = String.Format(basicPacket, "<array length=\"10\"><number>1</number><number>2</number><number>3</number><number>4</number><number>5</number><number>6</number><number>7</number><number>8</number><number>9</number><number>10</number></array>");
  208 + string expectedString = String.Format(basicPacket, "<array length=\"13\"><string>foo</string><string>bar</string><string>baz</string><string>qux</string><string>quux</string><string>corge</string><string>grault</string><string>garply</string><string>waldo</string><string>fred</string><string>plugh</string><string>xyzzy</string><string>thud</string></array>");
  209 +
  210 + WddxSerializer serializer = new WddxSerializer();
  211 +
  212 + string intPacket = serializer.Serialize(intArray);
  213 + Assert.AreEqual(expectedInt, intPacket);
  214 +
  215 + string stringPacket = serializer.Serialize(stringArray);
  216 + Assert.AreEqual(expectedString, stringPacket);
  217 + }
  218 +
  219 + /// <summary>
  220 + /// Tests deserialization of basic one-dimensional arrays.
  221 + /// </summary>
  222 + [Test]
  223 + public void TestBasicArrayDeserialization()
  224 + {
  225 + string intPacket = String.Format(basicPacket, "<array length=\"10\"><number>1</number><number>2</number><number>3</number><number>4</number><number>5</number><number>6</number><number>7</number><number>8</number><number>9</number><number>10</number></array>");
  226 + string stringPacket = String.Format(basicPacket, "<array length=\"13\"><string>foo</string><string>bar</string><string>baz</string><string>qux</string><string>quux</string><string>corge</string><string>grault</string><string>garply</string><string>waldo</string><string>fred</string><string>plugh</string><string>xyzzy</string><string>thud</string></array>");
  227 +
  228 + int[] expectedInt = {1,2,3,4,5,6,7,8,9,10};
  229 + string[] expectedString =
  230 + {
  231 + "foo",
  232 + "bar",
  233 + "baz",
  234 + "qux",
  235 + "quux",
  236 + "corge",
  237 + "grault",
  238 + "garply",
  239 + "waldo",
  240 + "fred",
  241 + "plugh",
  242 + "xyzzy",
  243 + "thud"
  244 + };
  245 +
  246 + WddxDeserializer deserializer = new WddxDeserializer();
  247 +
  248 + ArrayList intResult = (ArrayList)deserializer.Deserialize(intPacket);
  249 + int[] intArray = (int[])intResult.ToArray(typeof(int));
  250 + for (int i=0; i < expectedInt.Length; i++)
  251 + {
  252 + Assert.AreEqual(expectedInt[i], intArray[i]);
  253 + }
  254 +
  255 + ArrayList stringResult = (ArrayList)deserializer.Deserialize(stringPacket);
  256 + string[] stringArray = (string[])stringResult.ToArray(typeof(string));
  257 + for (int i=0; i < expectedString.Length; i++)
  258 + {
  259 + Assert.AreEqual(expectedString[i], stringArray[i]);
  260 + }
  261 + }
  262 +
  263 + /// <summary>
  264 + /// Tests the serialization of binary data (a byte array).
  265 + /// </summary>
  266 + [Test]
  267 + public void TestBinarySerialization()
  268 + {
  269 + byte[] byteArray = {0x4a, 0x6f, 0x65, 0x6c, 0x20, 0x72, 0x6f, 0x63, 0x6b, 0x73, 0x21};
  270 +
  271 + string expectedBinary = String.Format(basicPacket, "<binary length=\"11\">Sm9lbCByb2NrcyE=</binary>");
  272 +
  273 + WddxSerializer serializer = new WddxSerializer();
  274 +
  275 + string binaryPacket = serializer.Serialize(byteArray);
  276 + Assert.AreEqual(expectedBinary, binaryPacket);
  277 + }
  278 +
  279 + /// <summary>
  280 + /// Tests the deserialization of binary data.
  281 + /// </summary>
  282 + [Test]
  283 + public void TestBinaryDeserialization()
  284 + {
  285 + string binaryPacket = String.Format(basicPacket, "<binary length=\"11\">Sm9lbCByb2NrcyE=</binary>");
  286 + string binaryPacketNoLength = String.Format(basicPacket, "<binary>Sm9lbCByb2NrcyE=</binary>");
  287 +
  288 + byte[] expectedBytes = {0x4a, 0x6f, 0x65, 0x6c, 0x20, 0x72, 0x6f, 0x63, 0x6b, 0x73, 0x21};
  289 +
  290 + WddxDeserializer deserializer = new WddxDeserializer();
  291 +
  292 + byte[] binaryResult = (byte[])deserializer.Deserialize(binaryPacket);
  293 + for (int i=0; i < expectedBytes.Length; i++)
  294 + {
  295 + Assert.AreEqual(expectedBytes[i], binaryResult[i]);
  296 + }
  297 +
  298 + binaryResult = (byte[])deserializer.Deserialize(binaryPacketNoLength);
  299 + for (int i=0; i < expectedBytes.Length; i++)
  300 + {
  301 + Assert.AreEqual(expectedBytes[i], binaryResult[i]);
  302 + }
  303 + }
  304 +
  305 + /// <summary>
  306 + /// Tests the serialization of a basic WDDX struct (a <see cref="Hashtable"/> in this case).
  307 + /// </summary>
  308 + [Test]
  309 + public void TestBasicStructSerialization()
  310 + {
  311 + DateTime expectedDate = new DateTime(1998, 6, 12, 4, 32, 12,System.DateTimeKind.Local); //specifically set to local time
  312 + TimeZone localZone = TimeZone.CurrentTimeZone;
  313 + TimeSpan localOffset = localZone.GetUtcOffset(expectedDate);
  314 +
  315 + Hashtable thisTable = new Hashtable();
  316 + thisTable.Add("aNull", null);
  317 + thisTable.Add("aString", "a string");
  318 + thisTable.Add("aNumber", -12.456);
  319 + thisTable.Add("aBoolean", true);
  320 + thisTable.Add("aDateTime", expectedDate);
  321 +
  322 + string expectedStruct = String.Format(basicPacket, "<struct><var name=\"aString\"><string>a string</string></var><var name=\"aDateTime\"><dateTime>" + ISO8601DateFormatter(expectedDate) + "</dateTime></var><var name=\"aNumber\"><number>-12.456</number></var><var name=\"aNull\"><null /></var><var name=\"aBoolean\"><boolean value=\"true\" /></var></struct>");
  323 +
  324 + WddxSerializer serializer = new WddxSerializer();
  325 +
  326 + string structPacket = serializer.Serialize(thisTable);
  327 + Assert.AreEqual(expectedStruct, structPacket);
  328 + }
  329 +
  330 + /// <summary>
  331 + /// Tests the deserialization of a basic WDDX struct.
  332 + /// </summary>
  333 + [Test]
  334 + public void TestBasicStructDeserialization()
  335 + {
  336 + DateTime expectedDate = new DateTime(1998, 6, 12, 4, 32, 12, System.DateTimeKind.Local);
  337 +
  338 + string structPacket = String.Format(basicPacket, "<struct><var name=\"aNumber\"><number>-12.456</number></var><var name=\"aBoolean\"><boolean value=\"true\" /></var><var name=\"aDateTime\"><dateTime>" + ISO8601DateFormatter(expectedDate) + "</dateTime></var><var name=\"aNull\"><null /></var><var name=\"aString\"><string>a string</string></var></struct>");
  339 +
  340 + WddxDeserializer deserializer = new WddxDeserializer();
  341 +
  342 + Hashtable thisTable = (Hashtable)deserializer.Deserialize(structPacket);
  343 + Assert.AreEqual(null, thisTable["aNull"]);
  344 + Assert.AreEqual("a string", (string)thisTable["aString"]);
  345 + Assert.AreEqual(-12.456f, (float)thisTable["aNumber"]);
  346 + /*
  347 + if (thisTable["aNumber"].GetType().Name == "Single")
  348 + {
  349 + }
  350 + if (thisTable["aNumber"].GetType().Name == "Decimal")
  351 + {
  352 + Assert.AreEqual(-12.456m, (decimal)thisTable["aNumber"]);
  353 + }
  354 + */
  355 + Assert.AreEqual(true, (bool)thisTable["aBoolean"]);
  356 + Assert.AreEqual(expectedDate, (DateTime)thisTable["aDateTime"]);
  357 + }
  358 +
  359 + /// <summary>
  360 + /// Tests the serialization of nested and two-dimensional arrays.
  361 + /// </summary>
  362 + [Test]
  363 + public void TestComplexArraySerialization()
  364 + {
  365 + int[][] jaggedArray =
  366 + {
  367 + new int[] {1,2,3,4,5,6},
  368 + new int[] {1,2,3},
  369 + new int[] {1,2,3,4,5,6,7,8}
  370 + };
  371 +
  372 + int[,] matrix =
  373 + {
  374 + {1,1},
  375 + {2,2},
  376 + {3,5},
  377 + {4,5}
  378 + };
  379 +
  380 + string expectedJagged = String.Format(basicPacket, "<array length=\"3\"><array length=\"6\"><number>1</number><number>2</number><number>3</number><number>4</number><number>5</number><number>6</number></array><array length=\"3\"><number>1</number><number>2</number><number>3</number></array><array length=\"8\"><number>1</number><number>2</number><number>3</number><number>4</number><number>5</number><number>6</number><number>7</number><number>8</number></array></array>");
  381 + // WDDX doesn't support multi-dimensional arrays, so they are flattened
  382 + // to a one-dimensional array (but no data is lost).
  383 + string expectedMatrix = String.Format(basicPacket, "<array length=\"8\"><number>1</number><number>1</number><number>2</number><number>2</number><number>3</number><number>5</number><number>4</number><number>5</number></array>");
  384 +
  385 + WddxSerializer serializer = new WddxSerializer();
  386 +
  387 + string jaggedPacket = serializer.Serialize(jaggedArray);
  388 + Assert.AreEqual(expectedJagged, jaggedPacket);
  389 +
  390 + string matrixPacket = serializer.Serialize(matrix);
  391 + Assert.AreEqual(expectedMatrix, matrixPacket);
  392 + }
  393 +
  394 + /// <summary>
  395 + /// Tests the deserialization of nested arrays.
  396 + /// </summary>
  397 + [Test]
  398 + public void TestComplexArrayDeserialization()
  399 + {
  400 + string jaggedPacket = String.Format(basicPacket, "<array length=\"3\"><array length=\"6\"><number>1</number><number>2</number><number>3</number><number>4</number><number>5</number><number>6</number></array><array length=\"3\"><number>1</number><number>2</number><number>3</number></array><array length=\"8\"><number>1</number><number>2</number><number>3</number><number>4</number><number>5</number><number>6</number><number>7</number><number>8</number></array></array>");
  401 +
  402 + int[][] jaggedArray =
  403 + {
  404 + new int[] {1,2,3,4,5,6},
  405 + new int[] {1,2,3},
  406 + new int[] {1,2,3,4,5,6,7,8}
  407 + };
  408 +
  409 + WddxDeserializer deserializer = new WddxDeserializer();
  410 +
  411 + ArrayList resultList = (ArrayList)deserializer.Deserialize(jaggedPacket);
  412 + // jagged arrays come out as an ArrayList containing ArrayLists,
  413 + // and must be accessed as-is, or converted from the inside out.
  414 +
  415 + for (int i=0; i < jaggedArray.Length; i++)
  416 + {
  417 + for (int j=0; j < jaggedArray[i].Length; j++)
  418 + {
  419 + Assert.AreEqual(jaggedArray[i][j], ((ArrayList)resultList[i])[j]);
  420 + }
  421 + }
  422 + }
  423 +
  424 + /// <summary>
  425 + /// Tests the serialization of both simple and complex <see cref="DataSet"/>s.
  426 + /// </summary>
  427 + [Test]
  428 + public void TestDataSetSerialization()
  429 + {
  430 + DataSetGenerator gen = new DataSetGenerator();
  431 + DataSet simpleDataSet = gen.MakeSimpleDataSet();
  432 +
  433 + string expectedSimple = String.Format(basicPacket, "<recordset rowCount=\"3\" fieldNames=\"id,ParentItem\"><field name=\"id\"><number>0</number><number>1</number><number>2</number></field><field name=\"ParentItem\"><string>ParentItem 0</string><string>ParentItem 1</string><string>ParentItem 2</string></field></recordset>");
  434 + string expectedComplex = String.Format(basicPacket, "<struct><var name=\"ParentTable\"><recordset rowCount=\"3\" fieldNames=\"id,ParentItem\"><field name=\"id\"><number>0</number><number>1</number><number>2</number></field><field name=\"ParentItem\"><string>ParentItem 0</string><string>ParentItem 1</string><string>ParentItem 2</string></field></recordset></var><var name=\"ChildTable\"><recordset rowCount=\"15\" fieldNames=\"ChildID,ChildItem,ParentID\"><field name=\"ChildID\"><number>0</number><number>1</number><number>2</number><number>3</number><number>4</number><number>5</number><number>6</number><number>7</number><number>8</number><number>9</number><number>10</number><number>11</number><number>12</number><number>13</number><number>14</number></field><field name=\"ChildItem\"><string>Item 0</string><string>Item 1</string><string>Item 2</string><string>Item 3</string><string>Item 4</string><string>Item 0</string><string>Item 1</string><string>Item 2</string><null /><string>Item 4</string><string>Item 0</string><string>Item 1</string><string>Item 2</string><string>Item 3</string><string>Item 4</string></field><field name=\"ParentID\"><number>0</number><number>0</number><number>0</number><number>0</number><number>0</number><number>1</number><number>1</number><number>1</number><number>1</number><number>1</number><number>2</number><number>2</number><number>2</number><number>2</number><number>2</number></field></recordset></var></struct>");
  435 +
  436 + WddxSerializer serializer = new WddxSerializer();
  437 +
  438 + string simplePacket = serializer.Serialize(simpleDataSet);
  439 + Assert.AreEqual(expectedSimple, simplePacket);
  440 +
  441 + DataSet complexDataSet = gen.MakeComplexDataSet();
  442 +
  443 + string complexPacket = serializer.Serialize(complexDataSet);
  444 + Assert.AreEqual(expectedComplex, complexPacket);
  445 + }
  446 +
  447 + /// <summary>
  448 + /// Tests the deserialization of a simple WDDX recordset.
  449 + /// </summary>
  450 + [Test]
  451 + public void TestDataSetDeserialization()
  452 + {
  453 + string datasetPacket = String.Format(basicPacket, "<recordset rowCount=\"3\" fieldNames=\"id,ParentItem\"><field name=\"id\"><number>0</number><number>1</number><number>2</number></field><field name=\"ParentItem\"><string>ParentItem 0</string><string>ParentItem 1</string><string>ParentItem 2</string></field></recordset>");
  454 +
  455 + DataSetGenerator gen = new DataSetGenerator();
  456 + DataSet expectedDataSet = gen.MakeSimpleDataSet();
  457 +
  458 + WddxDeserializer deserializer = new WddxDeserializer();
  459 +
  460 + DataSet resultDataSet = (DataSet)deserializer.Deserialize(datasetPacket);
  461 + for (int i=0; i < expectedDataSet.Tables[0].Rows.Count; i++)
  462 + {
  463 + for (int j=0; j < expectedDataSet.Tables[0].Columns.Count; j++)
  464 + {
  465 + Assert.AreEqual(expectedDataSet.Tables[0].Rows[i][j], resultDataSet.Tables[0].Rows[i][j]);
  466 + }
  467 + }
  468 + }
  469 +
  470 + /// <summary>
  471 + /// Tests the serialization of a complex Hashtable, containing a number of other data types and objects.
  472 + /// </summary>
  473 + [Test]
  474 + public void TestComplexStructSerialization()
  475 + {
  476 + byte[] byteArray = {0x4a, 0x6f, 0x65, 0x6c, 0x20, 0x72, 0x6f, 0x63, 0x6b, 0x73, 0x21};
  477 + ArrayList mixedArray = new ArrayList();
  478 + mixedArray.Add(10);
  479 + mixedArray.Add("second element");
  480 +
  481 + DataSetGenerator gen = new DataSetGenerator();
  482 + DataSet simpleDataSet = gen.MakeSimpleDataSet();
  483 +
  484 + DateTime expectedDate = new DateTime(1998, 6, 12, 4, 32, 12,System.DateTimeKind.Local);
  485 +
  486 + Hashtable thisTable = new Hashtable();
  487 + thisTable.Add("aNull", null);
  488 + thisTable.Add("aString", "a string");
  489 + thisTable.Add("aNumber", -12.456);
  490 + thisTable.Add("aBoolean", true);
  491 + thisTable.Add("aDateTime", expectedDate);
  492 + thisTable.Add("aBinary", byteArray);
  493 + thisTable.Add("anArray", mixedArray);
  494 + thisTable.Add("aRecordset", simpleDataSet);
  495 +
  496 + string expectedStruct = GetComplexPacket(expectedDate);
  497 +
  498 + WddxSerializer serializer = new WddxSerializer();
  499 +
  500 + string structPacket = serializer.Serialize(thisTable);
  501 + Assert.AreEqual(expectedStruct, structPacket);
  502 + }
  503 +
  504 + /// <summary>
  505 + /// Tests the deserialization of a complex struct.
  506 + /// </summary>
  507 + [Test]
  508 + public void TestComplexStructDeserialization()
  509 + {
  510 + DateTime expectedDate = new DateTime(1998, 6, 12, 4, 32, 12);
  511 +
  512 + string structPacket = GetComplexPacket(expectedDate);
  513 +
  514 + WddxDeserializer deserializer = new WddxDeserializer();
  515 +
  516 + Hashtable resultTable = (Hashtable)deserializer.Deserialize(structPacket);
  517 +
  518 + }
  519 +
  520 + /// <summary>
  521 + /// Tests the serialization of a generic object that does not fit any of the pre-defined types.
  522 + /// In this case, the properties of the object will be serialized as a WDDX struct.
  523 + /// </summary>
  524 + [Test]
  525 + public void TestGenericSerialization()
  526 + {
  527 + TestObject obj = new TestObject();
  528 + obj.foo = "a string";
  529 + obj.bar = 42;
  530 + obj.baz = new DateTime(1975, 6, 17,0,0,0,System.DateTimeKind.Local);
  531 +
  532 + string expectedGeneric = String.Format(basicPacket, "<struct><var name=\"foo\"><string>a string</string></var><var name=\"bar\"><number>42</number></var><var name=\"baz\"><dateTime>" + ISO8601DateFormatter(obj.baz) + "</dateTime></var></struct>");
  533 +
  534 + WddxSerializer serializer = new WddxSerializer();
  535 +
  536 + string genericPacket = serializer.Serialize(obj);
  537 + Assert.AreEqual(expectedGeneric, genericPacket);
  538 + }
  539 +
  540 + /// <summary>
  541 + /// Tests the validity of a packet.
  542 + /// </summary>
  543 + [Test]
  544 + public void TestIsValid()
  545 + {
  546 + DateTime expectedDate = new DateTime(1998, 6, 12, 4, 32, 12,System.DateTimeKind.Local);
  547 + WddxDeserializer deserializer = new WddxDeserializer();
  548 + //string packet = String.Format(basicPacket, "<struct><var name=\"valor\"><string /></var></struct>");
  549 + string packet = GetComplexPacket(expectedDate);
  550 + Hashtable resultTable = (Hashtable)deserializer.Deserialize(packet);
  551 +
  552 + Assert.IsTrue(deserializer.IsValid(packet), "Packet is not valid when it should be");
  553 + Assert.IsTrue(!deserializer.IsValid(GetBrokenPacket()), "Packet is valid when it should not be.");
  554 +
  555 + }
  556 +
  557 + /// <summary>
  558 + /// Tests performing validation while deserializing.
  559 + /// </summary>
  560 + [Test]
  561 + [ExpectedException(typeof(WddxValidationException))]
  562 + public void TestValidDeserialization()
  563 + {
  564 + WddxDeserializer deserializer = new WddxDeserializer();
  565 +
  566 + // test with an invalid packet
  567 + Hashtable resultTable1 = (Hashtable)deserializer.Deserialize(GetBrokenPacket(), true);
  568 + }
  569 +
  570 + /// <summary>
  571 + /// Test to reproduce a reported deserialization bug.
  572 + /// In versions prior to 1.0.3, this packet would cause
  573 + /// an infinite loop.
  574 + /// </summary>
  575 + [Test]
  576 + public void TestStringDeserializationBug()
  577 + {
  578 + string packet = String.Format(basicPacket, "<struct><var name=\"valor\"><string /></var></struct>");
  579 +
  580 + WddxDeserializer deserializer = new WddxDeserializer();
  581 +
  582 + Hashtable result = (Hashtable)deserializer.Deserialize(packet);
  583 +
  584 + string content = (string)result["valor"];
  585 +
  586 + //Assert.AreEqual( "Empty string not deserialized correctly.", String.Empty, content);
  587 + //nunit changed order -- bsoylu
  588 + Assert.AreEqual(String.Empty, content, "Empty string not deserialized correctly.");
  589 + }
  590 +
  591 + /// <summary>
  592 + /// Test to reproduce a decimal conversion.
  593 + /// In versions prior to 1.0.4, this packet would cause wrong conversion
  594 + /// due to loss of precision
  595 + /// </summary>
  596 + [Test]
  597 + public void TestDecimalDeserializationBug()
  598 + {
  599 + string packet = String.Format(basicPacket, "<struct><var name=\"aDecimal\"><number>154523.85</number></var></struct>");
  600 +
  601 + WddxDeserializer deserializer = new WddxDeserializer();
  602 +
  603 + Hashtable result = (Hashtable)deserializer.Deserialize(packet);
  604 +
  605 + decimal content = (decimal)result["aDecimal"];
  606 +
  607 + //nunit changed order -- bsoylu
  608 + Assert.AreEqual(154523.85m, content, "Decimal is not deserialized correctly.");
  609 +
  610 + }
  611 +
  612 + private string GetComplexPacket(DateTime expectedDate)
  613 + {
  614 + //return String.Format(basicPacket, "<struct><var name=\"aNull\"><null /></var><var name=\"anArray\"><array length=\"2\"><number>10</number><string>second element</string></array></var><var name=\"aNumber\"><number>-12.456</number></var><var name=\"aRecordset\"><recordset rowCount=\"3\" fieldNames=\"id,ParentItem\"><field name=\"id\"><number>0</number><number>1</number><number>2</number></field><field name=\"ParentItem\"><string>ParentItem 0</string><string>ParentItem 1</string><string>ParentItem 2</string></field></recordset></var><var name=\"aBoolean\"><boolean value=\"true\" /></var><var name=\"aDateTime\"><dateTime>" + ISO8601DateFormatter(expectedDate) + "</dateTime></var><var name=\"aBinary\"><binary length=\"11\">Sm9lbCByb2NrcyE=</binary></var><var name=\"aString\"><string>a string</string></var></struct>");
  615 + //reordered return as expected -- bsoylu
  616 + return String.Format(basicPacket, "<struct><var name=\"aBoolean\"><boolean value=\"true\" /></var><var name=\"anArray\"><array length=\"2\"><number>10</number><string>second element</string></array></var><var name=\"aBinary\"><binary length=\"11\">Sm9lbCByb2NrcyE=</binary></var><var name=\"aDateTime\"><dateTime>" + ISO8601DateFormatter(expectedDate) + "</dateTime></var><var name=\"aRecordset\"><recordset rowCount=\"3\" fieldNames=\"id,ParentItem\"><field name=\"id\"><number>0</number><number>1</number><number>2</number></field><field name=\"ParentItem\"><string>ParentItem 0</string><string>ParentItem 1</string><string>ParentItem 2</string></field></recordset></var><var name=\"aString\"><string>a string</string></var><var name=\"aNull\"><null /></var><var name=\"aNumber\"><number>-12.456</number></var></struct>");
  617 + }
  618 +
  619 + private string GetBrokenPacket()
  620 + {
  621 + // This packet has two deliberate errors:
  622 + // the date is in an invalid format, and there is
  623 + // an illegal character in the base-64-encoded binary data.
  624 + // Both errors should be caught by the XSD used for validation.
  625 + return String.Format(basicPacket, "<struct><var name=\"aNull\"><null /></var><var name=\"anArray\"><array length=\"2\"><number>10</number><string>second element</string></array></var><var name=\"aNumber\"><number>-12.456</number></var><var name=\"aRecordset\"><recordset rowCount=\"3\" fieldNames=\"id,ParentItem\"><field name=\"id\"><number>0</number><number>1</number><number>2</number></field><field name=\"ParentItem\"><string>ParentItem 0</string><string>ParentItem 1</string><string>ParentItem 2</string></field></recordset></var><var name=\"aBoolean\"><boolean value=\"true\" /></var><var name=\"aDateTime\"><dateTime>6/17/75</dateTime></var><var name=\"aBinary\"><binary length=\"11\">Sm9lb%Byb2NrcyE=</binary></var><var name=\"aString\"><string>a string</string></var></struct>");
  626 + }
  627 + }
  628 +
  629 + /// <summary>
  630 + /// Generic object for the <see cref="WddxTest.TestGenericSerialization"/> test.
  631 + /// </summary>
  632 + internal struct TestObject
  633 + {
  634 + public string foo;
  635 + public int bar;
  636 + public DateTime baz;
  637 + }
  638 +
  639 + /// <summary>
  640 + /// Generates DataSets for the DataSet test, without requiring a database.
  641 + /// </summary>
  642 + internal class DataSetGenerator
  643 + {
  644 + private DataSet myDataSet;
  645 +
  646 + public DataSet MakeSimpleDataSet()
  647 + {
  648 + MakeParentTable();
  649 + return myDataSet;
  650 + }
  651 +
  652 + public DataSet MakeComplexDataSet()
  653 + {
  654 + MakeChildTable();
  655 +
  656 + DataRelation myDataRelation;
  657 + DataColumn parentColumn;
  658 + DataColumn childColumn;
  659 + parentColumn = myDataSet.Tables["ParentTable"].Columns["id"];
  660 + childColumn = myDataSet.Tables["ChildTable"].Columns["ParentID"];
  661 + myDataRelation = new DataRelation("parent2Child", parentColumn, childColumn);
  662 + myDataSet.Tables["ChildTable"].ParentRelations.Add(myDataRelation);
  663 +
  664 + return myDataSet;
  665 + }
  666 +
  667 + private DataTable MakeParentTable()
  668 + {
  669 + // Create a new DataTable.
  670 + System.Data.DataTable myDataTable = new DataTable("ParentTable");
  671 + // Declare variables for DataColumn and DataRow objects.
  672 + DataColumn myDataColumn;
  673 + DataRow myDataRow;
  674 +
  675 + // Create new DataColumn, set DataType, ColumnName and add to DataTable.
  676 + myDataColumn = new DataColumn();
  677 + myDataColumn.DataType = System.Type.GetType("System.Int32");
  678 + myDataColumn.ColumnName = "id";
  679 + myDataColumn.ReadOnly = true;
  680 + myDataColumn.Unique = true;
  681 + // Add the Column to the ColumnsCollection.
  682 + myDataTable.Columns.Add(myDataColumn);
  683 +
  684 + // Create second column.
  685 + myDataColumn = new DataColumn();
  686 + myDataColumn.DataType = System.Type.GetType("System.String");
  687 + myDataColumn.ColumnName = "ParentItem";
  688 + myDataColumn.AutoIncrement = false;
  689 + myDataColumn.Caption = "ParentItem";
  690 + myDataColumn.ReadOnly = false;
  691 + myDataColumn.Unique = false;
  692 + // Add the column to the table.
  693 + myDataTable.Columns.Add(myDataColumn);