Skip to content

Commit

Permalink
(GH-168) Fix issue when parsing a single device
Browse files Browse the repository at this point in the history
Also, more unit tests
  • Loading branch information
Jericho committed Feb 4, 2022
1 parent 5971fc6 commit da40bd4
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 7 deletions.
61 changes: 61 additions & 0 deletions Source/ZoomNet.UnitTests/Models/DashboardParticipant.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using Newtonsoft.Json;
using Shouldly;
using Xunit;
using ZoomNet.Models;

namespace StrongGrid.UnitTests.Resources
{
public class DashboardParticipantTests
{
#region FIELDS

internal const string SINGLE_DASHBOARDPARTICIPANT_JSON = @"{
'id': 'd52f19c548b88490b5d16fcbd38',
'user_id': '32dsfsd4g5gd',
'user_name': 'dojo',
'device': 'Unknown',
'ip_address': '127.0.0.1',
'location': 'New York',
'network_type': 'Wired',
'microphone': 'Plantronics BT600',
'camera': 'FaceTime HD Camera',
'speaker': 'Plantronics BT600',
'data_center': 'SC',
'full_data_center': 'United States;United States (US03_SC CRC)',
'connection_type': 'P2P',
'join_time': '2019-09-07T13:15:02.837Z',
'leave_time': '2019-09-07T13:15:09.837Z',
'share_application': false,
'share_desktop': true,
'share_whiteboard': true,
'recording': false,
'status': 'in_waiting_room',
'pc_name': 'dojo\'s pc',
'domain': 'Dojo-workspace',
'mac_addr': ' 00:0a:95:9d:68:16',
'harddisk_id': 'sed proident in',
'version': '4.4.55383.0716',
'leave_reason': 'Dojo left the meeting.<br>Reason: Host ended the meeting.',
'sip_uri': 'sip:[email protected]:11029',
'from_sip_uri': 'sip:[email protected]:11029',
'role': 'panelist'
}";

#endregion

[Fact]
public void Parse_json()
{
// Arrange

// Act
var result = JsonConvert.DeserializeObject<DashboardParticipant>(SINGLE_DASHBOARDPARTICIPANT_JSON);

// Assert
result.ShouldNotBeNull();
result.Devices.ShouldNotBeNull();
result.Devices.Length.ShouldBe(1);
result.Devices[0].ShouldBe(ParticipantDevice.Unknown);
}
}
}
15 changes: 11 additions & 4 deletions Source/ZoomNet.UnitTests/Utilities/ParticipantDeviceConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,18 @@ public void Write_multiple()
result.ShouldBe("\"Unknown + Phone\"");
}

[Fact]
public void Read_single()
[Theory]
[InlineDataAttribute("", ParticipantDevice.Unknown)]
[InlineDataAttribute("Unknown", ParticipantDevice.Unknown)]
[InlineDataAttribute("Android", ParticipantDevice.Android)]
[InlineDataAttribute("Phone", ParticipantDevice.Phone)]
[InlineDataAttribute("iOs", ParticipantDevice.IOS)]
[InlineDataAttribute("H.323/SIP", ParticipantDevice.Sip)]
[InlineDataAttribute("Windows", ParticipantDevice.Windows)]
public void Read_single(string value, ParticipantDevice expectedValue)
{
// Arrange
var json = "'Phone'";
var json = $"'{value}'";

var textReader = new StringReader(json);
var jsonReader = new JsonTextReader(textReader);
Expand All @@ -106,7 +113,7 @@ public void Read_single()

var resultAsArray = (ParticipantDevice[])result;
resultAsArray.Length.ShouldBe(1);
resultAsArray[0].ShouldBe(ParticipantDevice.Phone);
resultAsArray[0].ShouldBe(expectedValue);
}

[Fact]
Expand Down
6 changes: 4 additions & 2 deletions Source/ZoomNet/Models/DashboardParticipant.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Newtonsoft.Json;
using System;
using ZoomNet.Utilities;

namespace ZoomNet.Models
{
Expand Down Expand Up @@ -38,12 +39,13 @@ public class DashboardParticipant
public string UserName { get; set; }

/// <summary>
/// Gets or sets the type of device using which the participant joined the meeting.
/// Gets or sets the device(s) used by the participant to join the meeting.
/// </summary>
/// <value>
/// The type of device using which the participant joined the meeting.
/// The type of device used by the participant to join the meeting.
/// </value>
[JsonProperty(PropertyName = "device")]
[JsonConverter(typeof(ParticipantDeviceConverter))]
public ParticipantDevice[] Devices { get; set; }

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Source/ZoomNet/Utilities/ParticipantDeviceConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
{
var stringValue = (string)reader.Value;
var items = stringValue
.Split(new[] { "+" }, StringSplitOptions.RemoveEmptyEntries)
.Split(new[] { '+' })
.Select(item => Convert(item))
.ToArray();

Expand Down

0 comments on commit da40bd4

Please sign in to comment.