public void Scrobble_NotPlayedForLongEnough_ThrowsException()
 {
     // Arrange
     var scrobbler = new ScrobblerUnderTest("test", "test");
     
     // Act
     scrobbler.Scrobble(new Track {Duration = new TimeSpan(Scrobbler.MinimumScrobbleTrackLengthInSeconds*2), WhenStartedPlaying = DateTime.Now});
 }
 public void Scrobble_DurationTooShort_ThrowsException()
 {
     // Arrange
     var scrobbler = new ScrobblerUnderTest("test", "test");
     
     // Act
     scrobbler.Scrobble(new Track {Duration = new TimeSpan(Scrobbler.MinimumScrobbleTrackLengthInSeconds/2), WhenStartedPlaying = DateTime.Now.AddMinutes(-4)});
 }
        public void Scrobble_NotPlayedForLongEnough_ThrowsException()
        {
            // Arrange
            var scrobbler = new ScrobblerUnderTest("test", "test");

            // Act
            scrobbler.Scrobble(new Track {
                Duration = new TimeSpan(Scrobbler.MinimumScrobbleTrackLengthInSeconds * 2), WhenStartedPlaying = DateTime.Now
            });
        }
        public void Scrobble_DurationTooShort_ThrowsException()
        {
            // Arrange
            var scrobbler = new ScrobblerUnderTest("test", "test");

            // Act
            scrobbler.Scrobble(new Track {
                Duration = new TimeSpan(Scrobbler.MinimumScrobbleTrackLengthInSeconds / 2), WhenStartedPlaying = DateTime.Now.AddMinutes(-4)
            });
        }
        public void Scrobble_TrackDurationAndWhenStartedOk_CallsApiScrobble()
        {
            // Arrange
            var scrobbler = new ScrobblerUnderTest("test", "test");
            
            // Act
            scrobbler.Scrobble(new Track {Duration = new TimeSpan(Scrobbler.MinimumScrobbleTrackLengthInSeconds*2), WhenStartedPlaying = DateTime.Now.AddMinutes(-4)});

            // Assert
            scrobbler.TrackApiMock.Verify(a=>a.Scrobble(It.IsAny<Track>(), It.IsAny<Authentication>()));
        }
        public void Scrobble_TrackDurationAndWhenStartedOk_CallsApiScrobble()
        {
            // Arrange
            var scrobbler = new ScrobblerUnderTest("test", "test");

            // Act
            scrobbler.Scrobble(new Track {
                Duration = new TimeSpan(Scrobbler.MinimumScrobbleTrackLengthInSeconds * 2), WhenStartedPlaying = DateTime.Now.AddMinutes(-4)
            });

            // Assert
            scrobbler.TrackApiMock.Verify(a => a.Scrobble(It.IsAny <Track>(), It.IsAny <Authentication>()));
        }
        public void GetAuthenticationToken_InvalidToken_CallsApiGetToken()
        {
            // Arrange
            var scrobbler = new ScrobblerUnderTest("testApiKey", "testApiSecret");

            scrobbler.AuthenticationTokenUnderTest = new AuthenticationTokenUnderTest("testToken1", DateTime.Now.AddMinutes(-AuthenticationToken.ValidForMinutes * 2));

            // Act
            scrobbler.GetAuthenticationTokenUnderTest();

            // Assert
            scrobbler.AuthApiMock.Verify(api => api.GetToken(It.IsAny <Authentication>()), Times.Once());
        }
        public void GetAuthenticationToken_NullToken_CallsApiGetToken()
        {
            // Arrange
            var scrobbler = new ScrobblerUnderTest("testApiKey", "testApiSecret");

            scrobbler.AuthenticationTokenUnderTest = null;

            // Act
            scrobbler.GetAuthenticationTokenUnderTest();

            // Assert
            scrobbler.AuthApiMock.Verify(api => api.GetToken(It.IsAny <Authentication>()), Times.Once());
        }
        public void GetAuthenticationToken_ValidToken_DoesNotCallApiGetToken()
        {
            // Arrange
            var scrobbler = new ScrobblerUnderTest("testApiKey", "testApiSecret");

            scrobbler.AuthenticationTokenUnderTest = new AuthenticationToken("testToken1");

            // Act
            scrobbler.GetAuthenticationTokenUnderTest();

            // Assert
            scrobbler.AuthApiMock.Verify(api => api.GetToken(It.IsAny <Authentication>()), Times.Never());
        }
        public void GetAuthenticationToken_InvalidToken_CallsApiGetToken()
        {
            // Arrange
            var scrobbler = new ScrobblerUnderTest("testApiKey", "testApiSecret");
            scrobbler.AuthenticationTokenUnderTest = new AuthenticationTokenUnderTest("testToken1", DateTime.Now.AddMinutes(-AuthenticationToken.ValidForMinutes * 2));

            // Act
            scrobbler.GetAuthenticationTokenUnderTest();

            // Assert
            scrobbler.AuthApiMock.Verify(api => api.GetToken(It.IsAny<Authentication>()), Times.Once());

        }
        public void GetAuthenticationToken_NullToken_CallsApiGetToken()
        {
            // Arrange
            var scrobbler = new ScrobblerUnderTest("testApiKey", "testApiSecret");
            scrobbler.AuthenticationTokenUnderTest = null;

            // Act
            scrobbler.GetAuthenticationTokenUnderTest();

            // Assert
            scrobbler.AuthApiMock.Verify(api => api.GetToken(It.IsAny<Authentication>()), Times.Once());

        }
        public void GetAuthenticationToken_ValidToken_DoesNotCallApiGetToken()
        {
            // Arrange
            var scrobbler = new ScrobblerUnderTest("testApiKey", "testApiSecret");
            scrobbler.AuthenticationTokenUnderTest = new AuthenticationToken("testToken1");

            // Act
            scrobbler.GetAuthenticationTokenUnderTest();

            // Assert
            scrobbler.AuthApiMock.Verify(api => api.GetToken(It.IsAny<Authentication>()), Times.Never());

        }