Esempio n. 1
0
        public async Task GetUserAccessToken_TokenExpired_ReturnsNewToken()
        {
            // arrange
            var expiredToken = new BearerAccessToken
            {
                AccessToken = "abcd1234",
                ExpiresIn   = 3600,
                Expires     = new DateTime(2018, 7, 28, 9, 18, 0, DateTimeKind.Utc)
            };

            const string json = @"{
""access_token"": ""NgCXRKc...MzYjw"",
""token_type"": ""bearer"",
""expires_in"": 3600,
}";

            var mockHttp = new MockHttpClient();

            mockHttp.SetupSendAsync(json);
            var http = mockHttp.HttpClient;

            var bearerTokenStore = new Mock <IBearerTokenStore>();

            bearerTokenStore.Setup(s => s.Get(It.IsAny <string>())).ReturnsAsync(expiredToken);
            var config            = new MockConfiguration().Object;
            var refreshTokenStore = new MockRefreshTokenStore(UserHash, config).Object;
            var service           = new UserAccountsService(http, config, refreshTokenStore, bearerTokenStore.Object);

            // act
            var token = await service.GetUserAccessToken(UserHash);

            // assert
            Assert.AreNotEqual(expiredToken, token);
        }
        public async Task BasicUsage()
        {
            // Arrange
            const string username = "******";

            var mockHttp = new MockHttpClient();

            mockHttp.SetupSendAsync("{\"Id\":\"def456\",\"Name\":\"ghi789\"}");
            var accounts  = new MockAccountsService().Object;
            var playlists = new PlaylistsApi(mockHttp.HttpClient, accounts);

            // Act
            var result1 = await playlists.GetPlaylists(username);

            Trace.WriteLine(result1);
        }
        public async Task GetTracks_UsernameAndPlaylistId_GetAccessTokenCalled()
        {
            // Arrange
            const string playlistId = "jkl012";

            var mockHttp = new MockHttpClient();

            mockHttp.SetupSendAsync("{\"Id\":\"def456\",\"Name\":\"ghi789\"}");
            var mockAccounts = new MockAccountsService();

            var api = new PlaylistsApi(mockHttp.HttpClient, mockAccounts.Object);

            // Act
            await api.GetTracks(playlistId);

            // Assert
            mockAccounts.Verify(a => a.GetAccessToken());
        }
Esempio n. 4
0
        public async Task GetPlaylists_Username_GetAccessTokenCalled()
        {
            // Arrange
            const string username = "******";

            var mockHttp = new MockHttpClient();

            mockHttp.SetupSendAsync("{\"Id\":\"def456\",\"Name\":\"ghi789\"}");
            var mockAccounts = new MockAccountsService();

            var api = new PlaylistsApi(mockHttp.HttpClient, mockAccounts.Object);

            // Act
            await api.GetPlaylists(username);

            // Assert
            mockAccounts.Verify(a => a.GetAppAccessToken());
        }
Esempio n. 5
0
        public async Task GetCurrentPlaybackInfo_AccessToken_GetModelInvokedWithAccessToken()
        {
            // arrange
            const string token = "abc123";
            string       json  = JsonConvert.SerializeObject(new CurrentPlaybackContext());
            var          http  = new MockHttpClient();

            http.SetupSendAsync(json);
            var service = new Mock <PlayerApi>(http.HttpClient, token)
            {
                CallBase = true
            };

            // act
            await service.Object.GetCurrentPlaybackInfo(token);

            // assert
            service.Verify(s => s.GetModel <CurrentPlaybackContext>(It.IsAny <string>(), token));
        }
Esempio n. 6
0
        public async Task GetDevices_AccessToken_PutInvokedWithAccessToken()
        {
            // arrange
            const string token = "abc123";
            string       json  = JsonConvert.SerializeObject(new { devices = new Device[] { new Device() } });
            var          http  = new MockHttpClient();

            http.SetupSendAsync(json);
            var service = new Mock <PlayerApi>(http.HttpClient, token)
            {
                CallBase = true
            };

            // act
            await service.Object.GetDevices <dynamic>(token);

            // assert
            service.Verify(s => s.GetModelFromProperty <dynamic>(It.IsAny <string>(), It.IsAny <string>(), token));
        }
Esempio n. 7
0
        public async Task Play_AccessToken_PutInvokedWithAccessToken()
        {
            // arrange
            const string token = "abc123";

            var http = new MockHttpClient();

            http.SetupSendAsync();
            var service = new Mock <PlayerApi>(http.HttpClient, token)
            {
                CallBase = true
            };

            // act
            await service.Object.Play(token);

            // assert
            service.Verify(s => s.Put(It.IsAny <string>(), It.IsAny <object>(), token));
        }
Esempio n. 8
0
        public async Task PlayTracks_AccessToken_PutInvokedWithAccessToken()
        {
            // arrange
            const string token    = "abc123";
            const string trackUri = "spotify:track:7ouMYWpwJ422jRcDASZB7P";

            var http = new MockHttpClient();

            http.SetupSendAsync();
            var service = new Mock <PlayerApi>(http.HttpClient, token)
            {
                CallBase = true
            };

            // act
            await service.Object.PlayTracks(trackUri, token);

            // assert
            service.Verify(s => s.Put(It.IsAny <string>(), It.IsAny <object>(), token));
        }