public void GetSpotifyListeningHistoryWithInvalidAuthToken_ExceptionThrown()
        {
            sut = MakeSut();
            var listeningHistory = sut.GetSpotifyRecentlyPlayed(new SpotifyAuthenticationToken());

            listeningHistory.Result.Value.Should().NotBeNull();
            listeningHistory.Result.Value.Should().NotBe(string.Empty);
        }
        public void GetFitBitActivityHistoryWithValidAuthToken_ActivityHistoryRetrieved()
        {
            sut = MakeSut();
            var runningHistoryTask = sut.GetFitBitActivityHistory(fitBitAuthToken);

            runningHistoryTask.Result.Value.Should().NotBeNull();
            runningHistoryTask.Result.Value.Should().NotBe(string.Empty);
            ActivityLogsList actualRunningHistory = (ActivityLogsList)runningHistoryTask.Result.Value;

            actualRunningHistory.Should().BeOfType <ActivityLogsList>();
            actualRunningHistory.Activities.Should().HaveCount(2);
        }
        public void GetStravaActivityHistoryWithValidAuthToken_ActivityHistoryRetrieved()
        {
            sut = MakeSut();
            var runningHistoryTask = sut.GetStravaActivityHistory(stravaAuthToken);

            runningHistoryTask.Result.Value.Should().NotBeNull();
            runningHistoryTask.Result.Value.Should().NotBe(string.Empty);
            var runningHistoryJson   = JsonConvert.SerializeObject(runningHistoryTask.Result.Value);
            var actualRunningHistory = JsonConvert.DeserializeObject <List <StravaActivity> >(runningHistoryJson);

            actualRunningHistory.Count.Should().Be(2);
            actualRunningHistory[0].Should().BeOfType <StravaActivity>();
        }
        public void GetSpotifyListeningHistory_ListeningHistoryRetrieved()
        {
            sut = MakeSut();
            var listeningHistory = sut.GetSpotifyRecentlyPlayed(spotifyAuthToken);

            listeningHistory.Result.Value.Should().NotBeNull();
            listeningHistory.Result.Value.Should().NotBe(string.Empty);
            var listeningHistoryJson   = JsonConvert.SerializeObject(listeningHistory.Result.Value);
            var actualListeningHistory = JsonConvert.DeserializeObject <CursorPaging <PlayHistoryItem> >(listeningHistoryJson);

            actualListeningHistory.Items.Should().HaveCount(3);
            actualListeningHistory.Items[0].Should().BeOfType <PlayHistoryItem>();
        }
        public void GetLastFMListeningHistoryWithAfterParam_CorrectListeningHistoryReturned()
        {
            sut = MakeSut();
            var after = DateTime.UtcNow.AddDays(-1);
            var listeningHistoryTask = sut.GetLastFMRecentlyPlayed("RD", after);

            listeningHistoryTask.Result.Value.Should().NotBeNull();
            listeningHistoryTask.Result.Value.Should().NotBe(string.Empty);
            PageResponse <LastTrack> actualPageResponse = (PageResponse <LastTrack>)listeningHistoryTask.Result.Value;

            actualPageResponse.Content.Should().NotBeEmpty();
            actualPageResponse.Content.Should().HaveCount(1);
            actualPageResponse.Content[0].Should().BeOfType <LastTrack>();
        }
        public void GetLastFMListeniningHistory_ListeningHistoryReturned()
        {
            sut = MakeSut();
            var listeningHistoryTask = sut.GetLastFMRecentlyPlayed("RD");

            listeningHistoryTask.Result.Value.Should().NotBeNull();
            listeningHistoryTask.Result.Value.Should().NotBe(string.Empty);
            PageResponse <LastTrack> actualPageResponse = (PageResponse <LastTrack>)listeningHistoryTask.Result.Value;

            actualPageResponse.Content.Should().NotBeEmpty();
            actualPageResponse.Content.Should().HaveCount(2);
            actualPageResponse.Content[0].Duration.Should().Be(new TimeSpan(0, 2, 30));
            actualPageResponse.Content[0].Should().BeOfType <LastTrack>();
        }
        public void GetSpotifyListeningHistoryWithAfterParam_ListeningHistoryRetrieved()
        {
            sut = MakeSut();
            var after            = DateTime.UtcNow.AddDays(-1);
            var afterAsUnix      = ((DateTimeOffset)after).ToUnixTimeMilliseconds();
            var listeningHistory = sut.GetSpotifyRecentlyPlayed(spotifyAuthToken, afterAsUnix);

            listeningHistory.Result.Value.Should().NotBeNull();
            listeningHistory.Result.Value.Should().NotBe(string.Empty);
            var listeningHistoryJson   = JsonConvert.SerializeObject(listeningHistory.Result.Value);
            var actualListeningHistory = JsonConvert.DeserializeObject <CursorPaging <PlayHistoryItem> >(listeningHistoryJson);

            actualListeningHistory.Items.Should().HaveCount(1);
            actualListeningHistory.Items[0].Should().BeOfType <PlayHistoryItem>();
        }
Ejemplo n.º 8
0
        public void SetUpTests()
        {
            HttpClient httpClient;
            var        databaseRoot = new InMemoryDatabaseRoot();

            contextOptions = new DbContextOptionsBuilder <DataRetrievalContext>()
                             .UseInMemoryDatabase(DatabaseName, databaseRoot)
                             .Options;

            var webAppFactory = new InMemoryFactory <FakeResponseServer.Startup>(DatabaseName, databaseRoot);

            httpClient = webAppFactory.CreateClient(FakeServerAddress);
            var dataSource = new FakeDataRetrievalSource(new FakeResponseServer.Controllers.ExternalAPICaller(httpClient), FakeServerAddress);

            sut = new ExternalAPIGateway(dataSource);

            var externalAPICaller = new FakeResponseServer.Controllers.ExternalAPICaller(httpClient);

            var now_UTC   = DateTime.UtcNow;
            var now_local = DateTime.Now;
            var offset    = -2;

            foreach (var item in PlayHistoryItems)
            {
                item.PlayedAt = now_UTC.AddDays(offset);
                offset++;
            }

            foreach (var item in ActivityHistory)
            {
                item.start_date       = now_UTC;
                item.start_date_local = now_local;
            }

            foreach (var item in FitBitActivityItems)
            {
                item.StartTime         = now_UTC;
                item.OriginalStartTime = now_UTC;
                item.LastModified      = now_UTC;
            }

            offset = -1;
            foreach (var item in LastFMTrackItems)
            {
                item.TimePlayed = now_UTC.AddDays(offset);
                offset++;
            }

            using var context = new DataRetrievalContext(contextOptions);
            context.PlayHistoryItems.RemoveRange(context.PlayHistoryItems);
            context.PlayHistoryItems.AddRange(PlayHistoryItems);
            context.ActivityHistoryItems.RemoveRange(context.ActivityHistoryItems);
            context.ActivityHistoryItems.AddRange(ActivityHistory);
            context.FitBitActivityItems.RemoveRange(context.FitBitActivityItems);
            context.FitBitActivityItems.AddRange(FitBitActivityItems);
            context.LastTracks.RemoveRange(context.LastTracks);
            context.LastTracks.AddRange(LastFMTrackItems);
            context.SaveChanges();

            fakeDataRetrievalSource = new FakeDataRetrievalSource(externalAPICaller, FakeServerAddress);
            sut = MakeSut();
        }
        public void SetUpTests()
        {
            var now       = DateTime.UtcNow;
            var now_local = DateTime.Now;
            var offset    = -2;

            foreach (var item in PlayHistoryItems)
            {
                item.PlayedAt = now.AddDays(offset);
                offset++;
            }

            foreach (var item in ActivityItems)
            {
                item.start_date       = now;
                item.start_date_local = now_local;
            }

            foreach (var item in FitBitActivityItems)
            {
                item.StartTime         = now;
                item.OriginalStartTime = now;
                item.LastModified      = now;
            }

            offset = -1;
            foreach (var item in LastFMTrackItems)
            {
                item.TimePlayed = now.AddDays(offset);
                offset++;
            }

            RegisterMusicHistory(PlayHistoryItems);

            RegisterActivityHistory(ActivityItems);

            RegisterFitBitHistory(FitBitActivityItems);

            RegisterLastFMTracks(LastFMTrackItems);

            sut = MakeSut();

            // Get spotify auth token.
            var spotifyAuthTask = sut.GetSpotifyAuthenticationToken();

            spotifyAuthTask.Result.Should().NotBeNull();
            spotifyAuthTask.Result.Value.Should().NotBe(string.Empty);
            var temp = JsonConvert.SerializeObject(spotifyAuthTask.Result.Value);

            spotifyAuthToken = JsonConvert.DeserializeObject <SpotifyAuthenticationToken>(temp);
            spotifyAuthToken.AccessToken.Should().NotBeNullOrEmpty();

            // Get strava auth token.
            var stravaAuthTask = sut.GetStravaAuthenticationToken();

            stravaAuthTask.Result.Should().NotBeNull();
            stravaAuthTask.Result.Value.Should().NotBeNull();
            temp            = JsonConvert.SerializeObject(stravaAuthTask.Result.Value);
            stravaAuthToken = JsonConvert.DeserializeObject <StravaAuthenticationToken>(temp);
            stravaAuthToken.access_token.Should().NotBeNullOrEmpty();

            // Get FitBit auth token.
            var fitBitAuthTask = sut.GetFitBitAuthenticationToken();

            fitBitAuthTask.Result.Should().NotBeNull();
            fitBitAuthTask.Result.Value.Should().NotBeNull();
            temp            = JsonConvert.SerializeObject(fitBitAuthTask.Result.Value);
            fitBitAuthToken = JsonConvert.DeserializeObject <FitBitAuthenticationToken>(temp);
            fitBitAuthToken.AccessToken.Should().NotBeNullOrEmpty();
        }