This repository has been archived by the owner on Apr 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for new deserialize implementation.
- Loading branch information
1 parent
cf3b5fa
commit efeee9c
Showing
4 changed files
with
69 additions
and
3 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
RestSharp.Serializers.Newtonsoft.Json.Tests/NewtonsoftJsonSerializerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} | ||
} |
1 change: 0 additions & 1 deletion
1
RestSharp.Serializers.Newtonsoft.Json.Tests/RestRequestTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
using System.Net.Http; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters