Skip to content

Commit c15e9bb

Browse files
Merge pull request #30 from martincostello/Fix-Schema
Fix schema
2 parents dab376e + 6640751 commit c15e9bb

File tree

3 files changed

+54
-6
lines changed

3 files changed

+54
-6
lines changed

src/MartinCostello.BrowserStack.Automate/BrowserStackAutomateClient.cs

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,11 @@ public virtual async Task<ICollection<Build>> GetBuildsAsync(
329329
using (var response = await Client.SendAsync(request, cancellationToken).ConfigureAwait(false))
330330
{
331331
await EnsureSuccessAsync(response).ConfigureAwait(false);
332-
return await DeserializeAsync<List<Build>>(response).ConfigureAwait(false);
332+
var builds = await DeserializeAsync<List<AutomationBuild>>(response).ConfigureAwait(false);
333+
334+
return builds
335+
.Select((p) => p.Build)
336+
.ToList();
333337
}
334338
}
335339
}
@@ -403,7 +407,9 @@ public virtual async Task<SessionDetail> GetSessionAsync(string sessionId, Cance
403407
using (var response = await Client.SendAsync(request, cancellationToken).ConfigureAwait(false))
404408
{
405409
await EnsureSuccessAsync(response).ConfigureAwait(false);
406-
return await DeserializeAsync<SessionDetail>(response).ConfigureAwait(false);
410+
var result = await DeserializeAsync<AutomationSessionDetail>(response).ConfigureAwait(false);
411+
412+
return result?.SessionDetail;
407413
}
408414
}
409415
}
@@ -523,7 +529,11 @@ public virtual async Task<ICollection<Session>> GetSessionsAsync(
523529
using (var response = await Client.SendAsync(request, cancellationToken).ConfigureAwait(false))
524530
{
525531
await EnsureSuccessAsync(response).ConfigureAwait(false);
526-
return await DeserializeAsync<List<Session>>(response).ConfigureAwait(false);
532+
var sessions = await DeserializeAsync<List<AutomationSession>>(response).ConfigureAwait(false);
533+
534+
return sessions
535+
.Select((p) => p.Session)
536+
.ToList();
527537
}
528538
}
529539
}
@@ -708,7 +718,9 @@ public virtual async Task<Session> SetSessionStatusAsync(
708718
using (var response = await Client.SendAsync(request, cancellationToken).ConfigureAwait(false))
709719
{
710720
await EnsureSuccessAsync(response).ConfigureAwait(false);
711-
return await DeserializeAsync<Session>(response).ConfigureAwait(false);
721+
var session = await DeserializeAsync<AutomationSession>(response).ConfigureAwait(false);
722+
723+
return session?.Session;
712724
}
713725
}
714726
}
@@ -942,5 +954,41 @@ private async Task<T> SetNameAsync<T>(
942954
}
943955
}
944956
}
957+
958+
/// <summary>
959+
/// A class representing a BrowserStack Automate build. This class cannot be inherited.
960+
/// </summary>
961+
private sealed class AutomationBuild
962+
{
963+
/// <summary>
964+
/// Gets or sets the build.
965+
/// </summary>
966+
[JsonProperty("automation_build")]
967+
public Build Build { get; set; }
968+
}
969+
970+
/// <summary>
971+
/// A class representing a BrowserStack Automate session. This class cannot be inherited.
972+
/// </summary>
973+
private sealed class AutomationSession
974+
{
975+
/// <summary>
976+
/// Gets or sets the session.
977+
/// </summary>
978+
[JsonProperty("automation_session")]
979+
public Session Session { get; set; }
980+
}
981+
982+
/// <summary>
983+
/// A class representing a BrowserStack Automate session's details. This class cannot be inherited.
984+
/// </summary>
985+
private sealed class AutomationSessionDetail
986+
{
987+
/// <summary>
988+
/// Gets or sets the session.
989+
/// </summary>
990+
[JsonProperty("automation_session")]
991+
public SessionDetail SessionDetail { get; set; }
992+
}
945993
}
946994
}

src/MartinCostello.BrowserStack.Automate/Session.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class Session : IBrowserInfo
2626
/// <summary>
2727
/// Gets or sets the duration of the session in seconds.
2828
/// </summary>
29-
[JsonProperty("duration")]
29+
[JsonProperty("duration", NullValueHandling = NullValueHandling.Ignore)] // TODO Should be nullable, but don't want to break binary compatibility
3030
public int Duration { get; set; }
3131

3232
/// <summary>

tests/MartinCostello.BrowserStack.Automate.Tests/BrowserStackAutomateClientTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ private static void AssertSession(Session session, string expectedName)
978978
session.ProjectName.Should().NotBeNullOrEmpty();
979979
session.Reason.Should().NotBeNullOrEmpty();
980980
session.Status.Should().NotBeNullOrEmpty();
981-
session.Duration.Should().BeGreaterThan(0);
981+
session.Duration.Should().BeGreaterThan(-1);
982982
}
983983

984984
/// <summary>

0 commit comments

Comments
 (0)