Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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());
        }
Пример #4
0
        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);
        }
Пример #5
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);
        }
Пример #6
0
        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);
        }
Пример #7
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);
        }
Пример #8
0
        public void GetAccessTokenReturnsAnExceptionIfAccessTokenNotReturned()
        {
            var mockHttpClientFactory  = TestSetup.CreateMockHttpClientFactory(HttpStatusCode.NotFound);
            var mockConfiguration      = new MockConfiguration();
            var mockSpotifyAuthService = new SpotifyAuthService(mockHttpClientFactory, mockConfiguration);

            var ex = Assert.ThrowsAsync <SpotifyAuthException>(() => mockSpotifyAuthService.GetAccessToken());

            Assert.Equal(ErrorConstants.SpotifyAuthError, ex.Result.Message);
        }
Пример #9
0
        public void GetAccessTokenReturnsASpotifyAccessTokenStringWhenRequestIsSuccess()
        {
            var     testAccessToken   = "{\"access_token\": \"testToken\"}";
            JObject parsedAccessToken = JObject.Parse(testAccessToken);

            var mockHttpClientFactory  = TestSetup.CreateMockHttpClientFactory(HttpStatusCode.OK, parsedAccessToken);
            var mockConfiguration      = new MockConfiguration();
            var mockSpotifyAuthService = new SpotifyAuthService(mockHttpClientFactory, mockConfiguration);

            var result = mockSpotifyAuthService.GetAccessToken();

            Assert.Equal("testToken", result.Result);
        }
Пример #10
0
        public void HttpClientIsReturnedWithTheCorrectHeaders()
        {
            var content = JsonConvert.SerializeObject("test");
            var mockHttpMessageHandler = TestSetup.CreateMockHttpMessageHandler(HttpStatusCode.OK, content);
            var mockHttpClientFactory  = TestSetup.CreateMockHttpClientFactory(HttpStatusCode.NotFound);
            var mockConfiguration      = new MockConfiguration();
            var mockSpotifyAuthService = new SpotifyAuthService(mockHttpClientFactory, mockConfiguration);

            var mockHttpClient = new HttpClient(mockHttpMessageHandler.Object);

            mockSpotifyAuthService.AddHeaders(mockHttpClient);

            Assert.Equal("application/json", mockHttpClient.DefaultRequestHeaders.Accept.ToString());
            Assert.Contains("Basic", mockHttpClient.DefaultRequestHeaders.Authorization.ToString());
        }
Пример #11
0
        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);
        }
Пример #12
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);
        }
Пример #13
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);
        }
Пример #14
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);
        }
Пример #15
0
        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());
        }
Пример #16
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);
        }
Пример #17
0
        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);
        }
Пример #18
0
        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);
        }
Пример #19
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);
        }