Esempio n. 1
0
        public void GetSpotifyRecentlyPlayedWithAfterParam_CorrectResponseReturned()
        {
            var now = DateTime.UtcNow.AddDays(-1);

            sut = MakeSut();
            var tokenAsJson = sut.GetSpotifyAuthenticationToken();

            tokenAsJson.Value.Should().NotBeNull();
            var spotifyAuthToken = JsonConvert.DeserializeObject <SpotifyAuthenticationToken>((string)tokenAsJson.Value);

            spotifyAuthToken.AccessToken.Should().NotBeNullOrEmpty();
            var listeningHistory = sut.GetSpotifyRecentlyPlayed(spotifyAuthToken.AccessToken, now);

            listeningHistory.Value.Should().NotBeNull();
            var afterTestJSON = JsonConvert.SerializeObject(listeningHistory.Value);
            var afterTest     = JsonConvert.DeserializeObject <CursorPaging <PlayHistoryItem> >(afterTestJSON);

            afterTest.Items.Should().HaveCount(1);
            afterTest.Items.Should().NotBeNull().And.NotBeEmpty();

            listeningHistory = sut.GetSpotifyRecentlyPlayed(spotifyAuthToken.AccessToken);
            listeningHistory.Value.Should().NotBeNull();
            var listeningHistoryExtracted = JsonConvert.SerializeObject(listeningHistory.Value);
            var actualListeningHistory    = JsonConvert.DeserializeObject <CursorPaging <PlayHistoryItem> >(listeningHistoryExtracted);

            actualListeningHistory.Items.Should().HaveCount(3);
            actualListeningHistory.Items.Should().NotBeNull();
        }
Esempio n. 2
0
        public void GetFitBitActivityHistoryWithAllParams_ActivityHistoryReturned()
        {
            sut = MakeSut();
            var tokenAsJson = sut.GetFitBitAuthenticationToken();

            tokenAsJson.Value.Should().NotBeNull();
            var fitBitAuthToken = JsonConvert.DeserializeObject <FitBitAuthenticationToken>((string)tokenAsJson.Value);

            fitBitAuthToken.AccessToken.Should().NotBeNullOrEmpty();

            var startDate = DateTime.UtcNow.AddDays(-7);
            var endDate   = DateTime.UtcNow.AddDays(1);

            var activityHistory = sut.GetFitBitRecentActivities(fitBitAuthToken.AccessToken, startDate, endDate);

            Fitbit.Api.Portable.Models.ActivityLogsList actualHistory = (Fitbit.Api.Portable.Models.ActivityLogsList)activityHistory.Value;
            actualHistory.Should().NotBeNull();
            actualHistory.Should().BeOfType <Fitbit.Api.Portable.Models.ActivityLogsList>();
            actualHistory.Activities.Should().HaveCount(2);

            var alternativeActivityHistory = sut.GetFitBitRecentActivities(fitBitAuthToken.AccessToken, startDate.AddDays(7), endDate.AddDays(-31));

            Fitbit.Api.Portable.Models.ActivityLogsList alternativeActualHistory = (Fitbit.Api.Portable.Models.ActivityLogsList)alternativeActivityHistory.Value;
            alternativeActualHistory.Should().NotBeNull();
            alternativeActualHistory.Should().BeOfType <Fitbit.Api.Portable.Models.ActivityLogsList>();
            alternativeActualHistory.Activities.Should().HaveCount(0);
        }
Esempio n. 3
0
        public void GetStravaActivityWithAllParams_CorrectActivityHistoryReturned()
        {
            sut = MakeSut();
            var tokenAsJson = sut.GetStravaAuthenticationToken();

            tokenAsJson.Value.Should().NotBeNull();
            var stravaAuthToken = JsonConvert.DeserializeObject <StravaAuthenticationToken>((string)tokenAsJson.Value);

            stravaAuthToken.access_token.Should().NotBeNullOrEmpty();

            var startDate = DateTime.UtcNow.AddDays(-1);
            var endDate   = DateTime.UtcNow.AddDays(1);

            var activityHistory = sut.GetStravaRecentActivities(stravaAuthToken.access_token, startDate, endDate);

            activityHistory.Value.Should().NotBeNull();
            var activityHistoryExtracted = JsonConvert.SerializeObject(activityHistory.Value);
            var actualActivityHistory    = JsonConvert.DeserializeObject <List <StravaActivity> >(activityHistoryExtracted);

            actualActivityHistory.Count.Should().Be(2);

            var alternativeActivityHistory          = sut.GetStravaRecentActivities(stravaAuthToken.access_token, startDate.AddDays(7), endDate.AddDays(-7));
            var alternativeActivityHistoryExtracted = JsonConvert.SerializeObject(alternativeActivityHistory.Value);
            var alternativeActualActivityHistory    = JsonConvert.DeserializeObject <List <StravaActivity> >(alternativeActivityHistoryExtracted);

            alternativeActualActivityHistory.Count.Should().Be(0);
        }
Esempio n. 4
0
        public void GetLastFMRecentlyPlayedWithoutAfterParam_CorrectResponseReturned()
        {
            sut = MakeSut();
            var listeningHistory = sut.GetLastFMRecentlyPlayed("SomeUser");

            IF.Lastfm.Core.Api.Helpers.PageResponse <IF.Lastfm.Core.Objects.LastTrack> actualHistory = (IF.Lastfm.Core.Api.Helpers.PageResponse <IF.Lastfm.Core.Objects.LastTrack>)listeningHistory.Value;
            actualHistory.Should().NotBeNull();
            actualHistory.Should().BeOfType <IF.Lastfm.Core.Api.Helpers.PageResponse <IF.Lastfm.Core.Objects.LastTrack> >();
            actualHistory.Content.Should().HaveCount(2);
        }
Esempio n. 5
0
        public void GetFitBitAuthenticationToken_AuthenticationTokenReturned()
        {
            sut = MakeSut();
            var tokenAsJson = sut.GetFitBitAuthenticationToken();

            tokenAsJson.Value.Should().NotBeNull();
            var fitBitAuthToken = JsonConvert.DeserializeObject <FitBitAuthenticationToken>((string)tokenAsJson.Value);

            fitBitAuthToken.AccessToken.Should().NotBeNullOrEmpty();
        }
Esempio n. 6
0
        public void GetFitBitActivityHistory_ActivityHistoryReturned()
        {
            sut = MakeSut();
            var tokenAsJson = sut.GetFitBitAuthenticationToken();

            tokenAsJson.Value.Should().NotBeNull();
            var fitBitAuthToken = JsonConvert.DeserializeObject <FitBitAuthenticationToken>((string)tokenAsJson.Value);

            fitBitAuthToken.AccessToken.Should().NotBeNullOrEmpty();

            var activityHistory = sut.GetFitBitRecentActivities(fitBitAuthToken.AccessToken);

            Fitbit.Api.Portable.Models.ActivityLogsList actualHistory = (Fitbit.Api.Portable.Models.ActivityLogsList)activityHistory.Value;
            actualHistory.Should().NotBeNull();
            actualHistory.Should().BeOfType <Fitbit.Api.Portable.Models.ActivityLogsList>();
            actualHistory.Activities.Should().HaveCount(2);
        }
Esempio n. 7
0
        public void GetStravaActivityHistory_ActivityHistoryReturned()
        {
            sut = MakeSut();
            var tokenAsJson = sut.GetStravaAuthenticationToken();

            tokenAsJson.Value.Should().NotBeNull();
            var stravaAuthToken = JsonConvert.DeserializeObject <StravaAuthenticationToken>((string)tokenAsJson.Value);

            stravaAuthToken.access_token.Should().NotBeNullOrEmpty();

            var activityHistory = sut.GetStravaRecentActivities(stravaAuthToken.access_token);

            activityHistory.Value.Should().NotBeNull();
            var activityHistoryExtracted = JsonConvert.SerializeObject(activityHistory.Value);
            var actualActivityHistory    = JsonConvert.DeserializeObject <List <StravaActivity> >(activityHistoryExtracted);

            actualActivityHistory.Count.Should().Be(2);
            actualActivityHistory[0].average_speed.Should().Be(12.35);
        }
Esempio n. 8
0
        public void GetSpotifyRecentlyPlayed_ListeningHistoryReturned()
        {
            sut = MakeSut();
            var tokenAsJson = sut.GetSpotifyAuthenticationToken();

            tokenAsJson.Value.Should().NotBeNull();
            var spotifyAuthToken = JsonConvert.DeserializeObject <SpotifyAuthenticationToken>((string)tokenAsJson.Value);

            spotifyAuthToken.AccessToken.Should().NotBeNullOrEmpty();

            var listeningHistory = sut.GetSpotifyRecentlyPlayed(spotifyAuthToken.AccessToken);

            listeningHistory.Value.Should().NotBeNull();
            var listeningHistoryExtracted = JsonConvert.SerializeObject(listeningHistory.Value);
            var actualListeningHistory    = JsonConvert.DeserializeObject <CursorPaging <PlayHistoryItem> >(listeningHistoryExtracted);

            actualListeningHistory.Items.Should().HaveCount(3);
            actualListeningHistory.Items.Should().NotBeNull();
        }
Esempio n. 9
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();
        }
 /// <inheritdoc/>
 public void SetUp(ExternalAPIGateway externalAPIGateway)
 {
     this.externalAPIGateway  = externalAPIGateway;
     this.inferenceAPIGateway = new InferenceAPIGateway();
 }