예제 #1
0
        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);
        }
예제 #2
0
        public async void SetlistRequestReturnsNullWhenCalledWithSetlistIdWhichResultsInError()
        {
            var mockHttpClientFactory = TestSetup.CreateMockHttpClientFactory(HttpStatusCode.NotFound);
            var mockSetlistFmService  = new SetlistFmService(mockHttpClientFactory);

            var result = await mockSetlistFmService.SetlistRequest("invalidId");

            Assert.Null(result);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }
예제 #7
0
        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);
        }