public async Task <List <ChannelClipsContainer> > BuildClipContainers(string topClipsEndpoint, string clientId, string accept, List <PendingChannelConfigContainer> channelContainers) { var channelClipsContainers = new List <ChannelClipsContainer>(); var clipsCache = new Dictionary <string, GetClipsResponse>(); foreach (var channelContainer in channelContainers) { var pendingClipContainers = new List <PendingClipContainer>(); foreach (var broadcasterContainer in channelContainer.Broadcasters) { if (clipsCache.ContainsKey(broadcasterContainer.Broadcaster)) { var pendingClipContainer = new PendingClipContainer(broadcasterContainer, clipsCache[broadcasterContainer.Broadcaster]); pendingClipContainers.Add(pendingClipContainer); } else { var channelEndpoint = $"{topClipsEndpoint}&channel={broadcasterContainer.Broadcaster}"; var response = await _TwitchWrapper.GetClips(channelEndpoint, clientId, accept); var pendingClipContainer = new PendingClipContainer(broadcasterContainer, response); pendingClipContainers.Add(pendingClipContainer); clipsCache.Add(broadcasterContainer.Broadcaster, response); } } var channelClipsContainer = new ChannelClipsContainer(channelContainer, pendingClipContainers); channelClipsContainers.Add(channelClipsContainer); } return(channelClipsContainers); }
public void ClipsWithMinViews(int clipViews, int?globalMinViews, int?minViews, int expectedResult) { const int id = 123; var clip = new Clip { Views = clipViews }; var clips = new List <Clip> { clip }; var pendingClipContainer = new PendingClipContainer { Clips = clips, MinViews = minViews }; var pendingClipContainers = new List <PendingClipContainer> { pendingClipContainer }; var pendingChannelConfigContainer = new PendingChannelConfigContainer { ChannelId = id, GlobalMinViews = globalMinViews }; var channelClipsContainer = new ChannelClipsContainer { PendingChannelConfigContainer = pendingChannelConfigContainer, PendingClipContainers = pendingClipContainers }; var channelClipsContainers = new List <ChannelClipsContainer> { channelClipsContainer }; var results = _Helper.ClipsWithMinViews(channelClipsContainers); Assert.That(results.Count(s => s.PendingChannelConfigContainer.ChannelId == id), Is.EqualTo(expectedResult)); }