private async Task <ResponseInfo> GetSoundCloudSongs(JToken parameters) { var searchTerm = parameters["searchTerm"].ToObject <string>(); try { var requestCache = Locator.Current.GetService <IBlobCache>(BlobCacheKeys.RequestCacheContract); var songFinder = new SoundCloudSongFinder(requestCache); IReadOnlyList <SoundCloudSong> songs = await songFinder.GetSongsAsync(searchTerm); // Cache the latest SoundCloud search request, so we can find the songs by GUID when // we add one to the playlist later this.lastSoundCloudRequest = songs; JObject content = MobileHelper.SerializeSongs(songs); return(CreateResponse(ResponseStatus.Success, content)); } catch (NetworkSongFinderException) { return(CreateResponse(ResponseStatus.Failed, "Couldn't retrieve any SoundCloud songs")); } }
public async Task NullSearchTermDefaultsToEmptyString() { var songs = new[] { new SoundCloudSong { IsStreamable = true, StreamUrl = new Uri("http://blabla.com"), PermaLinkUrl = new Uri("http://blabla") } }; var cache = new InMemoryBlobCache(); cache.InsertObject(BlobCacheKeys.GetKeyForSoundCloudCache(string.Empty), songs); var finder = new SoundCloudSongFinder(cache); var result = await finder.GetSongsAsync(); Assert.Equal(1, result.Count); }
public async Task UsesCachedSongsIfAvailable() { const string searchTerm = "Foo"; var songs = new[] { new SoundCloudSong { IsStreamable = true, StreamUrl = new Uri("http://blabla.com"), PermaLinkUrl = new Uri("http://blabla") } }; var cache = new InMemoryBlobCache(); cache.InsertObject(BlobCacheKeys.GetKeyForSoundCloudCache(searchTerm), songs); var finder = new SoundCloudSongFinder(cache); var result = await finder.GetSongsAsync(searchTerm); Assert.Equal(1, result.Count); }
private async Task<ResponseInfo> GetSoundCloudSongs(JToken parameters) { var searchTerm = parameters["searchTerm"].ToObject<string>(); try { var requestCache = Locator.Current.GetService<IBlobCache>(BlobCacheKeys.RequestCacheContract); var songFinder = new SoundCloudSongFinder(requestCache); IReadOnlyList<SoundCloudSong> songs = await songFinder.GetSongsAsync(searchTerm); // Cache the latest SoundCloud search request, so we can find the songs by GUID when // we add one to the playlist later this.lastSoundCloudRequest = songs; JObject content = MobileHelper.SerializeSongs(songs); return CreateResponse(ResponseStatus.Success, content); } catch (NetworkSongFinderException) { return CreateResponse(ResponseStatus.Failed, "Couldn't retrieve any SoundCloud songs"); } }