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

Commit

Permalink
Added tests for new deserialize implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
adamfisher committed Jun 17, 2018
1 parent cf3b5fa commit efeee9c
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using FluentAssertions;
using Xunit;

namespace RestSharp.Serializers.Newtonsoft.Json.Tests
{
public class NewtonsoftJsonSerializerTests
{
#region Fields & Properties

private Person PersonObject => new Person()
{
Name = "John Smith",
FavoriteNumber = 34,
FavoriteColor = ConsoleColor.Red,
HasChildren = true,
NetWorth = 231453.56,
DateOfBirth = new DateTime(1956, 8, 12)
};

private string PersonString =>
"{\"Name\":\"John Smith\",\"FavoriteNumber\":34,\"FavoriteColor\":12,\"HasChildren\":true,\"NetWorth\":231453.56,\"DateOfBirth\":\"1956-08-12T00:00:00\"}";

#endregion

[Fact]
public void Serialize()
{
var serializer = NewtonsoftJsonSerializer.Default;
var result = serializer.Serialize(PersonObject);

result.ShouldBeEquivalentTo(PersonString);
}

[Fact]
public void Deserialize()
{
var serializer = NewtonsoftJsonSerializer.Default;
var restResponse = new RestResponse() {Content = PersonString};
var result = serializer.Deserialize<Person>(restResponse);

result.ShouldBeEquivalentTo(PersonObject);
}

public class Person
{
public string Name { get; set; }
public int FavoriteNumber { get; set; }
public ConsoleColor FavoriteColor { get; set; }
public bool HasChildren { get; set; }
public double NetWorth { get; set; }
public DateTime DateOfBirth { get; set; }
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Net.Http;
using FluentAssertions;
using Xunit;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@

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

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<LangVersion>latest</LangVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="4.19.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
Expand All @@ -19,4 +27,8 @@
<ProjectReference Include="..\RestSharp.Serializers.Newtonsoft.Json\RestSharp.Serializers.Newtonsoft.Json.csproj" />
</ItemGroup>

<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
<PackageId>RestSharp.Newtonsoft.Json</PackageId>
<Title>RestSharp.Serializers.Newtonsoft.Json</Title>
<TargetFrameworks>netstandard2.0;net452</TargetFrameworks>
<PackageVersion>1.4.0</PackageVersion>
<PackageVersion>1.5.0</PackageVersion>
<Authors>Adam Fisher</Authors>
<Description>Restores Newtonsoft.JSON as the default serializer for RestSharp.</Description>
<PackageLicenseUrl>https://github.com/adamfisher/RestSharp.Serializers.Newtonsoft.Json/blob/master/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/adamfisher/RestSharp.Serializers.Newtonsoft.Json</PackageProjectUrl>
<PackageIconUrl>https://pbs.twimg.com/profile_images/525503893/restsharp_400x400.png</PackageIconUrl>
<Copyright>Copyright 2017</Copyright>
<PackageTags>REST HTTP API JSON XML NEWTONSOFT RESTSHARP</PackageTags>
<Version>1.3.0</Version>
<Version>1.5.0</Version>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
</PropertyGroup>
Expand Down

0 comments on commit efeee9c

Please sign in to comment.