-
Notifications
You must be signed in to change notification settings - Fork 19
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 #77 from CodeItQuick/dev_original
Issue #35 Curate the Live Channels Display on Homepage
- Loading branch information
Showing
16 changed files
with
263 additions
and
40 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 |
---|---|---|
@@ -1,8 +1,13 @@ | ||
namespace DevChatter.DevStreams.Core.Twitch | ||
using NodaTime; | ||
|
||
namespace DevChatter.DevStreams.Core.Twitch | ||
{ | ||
public class ChannelLiveState | ||
{ | ||
public string TwitchId { get; set; } | ||
public bool IsLive { get; set; } | ||
public Instant StartedAt { get; set; } | ||
public Duration TimeOnline => SystemClock.Instance.GetCurrentInstant() - StartedAt; | ||
public int ViewerCount { 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
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
66 changes: 66 additions & 0 deletions
66
...ests/Core/Twitch/TwitchResultExtensions/CreateChannelLiveStatesFromStreamResultsShould.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,66 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using DevChatter.DevStreams.Core.Twitch; | ||
using FluentAssertions; | ||
using NodaTime; | ||
using NodaTime.Text; | ||
using Xunit; | ||
|
||
namespace DevChatter.DevStreams.UnitTests.Core.Twitch.TwitchResultExtensions | ||
{ | ||
public class CreateChannelLiveStatesFromStreamResultsShould | ||
{ | ||
[Fact] | ||
public void ReturnEmpty_GivenNoResults() | ||
{ | ||
var streamResult = new StreamResult { Data = new List<StreamResultData>() }; | ||
var twitchIds = new List<string>(); | ||
|
||
var liveStates = streamResult.CreateChannelLiveStatesFromStreamResults(twitchIds); | ||
|
||
liveStates.Should().BeEmpty(); | ||
} | ||
|
||
[Fact] | ||
public void ReturnNonLiveResult_GivenNotLiveChannel() | ||
{ | ||
const string twitchId = "123Link"; | ||
var streamResult = new StreamResult {Data = new List<StreamResultData>()}; | ||
var twitchIds = new List<string> { twitchId }; | ||
|
||
var liveStates = streamResult.CreateChannelLiveStatesFromStreamResults(twitchIds); | ||
|
||
liveStates.Single().IsLive.Should().BeFalse(); | ||
liveStates.Single().TwitchId.Should().Be(twitchId); | ||
liveStates.Single().StartedAt.Should().Be(Instant.MinValue); | ||
liveStates.Single().ViewerCount.Should().Be(0); | ||
} | ||
|
||
[Fact] | ||
public void ReturnLiveResultWithData_GivenLiveChannel() | ||
{ | ||
const string twitchId = "DevChatter42"; | ||
var startedAt = InstantPattern.General.Parse("2019-05-04T17:04:19Z").Value; | ||
const int viewerCount = 77; | ||
var streamResult = new StreamResult {Data = new List<StreamResultData> | ||
{ | ||
new StreamResultData | ||
{ | ||
Started_at = startedAt, | ||
Viewer_count = viewerCount, | ||
User_id = twitchId, | ||
} | ||
}}; | ||
var twitchIds = new List<string> { twitchId }; | ||
|
||
var liveState = streamResult.CreateChannelLiveStatesFromStreamResults(twitchIds) | ||
.Single(); | ||
|
||
liveState.IsLive.Should().BeTrue(); | ||
liveState.TwitchId.Should().Be(twitchId); | ||
liveState.StartedAt.Should().Be(startedAt); | ||
liveState.ViewerCount.Should().Be(viewerCount); | ||
} | ||
} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
src/DevChatter.DevStreams.Web/Data/ViewModel/LiveChannels/LiveChannelViewModel.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,14 @@ | ||
using NodaTime; | ||
|
||
namespace DevChatter.DevStreams.Web.Data.ViewModel.LiveChannels | ||
{ | ||
public class LiveChannelViewModel | ||
{ | ||
public string ChannelName { get; set; } | ||
public string Uri { get; set; } | ||
public Instant StartedAt { get; set; } | ||
public Duration TimeOnline => SystemClock.Instance.GetCurrentInstant() - StartedAt; | ||
public int ViewerCount { get; set; } | ||
|
||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/DevChatter.DevStreams.Web/Data/ViewModel/LiveChannels/LiveChannelsMappingExtensions.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,21 @@ | ||
using DevChatter.DevStreams.Core.Model; | ||
using DevChatter.DevStreams.Core.Twitch; | ||
|
||
namespace DevChatter.DevStreams.Web.Data.ViewModel.LiveChannels | ||
{ | ||
public static class LiveChannelsMappingExtensions | ||
{ | ||
public static LiveChannelViewModel ToViewModel(this ChannelLiveState src, Channel channel) | ||
{ | ||
var viewModel = new LiveChannelViewModel | ||
{ | ||
ChannelName = channel.Name, | ||
Uri = channel.Uri, | ||
StartedAt = src.StartedAt, | ||
ViewerCount = src.ViewerCount, | ||
}; | ||
|
||
return viewModel; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.