public async void SpotifyRequestReturnsASpotifyTracksModelWithTrackInformationWhenCalledWithValidSetlistModel() { var newSetlist = new SetlistDto { Id = "setlistId", EventDate = "01-07-2019", Artist = new Artist { Name = "Artist" }, Venue = new Venue { Name = "Venue" }, Tracks = new List <Song> { new Song { Name = "Song Title" } } }; var testSpotifyTracks = "{\"tracks\": {\"items\": [{\"name\": \"Song Title\", \"uri\": \"spotify:track:uri1\"}]}}"; JObject parsedSpotifyTracks = JObject.Parse(testSpotifyTracks); var mockHttpClientFactoryforSpotifyService = TestSetup.CreateMockHttpClientFactory(HttpStatusCode.OK, parsedSpotifyTracks); var mockSpotifyService = new SpotifyService(mockHttpClientFactoryforSpotifyService); var result = await mockSpotifyService.SpotifyRequest(newSetlist); Assert.Equal("Song Title", result.SpotifyTracks.First().Tracks.Items[0].Name); Assert.Equal("spotify:track:uri1", result.SpotifyTracks.First().Tracks.Items[0].Uri); }
public OkObjectResult DownloadSetlist([FromBody] EnsembleBookingDto dto) { var userId = GetUserId(); var booking = _context.Bookings .Include(b => b.Event) .Include(b => b.Ensemble) .FirstOrDefault(b => b.BookingId == dto.BookingId); var userIsMember = _context.EnsembleMembers .Any(em => em.UserIdRecipient == userId && em.EnsembleId == booking.EnsembleId && em.Status == RequestStatus.Accepted); if (!userIsMember || booking == null) { return(new OkObjectResult(new { success = false, error = "invalid request" })); } var setlist = new SetlistDto { EnsembleName = booking.Ensemble.Name, EventName = booking.Event.Name, EventLocation = booking.Event.Location, DateAndTime = booking.Event.DateAndTime, Setlist = booking.Setlist }; return(new OkObjectResult(new { success = true, setlist })); }
public async void SpotifyRequestReturnsSpotifyTracksModelWithCorrectNumberOfTracksWhenCalledWithASetlistModel() { var newSetlist = new SetlistDto { Id = "setlistId", EventDate = "01-07-2019", Artist = new Artist { Name = "Artist" }, Venue = new Venue { Name = "Venue" }, Tracks = new List <Song> { new Song { Name = "Song Title" }, new Song { Name = "Another Song Title" } } }; var mockHttpClientFactoryforSpotifyService = TestSetup.CreateMockHttpClientFactory(HttpStatusCode.OK); var mockSpotifyService = new SpotifyService(mockHttpClientFactoryforSpotifyService); var result = await mockSpotifyService.SpotifyRequest(newSetlist); Assert.Equal(2, result.SpotifyTracks.Count); }
public async void SpotifyRequestReturnsASpotifyModelWhenCalledWithValidSetlistModel() { var newSetlist = new SetlistDto { Id = "setlistId", EventDate = "01-07-2019", Artist = new Artist { Name = "Artist" }, Venue = new Venue { Name = "Venue" }, Tracks = new List <Song> { new Song { Name = "Song Title" } } }; var mockHttpClientFactoryforSpotifyService = TestSetup.CreateMockHttpClientFactory(HttpStatusCode.OK); var mockSpotifyService = new SpotifyService(mockHttpClientFactoryforSpotifyService); var result = await mockSpotifyService.SpotifyRequest(newSetlist); Assert.IsType <SpotifyTracksModel>(result); }
private static SpotSetDto CreateSpotSetDto(SetlistDto setlistModel, List <TracksDto> tracksDto) { var spotSetDto = new SpotSetDto { Id = setlistModel.Id, EventDate = setlistModel.EventDate, Artist = setlistModel.Artist.Name, Venue = setlistModel.Venue.Name, Tracks = tracksDto }; return(spotSetDto); }
private static async Task <SpotifyTracksModel> CreateSpotifyTracksModel(SetlistDto setlistModel, HttpClient spotifyHttpClient) { var artist = setlistModel?.Artist?.Name; var spotifyTracks = new SpotifyTracksModel(); foreach (var track in setlistModel.Tracks) { var spotifyResponse = await SendRequest(spotifyHttpClient, artist, track); if (spotifyResponse.StatusCode == HttpStatusCode.OK) { var spotifyTrack = DeserializeSpotifyTracks(spotifyResponse); spotifyTracks.Add(spotifyTrack.Result); } } return(spotifyTracks); }
public async void SpotifyRequestReturnsEmptySpotifyTracksModelWhenCalledWithAnInvalidSetlistModel() { var newSetlist = new SetlistDto { Id = null, EventDate = null, Artist = new Artist { Name = null }, Venue = new Venue { Name = null }, Tracks = new List <Song>() }; var mockHttpClientFactoryforSpotifyService = TestSetup.CreateMockHttpClientFactory(HttpStatusCode.OK); var mockSpotifyService = new SpotifyService(mockHttpClientFactoryforSpotifyService); var result = await mockSpotifyService.SpotifyRequest(newSetlist); Assert.Equal(0, result.SpotifyTracks.Count); }
public async Task <SpotifyTracksModel> SpotifyRequest(SetlistDto setlistModel) { var spotifyHttpClient = CreateHttpClient(); return(await CreateSpotifyTracksModel(setlistModel, spotifyHttpClient)); }
private static SetlistDto AddTracksField(SetlistDto setlist) { setlist.Tracks = setlist.Sets.Set.SelectMany(s => s.Song).ToList(); return(setlist); }