public void Should_Includ_A_Currectly_Structured_Channel_Url() { var channels = new List <YouTubeChannelDto> { new YouTubeChannelDto { id = "testchannelid", snippet = new YouTubeChannelSnippetDto { title = "testchannel", thumbnails = new YouTubeChannelSnippetThumbnailsDto { @default = new YouTubeChannelSnippetThumbnailDto { url = "http://thumbnail.url" } } } } }; var channelResults = MaybeResult <IEnumerable <YouTubeChannelDto>, StreamProviderError> .Success(channels); var channel = new YouTubeChannelMapper(youtubeWebUrl) .Map(channelResults) .GetOrElse(new PlatformChannelDto()); Assert.AreEqual(channel.ChannelName, "testchannel"); Assert.AreEqual(channel.AvatarUrl, "http://thumbnail.url"); Assert.AreEqual(channel.StreamPlatformName, StreamPlatform.YouTube); Assert.AreEqual(channel.ChannelUrl, "http://youtube.com/channel/testchannelid"); }
public PlatformStreamsDto Map( MaybeResult <IEnumerable <TwitchStreamDto>, StreamProviderError> twitchStreamResults, int pageSize, int pageOffset ) { return(twitchStreamResults.Select(streams => { var nextPagToken = streams.Count() == pageSize ? (pageOffset + pageSize).ToString() : string.Empty; return new PlatformStreamsDto { StreamPlatformName = StreamPlatform.Twitch, Streams = streams.Select(stream => new PlatformStreamDto { StreamTitle = stream.channel.status, StreamerName = stream.channel.display_name, StreamerAvatarUrl = stream.channel.logo, StreamThumbnailUrl = stream.preview.medium, StreamUrl = stream.channel.url, IsLive = true, Views = stream.viewers, }), NextPageToken = nextPagToken, }; }).GetOrElse(PlatformStreamsDto.Empty(StreamPlatform.Twitch))); }
public PlatformStreamsDto Map( MaybeResult <IEnumerable <DLiveStreamItemDto>, StreamProviderError> streamSearchResults, int pageSize, int pageOffset ) { return(streamSearchResults.Select(streams => { return new PlatformStreamsDto { StreamPlatformName = StreamPlatform.DLive, Streams = streams.Select(stream => { return new PlatformStreamDto { StreamTitle = stream.title, StreamerName = stream.creator.displayName, StreamThumbnailUrl = stream.thumbnailUrl, StreamerAvatarUrl = stream.creator.avatar, StreamUrl = $"{dliveWebUrl}/{stream.creator.displayName}", IsLive = true, Views = stream.watchingCount, }; }), NextPageToken = streams.Count() == pageSize ? (pageOffset + pageSize).ToString() : string.Empty }; }).GetOrElse(PlatformStreamsDto.Empty(StreamPlatform.DLive))); }
public async Task <MaybeResult <PlayerProfile, GenericErrorResult> > GetProfile(Guid id) { var profilePath = Directory.EnumerateFiles(_appDataDir, "*.json", SearchOption.TopDirectoryOnly) .Select(Path.GetFileName) .FirstOrDefault(x => { var idAndName = x.Split('_'); return(id == Guid.Parse(idAndName[0])); }); if (profilePath == null) { return(MaybeResult <PlayerProfile, GenericErrorResult> .CreateError(GenericErrorResult.NotFound)); } var profile = File.OpenRead(Path.Combine(_appDataDir, profilePath)) .DeserializeJsonFromStream <PlayerProfile>(); if (profile?.PlayerInfo == null) { return(MaybeResult <PlayerProfile, GenericErrorResult> .CreateError(GenericErrorResult.NotFound)); } return(MaybeResult <PlayerProfile, GenericErrorResult> .CreateOk(profile)); }
public static MaybeResult <TwitchChannelDto, StreamProviderError> Select( string channelName, MaybeResult <IEnumerable <TwitchChannelDto>, StreamProviderError> channelSearchResults) { return(channelSearchResults .Select(channels => channels .Where(channel => channel.display_name.Equals(channelName, StringComparison.CurrentCultureIgnoreCase)) .FirstOrDefault())); }
public void Should_Be_Success_With_A_Just_Value() { var successResult = MaybeResult <int, TestErrorType> .Success(1); Assert.IsTrue(successResult.IsSuccess); Assert.IsTrue(successResult.Value.IsSome); Assert.IsFalse(successResult.IsFailure); Assert.AreEqual(successResult.Error, TestErrorType.None); }
public void Should_Be_Fail_With_A_Nothing_Value() { var successResult = MaybeResult <int, TestErrorType> .Fail(TestErrorType.Error); Assert.IsTrue(successResult.IsFailure); Assert.IsTrue(successResult.Value.IsNothing); Assert.AreEqual(successResult.Error, TestErrorType.Error); Assert.IsFalse(successResult.IsSuccess); }
public void Should_Return_An_Empty_Next_Page_Token_When_The_Number_Of_Streams_Is_Less_Than_The_Page_Size() { var emptySearchResults = MaybeResult <IEnumerable <DLiveStreamItemDto>, StreamProviderError> .Success(new List <DLiveStreamItemDto>()); var streams = dliveStreamMapper.Map(emptySearchResults, pageSize, pageOffset); Assert.IsTrue(streams.IsEmpty()); Assert.IsEmpty(streams.NextPageToken); }
public void Should_Return_An_Empty_List_Of_Streams_When_No_Streams_Where_Returned_From_The_Streaming_Platform() { var emptySearchResults = MaybeResult <IEnumerable <DLiveStreamItemDto>, StreamProviderError> .Success(new List <DLiveStreamItemDto>()); var streams = dliveStreamMapper.Map(emptySearchResults, pageSize, pageOffset); Assert.IsTrue(streams.IsEmpty()); Assert.IsEmpty(streams.NextPageToken); }
public void Should_Return_Back_Nothing_When_No_Matching_Channel_Was_Found() { var channels = new List <TwitchChannelDto> { anotherChannel }; var channelResults = MaybeResult <IEnumerable <TwitchChannelDto>, StreamProviderError> .Success(channels); var channel = TwitchChannelSelector.Select(expectedChannel.display_name, channelResults); Assert.IsTrue(channel.IsNothing); }
public void Setup() { twitchStreamResults = new TwitchStreamPreviewResultsBuilder() .Add("http://stream.thumbnail.url", 1, "test channel", "http://channel.logo.url", "http://stream.url", "test stream") .Build(); }
public void Should_Return_Back_The_Matching_Channel() { var channels = new List <TwitchChannelDto> { expectedChannel, anotherChannel }; var channelResults = MaybeResult <IEnumerable <TwitchChannelDto>, StreamProviderError> .Success(channels); var channel = TwitchChannelSelector.Select(expectedChannel.display_name, channelResults); Assert.AreEqual(channel.GetOrElse(new TwitchChannelDto()), expectedChannel); }
public void Should_Be_Success_With_A_Maybe_Value() { var maybeValue = Maybe <int> .Some(1); var successResult = MaybeResult <int, TestErrorType> .Success(maybeValue); Assert.IsTrue(successResult.IsSuccess); Assert.AreEqual(successResult.Value, maybeValue); Assert.IsFalse(successResult.IsFailure); Assert.AreEqual(successResult.Error, TestErrorType.None); }
public bool Equals(BackblazeB2ActionResult <TResult> other) { if (EqualsPreamble(other) == false) { return(false); } TResult result = MaybeResult.OrElseDefault(); TResult otherResult = other.MaybeResult.OrElseDefault(); return(Equals(result, otherResult) && Enumerable.SequenceEqual(Errors, other.Errors)); }
public async Task SelectProfile(Guid id) { MaybeResult <PlayerProfile, GenericErrorResult> profileSelectionResult = await _profileService.GetProfile(id); if (profileSelectionResult.IsError) { throw new ArgumentNullException("id", $"Unable to find a profile with the id {id} on the local device."); } // Navigate to profile overview page that shows all questions await _navigationService.NavigateToViewModelAsync <ProfileOverviewViewModel>(profileSelectionResult.Unwrap()); }
public static async Task <MaybeResult <T, StreamProviderError> > GetOrError <T>(this Task <IFlurlResponse> responseTask) { var response = await responseTask; if (response.StatusCode >= 400) { return(MaybeResult <T, StreamProviderError> .Fail(StreamProviderError.ProviderNotAvailable)); } var payload = await response.GetJsonAsync <T>(); return(MaybeResult <T, StreamProviderError> .Success(payload)); }
public override int GetHashCode() { TResult result = MaybeResult.OrElseDefault(); int hashCode = 0; if (result != null) { hashCode ^= result.GetHashCode(); } return(Errors.Aggregate(hashCode, (acc, d) => d.GetHashCode() ^ acc)); }
public MaybeResult <PlatformChannelDto, StreamProviderError> Map( MaybeResult <TwitchChannelDto, StreamProviderError> twitchChannelResult) { return(twitchChannelResult.Select(channel => { return new PlatformChannelDto { ChannelName = channel.display_name, AvatarUrl = channel.logo, ChannelUrl = channel.url, StreamPlatformName = StreamPlatform.Twitch, }; })); }
public MaybeResult <PlatformChannelDto, StreamProviderError> Map( MaybeResult <DLiveUserDto, StreamProviderError> userSearchResult) { return(userSearchResult.Select(user => { return new PlatformChannelDto { ChannelName = user.displayName, AvatarUrl = user.avatar, ChannelUrl = $"{dliveWebUrl}/{user.displayName}", StreamPlatformName = StreamPlatform.DLive, }; })); }
public MaybeResult <PlatformStreamsDto, StreamProviderError> Map( YouTubeSearchDto videoSearchResults, MaybeResult <IEnumerable <YouTubeVideoDto>, StreamProviderError> videoDetailResults, MaybeResult <IEnumerable <YouTubeChannelDto>, StreamProviderError> videoChannelResults) { return(videoDetailResults.Chain(videosResult => { return videoChannelResults.Select(channelResults => { var videoDetails = videosResult.ToDictionary(v => v.id, v => v.liveStreamingDetails); var videoChannels = channelResults.ToDictionary(c => c.id, c => c.snippet); return ToStreams(videoSearchResults, videoChannels, videoDetails); }); })); }
public void Should_Map_A_DLive_Channel_To_A_PlatformChannel() { var mapper = new DLiveChannelMapper(dliveUrl); var dliveUser = new DLiveUserDto { displayName = "testuser", avatar = "http://avatar.url" }; var userSearchResults = MaybeResult <DLiveUserDto, StreamProviderError> .Success(dliveUser); var platformChannl = mapper.Map(userSearchResults).GetOrElse(new PlatformChannelDto()); Assert.AreEqual(platformChannl.ChannelName, "testuser"); Assert.AreEqual(platformChannl.AvatarUrl, "http://avatar.url"); Assert.AreEqual(platformChannl.StreamPlatformName, StreamPlatform.DLive); Assert.AreEqual(platformChannl.ChannelUrl, "http://dlive.com/testuser"); }
public void Should_Map_The_Channel_Exactly_Matching_The_Channel_Name_To_PlatformChannel() { var twitchChannelDto = new TwitchChannelDto { display_name = "test channel", logo = "http://logo.url", url = "http://channel.url", }; var twitchChannelResult = MaybeResult <TwitchChannelDto, StreamProviderError> .Success(twitchChannelDto); var platformChannel = new TwitchChannelMapper().Map(twitchChannelResult).GetOrElse(new PlatformChannelDto()); Assert.AreEqual(platformChannel.ChannelName, "test channel"); Assert.AreEqual(platformChannel.AvatarUrl, "http://logo.url"); Assert.AreEqual(platformChannel.ChannelUrl, "http://channel.url"); Assert.AreEqual(platformChannel.StreamPlatformName, StreamPlatform.Twitch); }
public MaybeResult <PlatformChannelDto, StreamProviderError> Map( MaybeResult <IEnumerable <YouTubeChannelDto>, StreamProviderError> channelSnippetResults) { return(channelSnippetResults.Select(channelSnippets => { return channelSnippets.Select(channelSnippet => { return new PlatformChannelDto { ChannelName = channelSnippet.snippet.title, AvatarUrl = [email protected], ChannelUrl = $"{youTubeWebUrl}/channel/{channelSnippet.id}", StreamPlatformName = StreamPlatform.YouTube, }; }) .FirstOrDefault(); })); }
public void Setup() { var dliveStreams = new List <DLiveStreamItemDto> { new DLiveStreamItemDto { title = "test stream", thumbnailUrl = "http://thunmbnail.url", watchingCount = 1, creator = new DLiveUserDto { displayName = "TestUserA", avatar = "http://avatar.url" } }, }; streamSearchResults = MaybeResult <IEnumerable <DLiveStreamItemDto>, StreamProviderError> .Success(dliveStreams); dliveStreamMapper = new DLiveStreamMapper(dliveUrl); }
public async Task AddQuestionToSavedProfile(Question newQuestion) { MaybeResult <PlayerProfile, GenericErrorResult> getProfileResult = await GetProfile(newQuestion.PlayerId); if (getProfileResult.IsError) { Debug.WriteLine($"Couldn't fine a profile with ID {newQuestion.PlayerId}"); return; } PlayerProfile profile = getProfileResult.Unwrap(); profile.Questions.Add(newQuestion); await SaveProfile(profile); _messagingService.Send(new ProfileUpdated { NewQuestion = newQuestion }); }
public static MaybeResult <T, GenericErrorResult> Failure <T>(GenericErrorResult error) { return(MaybeResult <T, GenericErrorResult> .CreateError(error)); }
public MaybeResult <IEnumerable <YouTubeVideoDto>, StreamProviderError> Build() { return(MaybeResult <IEnumerable <YouTubeVideoDto>, StreamProviderError> .Success(youTubeVideoDtos)); }
public MaybeResult <IEnumerable <TwitchStreamDto>, StreamProviderError> Build() { return(MaybeResult <IEnumerable <TwitchStreamDto>, StreamProviderError> .Success(twitchStreams)); }
} //Used in async method private Maybe(MaybeResult result) => this._result = result; // "Resolved" instance
public static MaybeResult <T, GenericErrorResult> Success <T>(T success) { return(MaybeResult <T, GenericErrorResult> .CreateOk(success)); }