-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from svpetry/patch-1
Fixed wrong index comparison.
- Loading branch information
Showing
2 changed files
with
84 additions
and
2 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
...odaTime.Serialization.Utf8Json/DS.NodaTime.Serialization.Utf8Json.Tests/NodaPeriodTest.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,82 @@ | ||
using DS.NodaTime.Serialization.Utf8Json; | ||
using Utf8Json; | ||
using Utf8Json.Resolvers; | ||
using Xunit; | ||
|
||
namespace NodaTime.Serialization.Utf8Json.Tests | ||
{ | ||
public class NodaPeriodTest | ||
{ | ||
private static readonly IJsonFormatterResolver Resolver = CompositeResolver.Create(new IJsonFormatter[] | ||
{ | ||
NodaFormatters.NormalizingIsoPeriodFormatter | ||
}, new[] { StandardResolver.Default }); | ||
|
||
[Fact] | ||
public void Days_InObject() | ||
{ | ||
var testObj = new PeriodTestObj | ||
{ | ||
Str = "abcdefghijklmnopqrstuvwxyz", | ||
Period = Period.FromDays(3) | ||
}; | ||
var json = JsonSerializer.ToJsonString(testObj, Resolver); | ||
|
||
var deserializedObj = JsonSerializer.Deserialize<PeriodTestObj>(json, Resolver); | ||
|
||
Assert.Equal(testObj.Period, deserializedObj.Period); | ||
} | ||
|
||
[Fact] | ||
public void Months_InObject() | ||
{ | ||
var testObj = new PeriodTestObj | ||
{ | ||
Str = "abcdefghijklmnopqrstuvwxyz", | ||
Period = Period.FromMonths(6) | ||
}; | ||
var json = JsonSerializer.ToJsonString(testObj, Resolver); | ||
|
||
var deserializedObj = JsonSerializer.Deserialize<PeriodTestObj>(json, Resolver); | ||
|
||
Assert.Equal(testObj.Period, deserializedObj.Period); | ||
} | ||
|
||
[Fact] | ||
public void Years_InObject() | ||
{ | ||
var testObj = new PeriodTestObj | ||
{ | ||
Str = "abcdefghijklmnopqrstuvwxyz", | ||
Period = Period.FromYears(10) | ||
}; | ||
var json = JsonSerializer.ToJsonString(testObj, Resolver); | ||
|
||
var deserializedObj = JsonSerializer.Deserialize<PeriodTestObj>(json, Resolver); | ||
|
||
Assert.Equal(testObj.Period, deserializedObj.Period); | ||
} | ||
|
||
[Fact] | ||
public void Hours_InObject() | ||
{ | ||
var testObj = new PeriodTestObj | ||
{ | ||
Str = "abcdefghijklmnopqrstuvwxyz", | ||
Period = Period.FromHours(8) | ||
}; | ||
var json = JsonSerializer.ToJsonString(testObj, Resolver); | ||
|
||
var deserializedObj = JsonSerializer.Deserialize<PeriodTestObj>(json, Resolver); | ||
|
||
Assert.Equal(testObj.Period, deserializedObj.Period); | ||
} | ||
} | ||
|
||
public class PeriodTestObj | ||
{ | ||
public string Str { get; set; } | ||
|
||
public Period Period { get; set; } | ||
} | ||
} |
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