Skip to content
This repository was archived by the owner on Apr 3, 2020. It is now read-only.

Commit efeee9c

Browse files
committed
Added tests for new deserialize implementation.
1 parent cf3b5fa commit efeee9c

File tree

4 files changed

+69
-3
lines changed

4 files changed

+69
-3
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System;
2+
using FluentAssertions;
3+
using Xunit;
4+
5+
namespace RestSharp.Serializers.Newtonsoft.Json.Tests
6+
{
7+
public class NewtonsoftJsonSerializerTests
8+
{
9+
#region Fields & Properties
10+
11+
private Person PersonObject => new Person()
12+
{
13+
Name = "John Smith",
14+
FavoriteNumber = 34,
15+
FavoriteColor = ConsoleColor.Red,
16+
HasChildren = true,
17+
NetWorth = 231453.56,
18+
DateOfBirth = new DateTime(1956, 8, 12)
19+
};
20+
21+
private string PersonString =>
22+
"{\"Name\":\"John Smith\",\"FavoriteNumber\":34,\"FavoriteColor\":12,\"HasChildren\":true,\"NetWorth\":231453.56,\"DateOfBirth\":\"1956-08-12T00:00:00\"}";
23+
24+
#endregion
25+
26+
[Fact]
27+
public void Serialize()
28+
{
29+
var serializer = NewtonsoftJsonSerializer.Default;
30+
var result = serializer.Serialize(PersonObject);
31+
32+
result.ShouldBeEquivalentTo(PersonString);
33+
}
34+
35+
[Fact]
36+
public void Deserialize()
37+
{
38+
var serializer = NewtonsoftJsonSerializer.Default;
39+
var restResponse = new RestResponse() {Content = PersonString};
40+
var result = serializer.Deserialize<Person>(restResponse);
41+
42+
result.ShouldBeEquivalentTo(PersonObject);
43+
}
44+
45+
public class Person
46+
{
47+
public string Name { get; set; }
48+
public int FavoriteNumber { get; set; }
49+
public ConsoleColor FavoriteColor { get; set; }
50+
public bool HasChildren { get; set; }
51+
public double NetWorth { get; set; }
52+
public DateTime DateOfBirth { get; set; }
53+
}
54+
}
55+
}

RestSharp.Serializers.Newtonsoft.Json.Tests/RestRequestTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Net.Http;
21
using FluentAssertions;
32
using Xunit;
43

RestSharp.Serializers.Newtonsoft.Json.Tests/RestSharp.Serializers.Newtonsoft.Json.Tests.csproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66

77
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Package Nuget|AnyCPU'" />
88

9+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
10+
<LangVersion>latest</LangVersion>
11+
</PropertyGroup>
12+
13+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
14+
<LangVersion>latest</LangVersion>
15+
</PropertyGroup>
16+
917
<ItemGroup>
1018
<PackageReference Include="FluentAssertions" Version="4.19.2" />
1119
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
@@ -19,4 +27,8 @@
1927
<ProjectReference Include="..\RestSharp.Serializers.Newtonsoft.Json\RestSharp.Serializers.Newtonsoft.Json.csproj" />
2028
</ItemGroup>
2129

30+
<ItemGroup>
31+
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
32+
</ItemGroup>
33+
2234
</Project>

RestSharp.Serializers.Newtonsoft.Json/RestSharp.Serializers.Newtonsoft.Json.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
<PackageId>RestSharp.Newtonsoft.Json</PackageId>
55
<Title>RestSharp.Serializers.Newtonsoft.Json</Title>
66
<TargetFrameworks>netstandard2.0;net452</TargetFrameworks>
7-
<PackageVersion>1.4.0</PackageVersion>
7+
<PackageVersion>1.5.0</PackageVersion>
88
<Authors>Adam Fisher</Authors>
99
<Description>Restores Newtonsoft.JSON as the default serializer for RestSharp.</Description>
1010
<PackageLicenseUrl>https://github.com/adamfisher/RestSharp.Serializers.Newtonsoft.Json/blob/master/LICENSE</PackageLicenseUrl>
1111
<PackageProjectUrl>https://github.com/adamfisher/RestSharp.Serializers.Newtonsoft.Json</PackageProjectUrl>
1212
<PackageIconUrl>https://pbs.twimg.com/profile_images/525503893/restsharp_400x400.png</PackageIconUrl>
1313
<Copyright>Copyright 2017</Copyright>
1414
<PackageTags>REST HTTP API JSON XML NEWTONSOFT RESTSHARP</PackageTags>
15-
<Version>1.3.0</Version>
15+
<Version>1.5.0</Version>
1616
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
1717
<AssemblyVersion>1.0.0.0</AssemblyVersion>
1818
</PropertyGroup>

0 commit comments

Comments
 (0)