Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit c6fa63e14208cde3243d1176f038da2342a175ab @johnsheehan johnsheehan committed Nov 15, 2009
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,5 @@
+<TestRunner>
+ <FriendlyName>xUnit.net {0}.{1} build {3}</FriendlyName>
+ <AssemblyPath>xunit.runner.tdnet.dll</AssemblyPath>
+ <TypeName>Xunit.Runner.TdNet.TdNetRunner</TypeName>
+</TestRunner>
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,77 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Xunit;
+using Newtonsoft.Json.Linq;
+
+using RestSharp.Deserializers;
+
+namespace RestSharp.Tests
+{
+ public class JsonTests
+ {
+ [Fact]
+ public void Can_Deserialize_With_Default_Root() {
+ var doc = CreateJson();
+
+ var d = new JsonDeserializer();
+ var p = d.Deserialize<Person>(doc);
+
+ Assert.Equal("John Sheehan", p.Name);
+ Assert.Equal(new DateTime(2009, 9, 25, 0, 6, 1), p.StartDate);
+ Assert.Equal(28, p.Age);
+ Assert.Equal(long.MaxValue, p.BigNumber);
+ Assert.Equal(99.9999m, p.Percent);
+ Assert.Equal(false, p.IsCool);
+
+ Assert.NotNull(p.Friends);
+ Assert.Equal(10, p.Friends.Count);
+
+ Assert.NotNull(p.BestFriend);
+ Assert.Equal("The Fonz", p.BestFriend.Name);
+ Assert.Equal(1952, p.BestFriend.Since);
+ }
+
+ [Fact]
+ public void Ignore_Protected_Property_That_Exists_In_Data() {
+ }
+
+ [Fact]
+ public void Ignore_ReadOnly_Property_That_Exists_In_Data() {
+ }
+
+ [Fact]
+ public void Can_Deserialize_Names_With_Underscores_On_Default_Root() {
+ }
+
+ private static string CreateJson() {
+ var doc = new JObject();
+ doc["Name"] = "John Sheehan";
+ doc["StartDate"] = new DateTime(2009, 9, 25, 0, 6, 1);
+ doc["Age"] = 28;
+ doc["Percent"] = 99.9999m;
+ doc["BigNumber"] = long.MaxValue;
+ doc["IsCool"] = false;
+ doc["Ignore"] = "dummy";
+ doc["ReadOnly"] = "dummy";
+
+ doc["BestFriend"] = new JObject(
+ new JProperty("Name", "The Fonz"),
+ new JProperty("Since", 1952)
+ );
+
+ var friendsArray = new JArray();
+ for (int i = 0; i < 10; i++) {
+ friendsArray.Add(new JObject(
+ new JProperty("Name", "Friend" + i),
+ new JProperty("Since", DateTime.Now.Year - i)
+ ));
+ }
+
+ doc["Friends"] = friendsArray;
+
+ return doc.ToString();
+ }
+ }
+}
@@ -0,0 +1,196 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Xunit;
+using System.Xml.Linq;
+using RestSharp.Deserializers;
+
+namespace RestSharp.Tests
+{
+ public class NamespacedXmlTests
+ {
+ [Fact]
+ public void Can_Deserialize_Elements_With_Namespace() {
+ var doc = CreateElementsXml();
+
+ var d = new XmlDeserializer();
+ d.Namespace = "http://restsharp.org";
+ var p = d.Deserialize<Person>(doc);
+
+ Assert.Equal("John Sheehan", p.Name);
+ Assert.Equal(new DateTime(2009, 9, 25, 0, 6, 1), p.StartDate);
+ Assert.Equal(28, p.Age);
+ Assert.Equal(long.MaxValue, p.BigNumber);
+ Assert.Equal(99.9999m, p.Percent);
+ Assert.Equal(false, p.IsCool);
+
+ Assert.NotNull(p.Friends);
+ Assert.Equal(10, p.Friends.Count);
+
+ Assert.NotNull(p.BestFriend);
+ Assert.Equal("The Fonz", p.BestFriend.Name);
+ Assert.Equal(1952, p.BestFriend.Since);
+ }
+
+ [Fact]
+ public void Can_Deserialize_Attributes_With_Namespace() {
+ var doc = CreateAttributesXml();
+
+ var d = new XmlDeserializer();
+ d.Namespace = "http://restsharp.org";
+ var p = d.Deserialize<Person>(doc);
+
+ Assert.Equal("John Sheehan", p.Name);
+ Assert.Equal(new DateTime(2009, 9, 25, 0, 6, 1), p.StartDate);
+ Assert.Equal(28, p.Age);
+ Assert.Equal(long.MaxValue, p.BigNumber);
+ Assert.Equal(99.9999m, p.Percent);
+ Assert.Equal(false, p.IsCool);
+
+ Assert.NotNull(p.BestFriend);
+ Assert.Equal("The Fonz", p.BestFriend.Name);
+ Assert.Equal(1952, p.BestFriend.Since);
+ }
+
+ [Fact]
+ public void Ignore_Protected_Property_That_Exists_In_Data() {
+ var doc = CreateElementsXml();
+
+ var d = new XmlDeserializer();
+ d.Namespace = "http://restsharp.org";
+ var p = d.Deserialize<Person>(doc);
+
+ Assert.Null(p.IgnoreProxy);
+ }
+
+ [Fact]
+ public void Ignore_ReadOnly_Property_That_Exists_In_Data() {
+ var doc = CreateElementsXml();
+
+ var d = new XmlDeserializer();
+ d.Namespace = "http://restsharp.org";
+ var p = d.Deserialize<Person>(doc);
+
+ Assert.Null(p.ReadOnlyProxy);
+ }
+
+ [Fact]
+ public void Can_Deserialize_Names_With_Underscores_With_Namespace() {
+ var doc = CreateUnderscoresXml();
+
+ var d = new XmlDeserializer();
+ d.Namespace = "http://restsharp.org";
+ var p = d.Deserialize<Person>(doc);
+
+ Assert.Equal("John Sheehan", p.Name);
+ Assert.Equal(new DateTime(2009, 9, 25, 0, 6, 1), p.StartDate);
+ Assert.Equal(28, p.Age);
+ Assert.Equal(long.MaxValue, p.BigNumber);
+ Assert.Equal(99.9999m, p.Percent);
+ Assert.Equal(false, p.IsCool);
+
+ Assert.NotNull(p.Friends);
+ Assert.Equal(10, p.Friends.Count);
+
+ Assert.NotNull(p.BestFriend);
+ Assert.Equal("The Fonz", p.BestFriend.Name);
+ Assert.Equal(1952, p.BestFriend.Since);
+
+ Assert.NotNull(p.Foes);
+ Assert.Equal(5, p.Foes.Count);
+ Assert.Equal("Yankees", p.Foes.Team);
+ }
+
+ private static string CreateUnderscoresXml() {
+ var doc = new XDocument();
+ var ns = XNamespace.Get("http://restsharp.org");
+ var root = new XElement(ns + "Person");
+ root.Add(new XElement(ns + "Name", "John Sheehan"));
+ root.Add(new XElement(ns + "Start_Date", new DateTime(2009, 9, 25, 0, 6, 1)));
+ root.Add(new XAttribute(ns + "Age", 28));
+ root.Add(new XElement(ns + "Percent", 99.9999m));
+ root.Add(new XElement(ns + "Big_Number", long.MaxValue));
+ root.Add(new XAttribute(ns + "Is_Cool", false));
+ root.Add(new XElement(ns + "Ignore", "dummy"));
+ root.Add(new XAttribute(ns + "Read_Only", "dummy"));
+
+ root.Add(new XElement(ns + "Best_Friend",
+ new XElement(ns + "Name", "The Fonz"),
+ new XAttribute(ns + "Since", 1952)
+ ));
+
+ var friends = new XElement(ns + "Friends");
+ for (int i = 0; i < 10; i++) {
+ friends.Add(new XElement(ns + "Friend",
+ new XElement(ns + "Name", "Friend" + i),
+ new XAttribute(ns + "Since", DateTime.Now.Year - i)
+ ));
+ }
+ root.Add(friends);
+
+ var foes = new XElement(ns + "Foes");
+ foes.Add(new XAttribute(ns + "Team", "Yankees"));
+ for (int i = 0; i < 5; i++) {
+ foes.Add(new XElement(ns + "Foe", new XElement(ns + "Nickname", "Foe" + i)));
+ }
+ root.Add(foes);
+
+ doc.Add(root);
+ return doc.ToString();
+ }
+
+ private static string CreateElementsXml() {
+ var doc = new XDocument();
+ var ns = XNamespace.Get("http://restsharp.org");
+ var root = new XElement(ns + "Person");
+ root.Add(new XElement(ns + "Name", "John Sheehan"));
+ root.Add(new XElement(ns + "StartDate", new DateTime(2009, 9, 25, 0, 6, 1)));
+ root.Add(new XElement(ns + "Age", 28));
+ root.Add(new XElement(ns + "Percent", 99.9999m));
+ root.Add(new XElement(ns + "BigNumber", long.MaxValue));
+ root.Add(new XElement(ns + "IsCool", false));
+ root.Add(new XElement(ns + "Ignore", "dummy"));
+ root.Add(new XElement(ns + "ReadOnly", "dummy"));
+
+ root.Add(new XElement(ns + "BestFriend",
+ new XElement(ns + "Name", "The Fonz"),
+ new XElement(ns + "Since", 1952)
+ ));
+
+ var friends = new XElement(ns + "Friends");
+ for (int i = 0; i < 10; i++) {
+ friends.Add(new XElement(ns + "Friend",
+ new XElement(ns + "Name", "Friend" + i),
+ new XElement(ns + "Since", DateTime.Now.Year - i)
+ ));
+ }
+ root.Add(friends);
+
+ doc.Add(root);
+ return doc.ToString();
+ }
+
+ private static string CreateAttributesXml() {
+ var doc = new XDocument();
+ var ns = XNamespace.Get("http://restsharp.org");
+ var root = new XElement(ns + "Person");
+ root.Add(new XAttribute(ns + "Name", "John Sheehan"));
+ root.Add(new XAttribute(ns + "StartDate", new DateTime(2009, 9, 25, 0, 6, 1)));
+ root.Add(new XAttribute(ns + "Age", 28));
+ root.Add(new XAttribute(ns + "Percent", 99.9999m));
+ root.Add(new XAttribute(ns + "BigNumber", long.MaxValue));
+ root.Add(new XAttribute(ns + "IsCool", false));
+ root.Add(new XAttribute(ns + "Ignore", "dummy"));
+ root.Add(new XAttribute(ns + "ReadOnly", "dummy"));
+
+ root.Add(new XElement(ns + "BestFriend",
+ new XAttribute(ns + "Name", "The Fonz"),
+ new XAttribute(ns + "Since", 1952)
+ ));
+
+ doc.Add(root);
+ return doc.ToString();
+ }
+ }
+}
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("RestSharp.Tests")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("RestSharp.Tests")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 2009")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("82c9d878-3d67-40fe-ac6b-6842605a04be")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.30729</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{1464E4AC-18BB-4F23-8A0B-68196F9E1871}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>RestSharp.Tests</RootNamespace>
+ <AssemblyName>RestSharp.Tests</AssemblyName>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="Newtonsoft.Json, Version=3.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\References\Newtonsoft.Json.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Xml.Linq">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Data.DataSetExtensions">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ <Reference Include="xunit, Version=1.5.0.1479, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\References\xunit.dll</HintPath>
+ </Reference>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="JsonTests.cs" />
+ <Compile Include="NamespacedXmlTests.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="SampleClasses.cs" />
+ <Compile Include="XmlTests.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\RestSharp\RestSharp.csproj">
+ <Project>{2ECECFBF-5F3E-40EE-A963-72336DC7ABE2}</Project>
+ <Name>RestSharp</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
Oops, something went wrong.

0 comments on commit c6fa63e

Please sign in to comment.