-Line endings
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Data.Linq;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.LinqToSql
|
||||
{
|
||||
[MetadataType(typeof(DepartmentMetadata))]
|
||||
public partial class Department
|
||||
{
|
||||
[JsonConverter(typeof(DepartmentConverter))]
|
||||
public class DepartmentMetadata
|
||||
{
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Data.Linq;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.LinqToSql
|
||||
{
|
||||
[MetadataType(typeof(DepartmentMetadata))]
|
||||
public partial class Department
|
||||
{
|
||||
[JsonConverter(typeof(DepartmentConverter))]
|
||||
public class DepartmentMetadata
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,38 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.LinqToSql
|
||||
{
|
||||
public class DepartmentConverter : JsonConverter
|
||||
{
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
Department department = (Department)value;
|
||||
|
||||
JObject o = new JObject();
|
||||
o["DepartmentId"] = new JValue(department.DepartmentId.ToString());
|
||||
o["Name"] = new JValue(new string(department.Name.Reverse().ToArray()));
|
||||
|
||||
o.WriteTo(writer);
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
JObject o = JObject.Load(reader);
|
||||
|
||||
Department department = new Department();
|
||||
department.DepartmentId = new Guid((string)o["DepartmentId"]);
|
||||
department.Name = new string(((string) o["Name"]).Reverse().ToArray());
|
||||
|
||||
return department;
|
||||
}
|
||||
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return (objectType == typeof (Department));
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.LinqToSql
|
||||
{
|
||||
public class DepartmentConverter : JsonConverter
|
||||
{
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
Department department = (Department)value;
|
||||
|
||||
JObject o = new JObject();
|
||||
o["DepartmentId"] = new JValue(department.DepartmentId.ToString());
|
||||
o["Name"] = new JValue(new string(department.Name.Reverse().ToArray()));
|
||||
|
||||
o.WriteTo(writer);
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
JObject o = JObject.Load(reader);
|
||||
|
||||
Department department = new Department();
|
||||
department.DepartmentId = new Guid((string)o["DepartmentId"]);
|
||||
department.Name = new string(((string) o["Name"]).Reverse().ToArray());
|
||||
|
||||
return department;
|
||||
}
|
||||
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return (objectType == typeof (Department));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.LinqToSql
|
||||
{
|
||||
public class GuidByteArrayConverter : JsonConverter
|
||||
{
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
Guid guid = (Guid) value;
|
||||
writer.WriteValue(Convert.ToBase64String(guid.ToByteArray()));
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
string encodedData = (string) reader.Value;
|
||||
byte[] data = Convert.FromBase64String(encodedData);
|
||||
return new Guid(data);
|
||||
}
|
||||
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return (objectType == typeof (Guid));
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.LinqToSql
|
||||
{
|
||||
public class GuidByteArrayConverter : JsonConverter
|
||||
{
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
Guid guid = (Guid) value;
|
||||
writer.WriteValue(Convert.ToBase64String(guid.ToByteArray()));
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
string encodedData = (string) reader.Value;
|
||||
byte[] data = Convert.FromBase64String(encodedData);
|
||||
return new Guid(data);
|
||||
}
|
||||
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return (objectType == typeof (Guid));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,35 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><Database EntityNamespace="Newtonsoft.Json.Tests.LinqToSql" ContextNamespace="Newtonsoft.Json.Tests.LinqToSql" Class="LinqToSqlClassesDataContext" xmlns="http://schemas.microsoft.com/linqtosql/dbml/2007">
|
||||
<Table Name="" Member="Persons">
|
||||
<Type Name="Person">
|
||||
<Column Name="FirstName" Type="System.String" CanBeNull="false" />
|
||||
<Column Name="LastName" Type="System.String" CanBeNull="false" />
|
||||
<Column Name="PersonId" Type="System.Guid" IsPrimaryKey="true" CanBeNull="false" />
|
||||
<Column Name="DepartmentId" Type="System.Guid" CanBeNull="false" />
|
||||
<Association Name="Person_PersonRole" Member="PersonRoles" ThisKey="PersonId" OtherKey="PersonId" Type="PersonRole" />
|
||||
<Association Name="Department_Person" Member="Department" ThisKey="DepartmentId" OtherKey="DepartmentId" Type="Department" IsForeignKey="true" />
|
||||
</Type>
|
||||
</Table>
|
||||
<Table Name="" Member="Roles">
|
||||
<Type Name="Role">
|
||||
<Column Name="Name" Type="System.String" CanBeNull="false" />
|
||||
<Column Name="RoleId" Type="System.Guid" IsPrimaryKey="true" CanBeNull="false" />
|
||||
<Association Name="Role_PersonRole" Member="PersonRoles" ThisKey="RoleId" OtherKey="RoleId" Type="PersonRole" />
|
||||
</Type>
|
||||
</Table>
|
||||
<Table Name="" Member="PersonRoles">
|
||||
<Type Name="PersonRole">
|
||||
<Column Name="PersonId" Type="System.Guid" CanBeNull="false" />
|
||||
<Column Name="RoleId" Type="System.Guid" CanBeNull="false" />
|
||||
<Column Name="PersonRoleId" Type="System.Guid" IsPrimaryKey="true" CanBeNull="false" />
|
||||
<Association Name="Person_PersonRole" Member="Person" ThisKey="PersonId" OtherKey="PersonId" Type="Person" IsForeignKey="true" />
|
||||
<Association Name="Role_PersonRole" Member="Role" ThisKey="RoleId" OtherKey="RoleId" Type="Role" IsForeignKey="true" />
|
||||
</Type>
|
||||
</Table>
|
||||
<Table Name="" Member="Departments">
|
||||
<Type Name="Department">
|
||||
<Column Name="DepartmentId" Type="System.Guid" IsPrimaryKey="true" CanBeNull="false" />
|
||||
<Column Name="Name" Type="System.String" CanBeNull="false" />
|
||||
<Association Name="Department_Person" Member="Persons" ThisKey="DepartmentId" OtherKey="DepartmentId" Type="Person" />
|
||||
</Type>
|
||||
</Table>
|
||||
<?xml version="1.0" encoding="utf-8"?><Database EntityNamespace="Newtonsoft.Json.Tests.LinqToSql" ContextNamespace="Newtonsoft.Json.Tests.LinqToSql" Class="LinqToSqlClassesDataContext" xmlns="http://schemas.microsoft.com/linqtosql/dbml/2007">
|
||||
<Table Name="" Member="Persons">
|
||||
<Type Name="Person">
|
||||
<Column Name="FirstName" Type="System.String" CanBeNull="false" />
|
||||
<Column Name="LastName" Type="System.String" CanBeNull="false" />
|
||||
<Column Name="PersonId" Type="System.Guid" IsPrimaryKey="true" CanBeNull="false" />
|
||||
<Column Name="DepartmentId" Type="System.Guid" CanBeNull="false" />
|
||||
<Association Name="Person_PersonRole" Member="PersonRoles" ThisKey="PersonId" OtherKey="PersonId" Type="PersonRole" />
|
||||
<Association Name="Department_Person" Member="Department" ThisKey="DepartmentId" OtherKey="DepartmentId" Type="Department" IsForeignKey="true" />
|
||||
</Type>
|
||||
</Table>
|
||||
<Table Name="" Member="Roles">
|
||||
<Type Name="Role">
|
||||
<Column Name="Name" Type="System.String" CanBeNull="false" />
|
||||
<Column Name="RoleId" Type="System.Guid" IsPrimaryKey="true" CanBeNull="false" />
|
||||
<Association Name="Role_PersonRole" Member="PersonRoles" ThisKey="RoleId" OtherKey="RoleId" Type="PersonRole" />
|
||||
</Type>
|
||||
</Table>
|
||||
<Table Name="" Member="PersonRoles">
|
||||
<Type Name="PersonRole">
|
||||
<Column Name="PersonId" Type="System.Guid" CanBeNull="false" />
|
||||
<Column Name="RoleId" Type="System.Guid" CanBeNull="false" />
|
||||
<Column Name="PersonRoleId" Type="System.Guid" IsPrimaryKey="true" CanBeNull="false" />
|
||||
<Association Name="Person_PersonRole" Member="Person" ThisKey="PersonId" OtherKey="PersonId" Type="Person" IsForeignKey="true" />
|
||||
<Association Name="Role_PersonRole" Member="Role" ThisKey="RoleId" OtherKey="RoleId" Type="Role" IsForeignKey="true" />
|
||||
</Type>
|
||||
</Table>
|
||||
<Table Name="" Member="Departments">
|
||||
<Type Name="Department">
|
||||
<Column Name="DepartmentId" Type="System.Guid" IsPrimaryKey="true" CanBeNull="false" />
|
||||
<Column Name="Name" Type="System.String" CanBeNull="false" />
|
||||
<Association Name="Department_Person" Member="Persons" ThisKey="DepartmentId" OtherKey="DepartmentId" Type="Person" />
|
||||
</Type>
|
||||
</Table>
|
||||
</Database>
|
||||
@@ -1,51 +1,51 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ordesignerObjectsDiagram dslVersion="1.0.0.0" absoluteBounds="0, 0, 11, 8.5" name="LinqToSqlClasses">
|
||||
<DataContextMoniker Name="/LinqToSqlClassesDataContext" />
|
||||
<nestedChildShapes>
|
||||
<classShape Id="be91ec15-4a64-4976-9358-2e01309ef584" absoluteBounds="0.875, 1.875, 2, 1.5785953776041666">
|
||||
<DataClassMoniker Name="/LinqToSqlClassesDataContext/Person" />
|
||||
<nestedChildShapes>
|
||||
<elementListCompartment Id="e16e186c-b29e-45ca-a2ab-93cb3de05143" absoluteBounds="0.8899999999999999, 2.335, 1.9700000000000002, 1.0185953776041665" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" />
|
||||
</nestedChildShapes>
|
||||
</classShape>
|
||||
<classShape Id="b1b861bb-382c-4c65-bdb1-7a3e2df873a2" absoluteBounds="3.625, 4.625, 2, 1.1939925130208333">
|
||||
<DataClassMoniker Name="/LinqToSqlClassesDataContext/Role" />
|
||||
<nestedChildShapes>
|
||||
<elementListCompartment Id="11d870c0-0ec3-4fba-bb69-43a96fa05670" absoluteBounds="3.6399999999999997, 5.085, 1.9700000000000002, 0.63399251302083326" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" />
|
||||
</nestedChildShapes>
|
||||
</classShape>
|
||||
<classShape Id="1eb138a4-9f12-4a20-b6b7-d1e23984b857" absoluteBounds="3.75, 2.25, 2, 1.3862939453125">
|
||||
<DataClassMoniker Name="/LinqToSqlClassesDataContext/PersonRole" />
|
||||
<nestedChildShapes>
|
||||
<elementListCompartment Id="6865be45-c748-47ff-be37-534064fc2e80" absoluteBounds="3.7649999999999997, 2.71, 1.9700000000000002, 0.8262939453125" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" />
|
||||
</nestedChildShapes>
|
||||
</classShape>
|
||||
<associationConnector edgePoints="[(2.875 : 2.85179768880208); (3.75 : 2.85179768880208)]" fixedFrom="NotFixed" fixedTo="NotFixed">
|
||||
<AssociationMoniker Name="/LinqToSqlClassesDataContext/Person/Person_PersonRole" />
|
||||
<nodes>
|
||||
<classShapeMoniker Id="be91ec15-4a64-4976-9358-2e01309ef584" />
|
||||
<classShapeMoniker Id="1eb138a4-9f12-4a20-b6b7-d1e23984b857" />
|
||||
</nodes>
|
||||
</associationConnector>
|
||||
<associationConnector edgePoints="[(4.6875 : 4.625); (4.6875 : 3.6362939453125)]" fixedFrom="NotFixed" fixedTo="NotFixed">
|
||||
<AssociationMoniker Name="/LinqToSqlClassesDataContext/Role/Role_PersonRole" />
|
||||
<nodes>
|
||||
<classShapeMoniker Id="b1b861bb-382c-4c65-bdb1-7a3e2df873a2" />
|
||||
<classShapeMoniker Id="1eb138a4-9f12-4a20-b6b7-d1e23984b857" />
|
||||
</nodes>
|
||||
</associationConnector>
|
||||
<classShape Id="b96fa86b-7f23-489f-8eb2-44ca2af1551b" absoluteBounds="0.875, 4.5, 2, 1.1939925130208327">
|
||||
<DataClassMoniker Name="/LinqToSqlClassesDataContext/Department" />
|
||||
<nestedChildShapes>
|
||||
<elementListCompartment Id="46cdd558-04c5-4c77-82ce-fe92cda427fe" absoluteBounds="0.89, 4.96, 1.9700000000000002, 0.63399251302083326" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" />
|
||||
</nestedChildShapes>
|
||||
</classShape>
|
||||
<associationConnector edgePoints="[(1.875 : 4.5); (1.875 : 3.45359537760417)]" fixedFrom="NotFixed" fixedTo="NotFixed">
|
||||
<AssociationMoniker Name="/LinqToSqlClassesDataContext/Department/Department_Person" />
|
||||
<nodes>
|
||||
<classShapeMoniker Id="b96fa86b-7f23-489f-8eb2-44ca2af1551b" />
|
||||
<classShapeMoniker Id="be91ec15-4a64-4976-9358-2e01309ef584" />
|
||||
</nodes>
|
||||
</associationConnector>
|
||||
</nestedChildShapes>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ordesignerObjectsDiagram dslVersion="1.0.0.0" absoluteBounds="0, 0, 11, 8.5" name="LinqToSqlClasses">
|
||||
<DataContextMoniker Name="/LinqToSqlClassesDataContext" />
|
||||
<nestedChildShapes>
|
||||
<classShape Id="be91ec15-4a64-4976-9358-2e01309ef584" absoluteBounds="0.875, 1.875, 2, 1.5785953776041666">
|
||||
<DataClassMoniker Name="/LinqToSqlClassesDataContext/Person" />
|
||||
<nestedChildShapes>
|
||||
<elementListCompartment Id="e16e186c-b29e-45ca-a2ab-93cb3de05143" absoluteBounds="0.8899999999999999, 2.335, 1.9700000000000002, 1.0185953776041665" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" />
|
||||
</nestedChildShapes>
|
||||
</classShape>
|
||||
<classShape Id="b1b861bb-382c-4c65-bdb1-7a3e2df873a2" absoluteBounds="3.625, 4.625, 2, 1.1939925130208333">
|
||||
<DataClassMoniker Name="/LinqToSqlClassesDataContext/Role" />
|
||||
<nestedChildShapes>
|
||||
<elementListCompartment Id="11d870c0-0ec3-4fba-bb69-43a96fa05670" absoluteBounds="3.6399999999999997, 5.085, 1.9700000000000002, 0.63399251302083326" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" />
|
||||
</nestedChildShapes>
|
||||
</classShape>
|
||||
<classShape Id="1eb138a4-9f12-4a20-b6b7-d1e23984b857" absoluteBounds="3.75, 2.25, 2, 1.3862939453125">
|
||||
<DataClassMoniker Name="/LinqToSqlClassesDataContext/PersonRole" />
|
||||
<nestedChildShapes>
|
||||
<elementListCompartment Id="6865be45-c748-47ff-be37-534064fc2e80" absoluteBounds="3.7649999999999997, 2.71, 1.9700000000000002, 0.8262939453125" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" />
|
||||
</nestedChildShapes>
|
||||
</classShape>
|
||||
<associationConnector edgePoints="[(2.875 : 2.85179768880208); (3.75 : 2.85179768880208)]" fixedFrom="NotFixed" fixedTo="NotFixed">
|
||||
<AssociationMoniker Name="/LinqToSqlClassesDataContext/Person/Person_PersonRole" />
|
||||
<nodes>
|
||||
<classShapeMoniker Id="be91ec15-4a64-4976-9358-2e01309ef584" />
|
||||
<classShapeMoniker Id="1eb138a4-9f12-4a20-b6b7-d1e23984b857" />
|
||||
</nodes>
|
||||
</associationConnector>
|
||||
<associationConnector edgePoints="[(4.6875 : 4.625); (4.6875 : 3.6362939453125)]" fixedFrom="NotFixed" fixedTo="NotFixed">
|
||||
<AssociationMoniker Name="/LinqToSqlClassesDataContext/Role/Role_PersonRole" />
|
||||
<nodes>
|
||||
<classShapeMoniker Id="b1b861bb-382c-4c65-bdb1-7a3e2df873a2" />
|
||||
<classShapeMoniker Id="1eb138a4-9f12-4a20-b6b7-d1e23984b857" />
|
||||
</nodes>
|
||||
</associationConnector>
|
||||
<classShape Id="b96fa86b-7f23-489f-8eb2-44ca2af1551b" absoluteBounds="0.875, 4.5, 2, 1.1939925130208327">
|
||||
<DataClassMoniker Name="/LinqToSqlClassesDataContext/Department" />
|
||||
<nestedChildShapes>
|
||||
<elementListCompartment Id="46cdd558-04c5-4c77-82ce-fe92cda427fe" absoluteBounds="0.89, 4.96, 1.9700000000000002, 0.63399251302083326" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" />
|
||||
</nestedChildShapes>
|
||||
</classShape>
|
||||
<associationConnector edgePoints="[(1.875 : 4.5); (1.875 : 3.45359537760417)]" fixedFrom="NotFixed" fixedTo="NotFixed">
|
||||
<AssociationMoniker Name="/LinqToSqlClassesDataContext/Department/Department_Person" />
|
||||
<nodes>
|
||||
<classShapeMoniker Id="b96fa86b-7f23-489f-8eb2-44ca2af1551b" />
|
||||
<classShapeMoniker Id="be91ec15-4a64-4976-9358-2e01309ef584" />
|
||||
</nodes>
|
||||
</associationConnector>
|
||||
</nestedChildShapes>
|
||||
</ordesignerObjectsDiagram>
|
||||
+726
-726
File diff suppressed because it is too large
Load Diff
@@ -1,110 +1,110 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Tests.LinqToSql;
|
||||
using NUnit.Framework;
|
||||
using System.Reflection;
|
||||
using System.ComponentModel;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using System.Data.Linq.Mapping;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.LinqToSql
|
||||
{
|
||||
public class LinqToSqlClassesSerializationTests : TestFixtureBase
|
||||
{
|
||||
[Test]
|
||||
public void Serialize()
|
||||
{
|
||||
Role role = new Role();
|
||||
role.Name = "Role1";
|
||||
role.RoleId = new Guid("67EA92B7-4BD3-4718-BD75-3C7EDF800B34");
|
||||
|
||||
Person person = new Person();
|
||||
person.FirstName = "FirstName!";
|
||||
person.LastName = "LastName!";
|
||||
person.PersonId = new Guid("7AA027AA-C995-4986-908D-999D8063599F");
|
||||
person.PersonRoles.Add(new PersonRole
|
||||
{
|
||||
PersonRoleId = new Guid("B012DD41-71DF-4839-B8D5-D1333FB886BC"),
|
||||
Role = role
|
||||
});
|
||||
|
||||
person.Department = new Department
|
||||
{
|
||||
DepartmentId = new Guid("08F68BF9-929B-4434-BC47-C9489D22112B"),
|
||||
Name = "Name!"
|
||||
};
|
||||
|
||||
string json = JsonConvert.SerializeObject(person, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
|
||||
|
||||
Assert.AreEqual(@"{
|
||||
""first_name"": ""FirstName!"",
|
||||
""LastName"": ""LastName!"",
|
||||
""PersonId"": ""7aa027aa-c995-4986-908d-999d8063599f"",
|
||||
""DepartmentId"": ""08f68bf9-929b-4434-bc47-c9489d22112b"",
|
||||
""PersonRoles"": [
|
||||
{
|
||||
""PersonId"": ""7aa027aa-c995-4986-908d-999d8063599f"",
|
||||
""RoleId"": ""67ea92b7-4bd3-4718-bd75-3c7edf800b34"",
|
||||
""PersonRoleId"": ""b012dd41-71df-4839-b8d5-d1333fb886bc"",
|
||||
""Role"": {
|
||||
""Name"": ""Role1"",
|
||||
""RoleId"": ""t5LqZ9NLGEe9dTx+34ALNA==""
|
||||
}
|
||||
}
|
||||
],
|
||||
""Department"": {
|
||||
""DepartmentId"": ""08f68bf9-929b-4434-bc47-c9489d22112b"",
|
||||
""Name"": ""!emaN""
|
||||
}
|
||||
}", json);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Deserialize()
|
||||
{
|
||||
string json = @"{
|
||||
""first_name"": ""FirstName!"",
|
||||
""LastName"": ""LastName!"",
|
||||
""PersonId"": ""7aa027aa-c995-4986-908d-999d8063599f"",
|
||||
""PersonRoles"": [
|
||||
{
|
||||
""PersonId"": ""7aa027aa-c995-4986-908d-999d8063599f"",
|
||||
""RoleId"": ""67ea92b7-4bd3-4718-bd75-3c7edf800b34"",
|
||||
""PersonRoleId"": ""b012dd41-71df-4839-b8d5-d1333fb886bc"",
|
||||
""Role"": {
|
||||
""Name"": ""Role1"",
|
||||
""RoleId"": ""t5LqZ9NLGEe9dTx+34ALNA==""
|
||||
}
|
||||
}
|
||||
],
|
||||
""Department"": {
|
||||
""DepartmentId"": ""08f68bf9-929b-4434-bc47-c9489d22112b"",
|
||||
""Name"": ""!emaN""
|
||||
}
|
||||
}";
|
||||
|
||||
Person person = JsonConvert.DeserializeObject<Person>(json);
|
||||
Assert.IsNotNull(person);
|
||||
|
||||
Assert.AreEqual(new Guid("7AA027AA-C995-4986-908D-999D8063599F"), person.PersonId);
|
||||
Assert.AreEqual("FirstName!", person.FirstName);
|
||||
Assert.AreEqual("LastName!", person.LastName);
|
||||
Assert.AreEqual(1, person.PersonRoles.Count);
|
||||
Assert.AreEqual(person.PersonId, person.PersonRoles[0].PersonId);
|
||||
Assert.AreEqual(new Guid("67EA92B7-4BD3-4718-BD75-3C7EDF800B34"), person.PersonRoles[0].RoleId);
|
||||
Assert.IsNotNull(person.PersonRoles[0].Role);
|
||||
Assert.AreEqual(1, person.PersonRoles[0].Role.PersonRoles.Count);
|
||||
|
||||
Assert.AreEqual("Name!", person.Department.Name);
|
||||
|
||||
TableAttribute tableAttribute = JsonTypeReflector.GetAttribute<TableAttribute>(typeof(Person));
|
||||
Assert.AreEqual("", tableAttribute.Name);
|
||||
|
||||
ColumnAttribute columnAttribute = JsonTypeReflector.GetAttribute<ColumnAttribute>(typeof(Person).GetProperty("FirstName"));
|
||||
Assert.AreEqual("_FirstName", columnAttribute.Storage);
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Tests.LinqToSql;
|
||||
using NUnit.Framework;
|
||||
using System.Reflection;
|
||||
using System.ComponentModel;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using System.Data.Linq.Mapping;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.LinqToSql
|
||||
{
|
||||
public class LinqToSqlClassesSerializationTests : TestFixtureBase
|
||||
{
|
||||
[Test]
|
||||
public void Serialize()
|
||||
{
|
||||
Role role = new Role();
|
||||
role.Name = "Role1";
|
||||
role.RoleId = new Guid("67EA92B7-4BD3-4718-BD75-3C7EDF800B34");
|
||||
|
||||
Person person = new Person();
|
||||
person.FirstName = "FirstName!";
|
||||
person.LastName = "LastName!";
|
||||
person.PersonId = new Guid("7AA027AA-C995-4986-908D-999D8063599F");
|
||||
person.PersonRoles.Add(new PersonRole
|
||||
{
|
||||
PersonRoleId = new Guid("B012DD41-71DF-4839-B8D5-D1333FB886BC"),
|
||||
Role = role
|
||||
});
|
||||
|
||||
person.Department = new Department
|
||||
{
|
||||
DepartmentId = new Guid("08F68BF9-929B-4434-BC47-C9489D22112B"),
|
||||
Name = "Name!"
|
||||
};
|
||||
|
||||
string json = JsonConvert.SerializeObject(person, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
|
||||
|
||||
Assert.AreEqual(@"{
|
||||
""first_name"": ""FirstName!"",
|
||||
""LastName"": ""LastName!"",
|
||||
""PersonId"": ""7aa027aa-c995-4986-908d-999d8063599f"",
|
||||
""DepartmentId"": ""08f68bf9-929b-4434-bc47-c9489d22112b"",
|
||||
""PersonRoles"": [
|
||||
{
|
||||
""PersonId"": ""7aa027aa-c995-4986-908d-999d8063599f"",
|
||||
""RoleId"": ""67ea92b7-4bd3-4718-bd75-3c7edf800b34"",
|
||||
""PersonRoleId"": ""b012dd41-71df-4839-b8d5-d1333fb886bc"",
|
||||
""Role"": {
|
||||
""Name"": ""Role1"",
|
||||
""RoleId"": ""t5LqZ9NLGEe9dTx+34ALNA==""
|
||||
}
|
||||
}
|
||||
],
|
||||
""Department"": {
|
||||
""DepartmentId"": ""08f68bf9-929b-4434-bc47-c9489d22112b"",
|
||||
""Name"": ""!emaN""
|
||||
}
|
||||
}", json);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Deserialize()
|
||||
{
|
||||
string json = @"{
|
||||
""first_name"": ""FirstName!"",
|
||||
""LastName"": ""LastName!"",
|
||||
""PersonId"": ""7aa027aa-c995-4986-908d-999d8063599f"",
|
||||
""PersonRoles"": [
|
||||
{
|
||||
""PersonId"": ""7aa027aa-c995-4986-908d-999d8063599f"",
|
||||
""RoleId"": ""67ea92b7-4bd3-4718-bd75-3c7edf800b34"",
|
||||
""PersonRoleId"": ""b012dd41-71df-4839-b8d5-d1333fb886bc"",
|
||||
""Role"": {
|
||||
""Name"": ""Role1"",
|
||||
""RoleId"": ""t5LqZ9NLGEe9dTx+34ALNA==""
|
||||
}
|
||||
}
|
||||
],
|
||||
""Department"": {
|
||||
""DepartmentId"": ""08f68bf9-929b-4434-bc47-c9489d22112b"",
|
||||
""Name"": ""!emaN""
|
||||
}
|
||||
}";
|
||||
|
||||
Person person = JsonConvert.DeserializeObject<Person>(json);
|
||||
Assert.IsNotNull(person);
|
||||
|
||||
Assert.AreEqual(new Guid("7AA027AA-C995-4986-908D-999D8063599F"), person.PersonId);
|
||||
Assert.AreEqual("FirstName!", person.FirstName);
|
||||
Assert.AreEqual("LastName!", person.LastName);
|
||||
Assert.AreEqual(1, person.PersonRoles.Count);
|
||||
Assert.AreEqual(person.PersonId, person.PersonRoles[0].PersonId);
|
||||
Assert.AreEqual(new Guid("67EA92B7-4BD3-4718-BD75-3C7EDF800B34"), person.PersonRoles[0].RoleId);
|
||||
Assert.IsNotNull(person.PersonRoles[0].Role);
|
||||
Assert.AreEqual(1, person.PersonRoles[0].Role.PersonRoles.Count);
|
||||
|
||||
Assert.AreEqual("Name!", person.Department.Name);
|
||||
|
||||
TableAttribute tableAttribute = JsonTypeReflector.GetAttribute<TableAttribute>(typeof(Person));
|
||||
Assert.AreEqual("", tableAttribute.Name);
|
||||
|
||||
ColumnAttribute columnAttribute = JsonTypeReflector.GetAttribute<ColumnAttribute>(typeof(Person).GetProperty("FirstName"));
|
||||
Assert.AreEqual("_FirstName", columnAttribute.Storage);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.LinqToSql
|
||||
{
|
||||
[MetadataType(typeof(PersonMetadata))]
|
||||
public partial class Person
|
||||
{
|
||||
public class PersonMetadata
|
||||
{
|
||||
[JsonProperty("first_name")]
|
||||
public string FirstName { get; set; }
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.LinqToSql
|
||||
{
|
||||
[MetadataType(typeof(PersonMetadata))]
|
||||
public partial class Person
|
||||
{
|
||||
public class PersonMetadata
|
||||
{
|
||||
[JsonProperty("first_name")]
|
||||
public string FirstName { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Data.Linq;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.LinqToSql
|
||||
{
|
||||
[MetadataType(typeof(RoleMetadata))]
|
||||
public partial class Role
|
||||
{
|
||||
public class RoleMetadata
|
||||
{
|
||||
[JsonConverter(typeof(GuidByteArrayConverter))]
|
||||
public Guid RoleId { get; set; }
|
||||
[JsonIgnore]
|
||||
public EntitySet<PersonRole> PersonRoles { get; set; }
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Data.Linq;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.LinqToSql
|
||||
{
|
||||
[MetadataType(typeof(RoleMetadata))]
|
||||
public partial class Role
|
||||
{
|
||||
public class RoleMetadata
|
||||
{
|
||||
[JsonConverter(typeof(GuidByteArrayConverter))]
|
||||
public Guid RoleId { get; set; }
|
||||
[JsonIgnore]
|
||||
public EntitySet<PersonRole> PersonRoles { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user