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 SetlistRequestReturnsNullWhenCalledWithSetlistIdWhichResultsInError() { var mockHttpClientFactory = TestSetup.CreateMockHttpClientFactory(HttpStatusCode.NotFound); var mockSetlistFmService = new SetlistFmService(mockHttpClientFactory); var result = await mockSetlistFmService.SetlistRequest("invalidId"); Assert.Null(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 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 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); }