public void Setup()
        {
            httpContextHelper = Substitute.For <IHttpContextHelper>();
            httpContextHelper.getAccessToken().Returns("access_token");

            stravaClient = Substitute.For <IStravaClient>();
            IEnumerable <VisualActivity> activities        = TestData.VisualActivitiesList();
            IEnumerable <VisualActivity> newUserActivities = TestData.NewVisualActivitiesList();

            stravaClient.getAllUserActivities("access_token", 123).Returns(activities);
            stravaClient.getAllUserActivities("access_token", 2222).Returns(newUserActivities);
            stravaClient.getUserActivitiesAfter("access_token", Arg.Any <StravaUser>(), Arg.Any <DateTime>()).Returns(newUserActivities);

            map = new Map();

            var userActivity = new StravaUser {
                VisualActivities = (List <VisualActivity>)activities, UserId = 2, LastDownload = DateTime.Now
            };

            userActivities = new List <StravaUser>
            {
                new StravaUser {
                    VisualActivities = (List <VisualActivity>)activities, UserId = 1, LastDownload = DateTime.Now
                },
                userActivity,
                new StravaUser {
                    VisualActivities = (List <VisualActivity>)activities, UserId = 3, LastDownload = DateTime.Now
                },
            }.AsQueryable();
            userActivityRepository = Substitute.For <IStravaVisualizerRepository>();
            userActivityRepository.GetUserActivities().Returns(userActivities);
            userActivityRepository.GetStravaUserById(123).Returns(userActivity);
            userActivityRepository.GetStravaUserById(2222).Returns(new StravaUser());
        }
        private StravaUser getUpdatedUserActivities(string accessToken, int id)
        {
            var user = _context.GetStravaUserById(id);

            if (user == null || user.VisualActivities == null || user.VisualActivities.Count == 0)
            {
                var activities = _stravaClient.getAllUserActivities(accessToken, id);
                user = new StravaUser()
                {
                    VisualActivities = activities.ToList(),
                    UserId           = id,
                    LastDownload     = DateTime.Now.Date
                };
                _context.Add(user);
                _context.SaveChanges();
            }
            else
            {
                var latestActivities = _stravaClient.getUserActivitiesAfter(accessToken, user, user.LastDownload);

                if (latestActivities != null)
                {
                    foreach (var activity in latestActivities)
                    {
                        if (!_context.Contains(activity))
                        {
                            _context.Add(activity);
                            user.VisualActivities.Add(activity);
                        }
                    }
                    _context.SaveChanges();
                }
            }
            return(user);
        }