-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
282 additions
and
94 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using Shouldly; | ||
using System.Text.Json; | ||
using Xunit; | ||
using ZoomNet.Json; | ||
using ZoomNet.Models; | ||
|
||
namespace ZoomNet.UnitTests.Models | ||
{ | ||
public class DailyUsageReportTests | ||
{ | ||
#region FIELDS | ||
|
||
internal const string DAILY_USAGE_REPORT_JSON = @"{ | ||
""dates"": [ | ||
{ | ||
""date"": ""2022-03-01"", | ||
""meeting_minutes"": 34, | ||
""meetings"": 2, | ||
""new_users"": 3, | ||
""participants"": 4 | ||
} | ||
], | ||
""month"": 3, | ||
""year"": 2022 | ||
}"; | ||
|
||
#endregion | ||
|
||
[Fact] | ||
public void Parse_json() | ||
{ | ||
// Arrange | ||
|
||
// Act | ||
var result = JsonSerializer.Deserialize<DailyUsageReport>(DAILY_USAGE_REPORT_JSON, JsonFormatter.SerializerOptions); | ||
|
||
// Assert | ||
result.ShouldNotBeNull(); | ||
result.Month.ShouldBe(3); | ||
result.Year.ShouldBe(2022); | ||
result.DailyUsageSummaries.ShouldNotBeEmpty(); | ||
result.DailyUsageSummaries.Length.ShouldBe(1); | ||
result.DailyUsageSummaries[0].Date.Year.ShouldBe(2022); | ||
result.DailyUsageSummaries[0].Date.Month.ShouldBe(3); | ||
result.DailyUsageSummaries[0].Date.Day.ShouldBe(1); | ||
result.DailyUsageSummaries[0].MeetingMinutes.ShouldBe(34); | ||
result.DailyUsageSummaries[0].Meetings.ShouldBe(2); | ||
result.DailyUsageSummaries[0].NewUsers.ShouldBe(3); | ||
result.DailyUsageSummaries[0].Participants.ShouldBe(4); | ||
|
||
} | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using System.Text.Json; | ||
|
||
namespace ZoomNet.Json | ||
{ | ||
/// <summary> | ||
/// Converts a DateOnly (which is represented by 3 integer values: year, month and day) to or from JSON. | ||
/// </summary> | ||
/// <seealso cref="ZoomNetJsonConverter{T}"/> | ||
internal class DateOnlyConverter : ZoomNetJsonConverter<(int Year, int Month, int Day)> | ||
{ | ||
public override (int Year, int Month, int Day) Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
switch (reader.TokenType) | ||
{ | ||
case JsonTokenType.None: | ||
case JsonTokenType.Null: | ||
case JsonTokenType.String when string.IsNullOrEmpty(reader.GetString()): | ||
throw new JsonException("Unable to convert a null value to DateOnly"); | ||
|
||
case JsonTokenType.String: | ||
var rawValue = reader.GetString(); | ||
var parts = rawValue.Split('-'); | ||
if (parts.Length != 3) throw new JsonException($"Unable to convert {rawValue} to DateOnly"); | ||
return (int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2])); | ||
|
||
default: | ||
throw new JsonException($"Unable to convert {reader.TokenType.ToEnumString()} to DateOnly"); | ||
} | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, (int Year, int Month, int Day) value, JsonSerializerOptions options) | ||
{ | ||
writer.WriteStringValue($"{value.Year:D4}-{value.Month:D2}-{value.Day:D2}"); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace ZoomNet.Models | ||
{ | ||
/// <summary> | ||
/// Daily Usage Report. | ||
/// </summary> | ||
public class DailyUsageReport | ||
{ | ||
/// <summary>Gets or sets the daily usage summaries.</summary> | ||
[JsonPropertyName("dates")] | ||
public DailyUsageSummary[] DailyUsageSummaries { get; set; } | ||
|
||
/// <summary>Gets or sets the month.</summary> | ||
[JsonPropertyName("month")] | ||
public int Month { get; set; } | ||
|
||
/// <summary>Gets or sets the year.</summary> | ||
[JsonPropertyName("year")] | ||
public int Year { get; set; } | ||
} | ||
} |
Oops, something went wrong.