public async Task Handles_no_results([Frozen] IApi zendesk, Watcher sut)
        {
            zendesk.SearchTickets(Arg.Any <string>())
            .Returns(SearchResponse.Create());

            var result = await sut.GetTicketsForSharing();

            result.Should().BeEmpty();
        }
        public async Task Filters_out_tickets_returned_by_api_that_do_not_have_tag([Frozen] IApi zendesk, Watcher sut, Ticket ticket)
        {
            ticket.Tags.Clear();
            zendesk.SearchTickets(Arg.Any <string>())
            .Returns(SearchResponse.Create(ticket));

            var result = await sut.GetTicketsForSharing();

            result.Should().BeEmpty();
        }
        public async Task Returns_all_tickets_with_tag(string tagName, [Frozen] IApi zendesk, Watcher sut, Ticket ticket)
        {
            ticket.Tags = new List <string> {
                tagName
            };
            zendesk.SearchTickets(Arg.Any <string>())
            .Returns(SearchResponse.Create(ticket));

            var result = await sut.GetTicketsForSharing();

            result.Should().Contain(ticket.Id);
        }
예제 #4
0
        /// <inheritdoc />
        public async ValueTask <SearchResponse> SearchAsync(string query)
        {
            var response = SearchResponse.Create(query);

            query = query switch
            {
                var trackUrl when _trackUrlRegex.IsMatch(query) => trackUrl,
                var albumUrl when _albumUrlRegex.IsMatch(query) => albumUrl,
                _ =>
                $"https://bandcamp.com/search?q={WebUtility.UrlEncode(query)}"
            };

            var json = await BandCampParser.ScrapeJsonAsync(_restClient, query)
                       .ConfigureAwait(false);

            if (string.IsNullOrWhiteSpace(json))
            {
                return(response.WithStatus(SearchStatus.SearchError));
            }

            try
            {
                var bcResult = JsonSerializer.Deserialize <BandCampResult>(json);
                response.WithStatus(bcResult.ItemType switch
                {
                    "album" => SearchStatus.PlaylistLoaded,
                    "track" => SearchStatus.TrackLoaded,
                    _ => SearchStatus.NoMatches
                });

                if (response.Status == SearchStatus.NoMatches)
                {
                    return(response);
                }

                long duration = 0;
                foreach (var trackInfo in bcResult.TrackInfo)
                {
                    var track = trackInfo.AsTrackInfo(bcResult.Artist, bcResult.Url, bcResult.ArtId);
                    response.WithTrack(track);
                    duration += track.Duration;
                }

                var playlistInfo = new PlaylistInfo()
                                   .WithId($"{bcResult.Current.Id}")
                                   .WithName(bcResult.Current.Title)
                                   .WithUrl(bcResult.Url)
                                   .WithDuration(duration)
                                   .WithArtwork(bcResult.ArtId == 0 ? default : $"https://f4.bcbits.com/img/a{bcResult.ArtId}_0.jpg");

                response.WithPlaylist(playlistInfo);
            }
예제 #5
0
        public async Task <SearchResponse> Search(string firstName, string lastName, string phone)
        {
            var users = await repository.FindUsers(U => U.PhoneNumber.Contains(phone));

            return(SearchResponse.Create(users.Select(U => U.ToPresent())));
        }