public async void GivenSetlistServiceReturnsASuccessResult_WhenCallingGetSetlist_ThenItReturnsAStatus200() { var testSetlist = "{ \"id\": \"testId\", " + "\"eventDate\": \"30-07-2019\", " + "\"artist\": {\"name\": \"artistName\"}, " + "\"venue\": {\"name\": \"venueName\"}, " + "\"sets\": {\"set\": [{\"song\": [{\"name\": \"songTitle1\"}]}]}}"; JObject parsedSetlist = JObject.Parse(testSetlist); var testSpotifyTracks = "{\"tracks\": {\"items\": [{\"name\": \"songTitle\", \"uri\": \"spotify:track:uri1\"}]}}"; JObject parsedSpotifyTracks = JObject.Parse(testSpotifyTracks); var mockHttpClientFactoryForSetlistFmService = TestSetup.CreateMockHttpClientFactory(HttpStatusCode.OK, parsedSetlist); var mockSetlistFmService = new SetlistFmService(mockHttpClientFactoryForSetlistFmService); var setlistDto = mockSetlistFmService.SetlistRequest("testId"); var mockHttpClientFactoryforSpotifyService = TestSetup.CreateMockHttpClientFactory(HttpStatusCode.OK, parsedSpotifyTracks); var mockSpotifyService = new SpotifyService(mockHttpClientFactoryforSpotifyService); await mockSpotifyService.SpotifyRequest(setlistDto.Result); var mockSpotSetService = new SpotSetService(mockSetlistFmService, mockSpotifyService); var controller = CreateController(mockSpotSetService); var result = await controller.GetSetlist("testId"); Assert.IsType <OkObjectResult>(result); }
public async void GetSetlistReturnsASpotSetDtoWhenCalledWithSetlistIdThatReturnsValidDataButMissingTrackInfo() { var testSetlist = "{ \"id\": \"testId\", " + "\"eventDate\": \"30-07-2019\", " + "\"artist\": {\"name\": \"artistName\"}, " + "\"venue\": {\"name\": \"venueName\"}, " + "\"sets\": {\"set\": [{\"song\": [{\"name\": \"songTitle\"}]}]}}"; JObject parsedSetlist = JObject.Parse(testSetlist); var testSpotifyTracks = "{\"tracks\": {\"items\": [{\"name\": \"songTitle\"}]}}"; JObject parsedSpotifyTracks = JObject.Parse(testSpotifyTracks); var mockHttpClientFactoryForSetlistFmService = TestSetup.CreateMockHttpClientFactory(HttpStatusCode.OK, parsedSetlist); var mockSetlistFmService = new SetlistFmService(mockHttpClientFactoryForSetlistFmService); var mockHttpClientFactoryforSpotifyService = TestSetup.CreateMockHttpClientFactory(HttpStatusCode.OK, parsedSpotifyTracks); var mockSpotifyService = new SpotifyService(mockHttpClientFactoryforSpotifyService); var mockSpotSetService = new SpotSetService(mockSetlistFmService, mockSpotifyService); var result = await mockSpotSetService.GetSetlist("testId"); Assert.Equal("testId", result.Id); Assert.Equal("07-30-2019", result.EventDate); Assert.Equal("artistName", result.Artist); Assert.Equal("venueName", result.Venue); Assert.Equal("songTitle", result.Tracks[0].Name); Assert.Null(result.Tracks[0].TrackUri); }
public async void GivenSetlistServiceReturnsAnErrorResultFromSpotifyService_WhenCallingGetSetlist_ThenItReturnsTheCorrectError() { var testSetlist = "{ \"id\": \"testId\", " + "\"eventDate\": \"30-07-2019\", " + "\"artist\": {\"name\": \"artistName\"}, " + "\"venue\": {\"name\": \"venueName\"}, " + "\"sets\": {\"set\": [{\"song\": [{\"name\": \"songTitle1\"}]}]}}"; JObject parsedSetlist = JObject.Parse(testSetlist); var mockHttpClientFactoryForSetlistFmService = TestSetup.CreateMockHttpClientFactory(HttpStatusCode.OK, parsedSetlist); var mockSetlistFmService = new SetlistFmService(mockHttpClientFactoryForSetlistFmService); var mockHttpClientFactoryforSpotifyService = TestSetup.CreateMockHttpClientFactory(HttpStatusCode.NotFound); var mockSpotifyService = new SpotifyService(mockHttpClientFactoryforSpotifyService); var mockSpotSetService = new SpotSetService(mockSetlistFmService, mockSpotifyService); var controller = CreateController(mockSpotSetService); var result = await controller.GetSetlist("invalidId"); var error = Assert.IsType <NotFoundObjectResult>(result); Assert.Contains(ErrorConstants.SpotifyError, error.Value.ToString()); }
public async void SetlistRequestReturnsNullWhenCalledWithSetlistIdWhichResultsInError() { var mockHttpClientFactory = TestSetup.CreateMockHttpClientFactory(HttpStatusCode.NotFound); var mockSetlistFmService = new SetlistFmService(mockHttpClientFactory); var result = await mockSetlistFmService.SetlistRequest("invalidId"); Assert.Null(result); }
public async void GivenSetlistServiceReturnsAnErrorResultFromSetlistService_WhenCallingGetSetlist_ThenItReturnsAStatus404() { var mockHttpClientFactoryForSetlistFmService = TestSetup.CreateMockHttpClientFactory(HttpStatusCode.NotFound); var mockSetlistFmService = new SetlistFmService(mockHttpClientFactoryForSetlistFmService); var mockHttpClientFactoryforSpotifyService = TestSetup.CreateMockHttpClientFactory(HttpStatusCode.NotFound); var mockSpotifyService = new SpotifyService(mockHttpClientFactoryforSpotifyService); var mockSpotSetService = new SpotSetService(mockSetlistFmService, mockSpotifyService); var controller = CreateController(mockSpotSetService); var result = await controller.GetSetlist("invalidId"); Assert.IsType <NotFoundObjectResult>(result); }
public async void GetSetlistReturnsSetlistExceptionWhenSetlistFmServiceResultsInError() { var mockHttpClientFactoryForSetlistFmService = TestSetup.CreateMockHttpClientFactory(HttpStatusCode.NotFound); var mockSetlistFmService = new SetlistFmService(mockHttpClientFactoryForSetlistFmService); await mockSetlistFmService.SetlistRequest("testId"); var mockHttpClientFactoryforSpotifyService = TestSetup.CreateMockHttpClientFactory(HttpStatusCode.NotFound); var mockSpotifyService = new SpotifyService(mockHttpClientFactoryforSpotifyService); var mockSpotSetService = new SpotSetService(mockSetlistFmService, mockSpotifyService); var ex = Assert.ThrowsAsync <SetlistNotFoundException>(() => mockSpotSetService.GetSetlist("testId")); var expected = ErrorConstants.SetlistError + "testId" + ErrorConstants.SetlistErrorTryAgain; Assert.Equal(expected, ex.Result.Message); }
public async void DatesFromIncomingDataAreProperlyFormattedToMonthDayYearWhenDayIsSingleDigit() { var testSetlist = "{ \"id\": \"testId\", " + "\"eventDate\": \"03-07-2019\", " + "\"artist\": {\"name\": \"artistName\"}, " + "\"venue\": {\"name\": \"venueName\"}, " + "\"sets\": {\"set\": [{\"song\": [{\"name\": \"songTitle\"}]}]}}"; JObject parsedSetlist = JObject.Parse(testSetlist); var mockHttpClientFactory = TestSetup.CreateMockHttpClientFactory(HttpStatusCode.OK, parsedSetlist); var mockSetlistFmService = new SetlistFmService(mockHttpClientFactory); var result = await mockSetlistFmService.SetlistRequest("testId"); Assert.Equal("07-03-2019", result.EventDate); }
public async void SetlistDtoIsReturnedWithTracksFieldEmptyAfterDeserialization() { var testSetlist = "{ \"id\": \"testId\", " + "\"eventDate\": \"03-07-2019\", " + "\"artist\": {\"name\": \"artistName\"}, " + "\"venue\": {\"name\": \"venueName\"}, " + "\"sets\": {\"set\": [{\"song\": []}]}}"; JObject parsedSetlist = JObject.Parse(testSetlist); var mockHttpClientFactory = TestSetup.CreateMockHttpClientFactory(HttpStatusCode.OK, parsedSetlist); var mockSetlistFmService = new SetlistFmService(mockHttpClientFactory); var result = await mockSetlistFmService.SetlistRequest("testId"); Assert.Empty(result.Tracks); }
public async void GivenSetlistServiceReturnsAnErrorResultFromSetlistService_WhenCallingGetSetlist_ThenItReturnsTheCorrectError() { var mockHttpClientFactoryForSetlistFmService = TestSetup.CreateMockHttpClientFactory(HttpStatusCode.NotFound); var mockSetlistFmService = new SetlistFmService(mockHttpClientFactoryForSetlistFmService); var mockHttpClientFactoryforSpotifyService = TestSetup.CreateMockHttpClientFactory(HttpStatusCode.NotFound); var mockSpotifyService = new SpotifyService(mockHttpClientFactoryforSpotifyService); var mockSpotSetService = new SpotSetService(mockSetlistFmService, mockSpotifyService); var controller = CreateController(mockSpotSetService); var result = await controller.GetSetlist("invalidId"); var error = Assert.IsType <NotFoundObjectResult>(result); var expected = ErrorConstants.SetlistError + "invalidId" + ErrorConstants.SetlistErrorTryAgain; Assert.Contains(expected, error.Value.ToString()); }
public async void SetlistDtoIsReturnedWithTracksFieldPopulatedWithManyTrackAfterDeserialization() { var testSetlist = "{ \"id\": \"testId\", " + "\"eventDate\": \"03-07-2019\", " + "\"artist\": {\"name\": \"artistName\"}, " + "\"venue\": {\"name\": \"venueName\"}, " + "\"sets\": {\"set\": [{\"song\": [{\"name\": \"songTitle1\"}]}, {\"song\": [{\"name\": \"songTitle2\"}]}, {\"song\": [{\"name\": \"songTitle3\"}]}]}}"; JObject parsedSetlist = JObject.Parse(testSetlist); var mockHttpClientFactory = TestSetup.CreateMockHttpClientFactory(HttpStatusCode.OK, parsedSetlist); var mockSetlistFmService = new SetlistFmService(mockHttpClientFactory); var result = await mockSetlistFmService.SetlistRequest("testId"); Assert.Equal(3, result.Tracks.Count); Assert.Equal("songTitle1", result.Tracks[0].Name); Assert.Equal("songTitle2", result.Tracks[1].Name); Assert.Equal("songTitle3", result.Tracks[2].Name); }
public void GetSetlistReturnsSpotifyExceptionWhenSpotifyServiceResultsInAnEmptySpotifyTracksDto() { var testSetlist = "{ \"id\": \"testId\", " + "\"eventDate\": \"30-07-2019\", " + "\"artist\": {\"name\": \"artistName\"}, " + "\"venue\": {\"name\": \"venueName\"}, " + "\"sets\": {\"set\": [{\"song\": []}]}}"; JObject parsedSetlist = JObject.Parse(testSetlist); var mockHttpClientFactoryForSetlistFmService = TestSetup.CreateMockHttpClientFactory(HttpStatusCode.OK, parsedSetlist); var mockSetlistFmService = new SetlistFmService(mockHttpClientFactoryForSetlistFmService); var mockHttpClientFactoryforSpotifyService = TestSetup.CreateMockHttpClientFactory(HttpStatusCode.NotFound); var mockSpotifyService = new SpotifyService(mockHttpClientFactoryforSpotifyService); var mockSpotSetService = new SpotSetService(mockSetlistFmService, mockSpotifyService); var ex = Assert.ThrowsAsync <SpotifyNotFoundException>(() => mockSpotSetService.GetSetlist("testId")); Assert.Equal(ErrorConstants.SpotifyError, ex.Result.Message); }
public async void SetlistRequestReturnsASetlistDtoWhenCalledWithSetlistIdWhichHasMissingData() { var testSetlist = "{ \"id\": \"testId\", " + "\"eventDate\": \"30-07-2019\", " + "\"artist\": {\"name\": \"\"}, " + "\"venue\": {\"name\": \"\"}, " + "\"sets\": {\"set\": [{\"song\": [{\"name\": \"\"}]}]}}"; JObject parsedSetlist = JObject.Parse(testSetlist); var mockHttpClientFactory = TestSetup.CreateMockHttpClientFactory(HttpStatusCode.OK, parsedSetlist); var mockSetlistFmService = new SetlistFmService(mockHttpClientFactory); var result = await mockSetlistFmService.SetlistRequest("testId"); Assert.IsType <SetlistDto>(result); Assert.Equal("testId", result.Id); Assert.Equal("07-30-2019", result.EventDate); Assert.Equal("", result.Artist.Name); Assert.Equal("", result.Venue.Name); Assert.Equal("", result.Sets.Set.First().Song.First().Name); }