Exemplo n.º 1
0
        public void AssertReturnsRunsWithinDistanceRange()
        {
            const int maximum = 7;
            const int minimum = 5;

            var runsQuery =
                new BestRunsQuery
                    {
                        Athlete = _athlete,
                        DistanceMaximum = maximum,
                        DistanceMinimum = minimum,
                        NumberOfRunsToFetch = 10
                    };

            Assert.DoesNotThrow(runsQuery.EnsureQueryValid);

            var runDataAccess = new RunDataAccess();
            var bestRunsQuery = runDataAccess.GetBestRuns(runsQuery);

            Assert.AreEqual(3, bestRunsQuery.Runs.Count);
            foreach (var run in bestRunsQuery.Runs)
            {
                Assert.IsTrue(run.Distance >= minimum && run.Distance <= maximum);
            }
        }
Exemplo n.º 2
0
        public void AssertInsertPlannedRuns()
        {
            var builder = new AthleteBuilder();

            var athlete = builder.Build();

            var selectedDays = WeekdaySelectionEnumeration.FifthDayOfWeek | WeekdaySelectionEnumeration.SeventhDayOfWeek;

            var trainingPlan = new TrainingPlan
                                   {
                                       Workload = 50,
                                       Goal = CreateGoal(),
                                       Athlete = athlete,
                                       Start = new DateTime(2009, 1, 1),
                                       StartDistance = 2000,
                                       PreferredWeekdays = (int)selectedDays
                                   };

            MemoryDataContext.Clear();
            Assert.IsTrue(MemoryDataContext.IsEmpty);
            MemoryDataContext.InsertOnSubmit(athlete);
            MemoryDataContext.InsertOnSubmit(trainingPlan);
            MemoryDataContext.Commit();

            var runDataAccess = new RunDataAccess();

            runDataAccess.CreateRuns(trainingPlan);

            Assert.AreEqual(47, MemoryDataContext.Queryable<Run>().Count());
        }
Exemplo n.º 3
0
        public void WhenActivitiesExistShouldSetDayActivityCount()
        {
            MemoryDataContext.Clear();
            InsertDefaultAthlete();
            Assert.AreEqual(0, MemoryDataContext.Queryable<Run>().Count());

            var e = new RunDataAccess();

            var monthQuery = new MonthQuery
            {
                Athlete = _athlete,
                Month = 1,
                WeekStartsOnMonday = true,
                Year = 2009
            };
            monthQuery.CalculateDateRange();

            InsertPersistentRun(monthQuery.Start);
            InsertPersistentRun(monthQuery.End);
            InsertPersistentRun(monthQuery.End);

            monthQuery = e.GetMonthQuery(monthQuery);

            Assert.AreEqual(1, monthQuery.DayActivities.First().ActivityCount);
            Assert.AreEqual(2, monthQuery.DayActivities.Last().ActivityCount);
        }
Exemplo n.º 4
0
        public void ShouldSaveRun()
        {
            MemoryDataContext.Clear();
            var e = new RunDataAccess ();

            var athlete = new AthleteBuilder().Build();
            MemoryDataContext.Add(athlete);

            var run = new Run { ID = 0, Athlete = athlete};

            e.SaveRun(run);

            Assert.IsTrue(MemoryDataContext.IsCommited(run));
        }
Exemplo n.º 5
0
        public void AssertReturnsRunsForPlan()
        {
            var plan = new TrainingPlanBuilder().WithAthlete();
            for (var i = 0; i < 10; i++)
            {
                var run =
                    new Run {Distance = 1000, TrainingPlanID = plan.ID, Athlete = plan.Athlete};
                MemoryDataContext.InsertOnSubmit(run);
            }
            MemoryDataContext.Commit();
            var runDataAcces = new RunDataAccess();
            var runs = runDataAcces.GetPlannedRuns(plan);

            Assert.AreEqual(10, runs.Count);
        }
Exemplo n.º 6
0
        public string DownloadMyRuns(Athlete athlete)
        {
            var fileSystem = ResolveFileSystem();
            var csvData = ResolveCsvData();
            var rundataAccess = new RunDataAccess();

            var runs = rundataAccess.GetRuns(athlete);
            var fileName = athlete.User.UserName + ".csv";

            var filepath =
                Path.Combine(
                    RunTrackEnvironment.MappedFullyQualifiedDownloadDirectory,
                    fileName);

            var content = csvData.AsFileContent(runs);
            fileSystem.WriteContent(filepath, content);

            var downloadPathForClient = RunTrackEnvironment.FullyQualifiedDownloadDirectoryUrl + "/" + fileName;

            return downloadPathForClient;
        }
Exemplo n.º 7
0
        public void AssertReturnsRunsWithinDateRange()
        {
            const int maximum = 100;
            const int minimum = 0;

            var runsQuery =
                new BestRunsQuery
                    {
                        Athlete = _athlete,
                        After = new DateTime(2008, 1, 1),
                        Before = new DateTime(2008, 1, 30),
                        DistanceMaximum = maximum,
                        DistanceMinimum = minimum,
                        NumberOfRunsToFetch = 10
                    };

            Assert.DoesNotThrow(runsQuery.EnsureQueryValid);

            var runDataAccess = new RunDataAccess();
            var bestRunsQuery = runDataAccess.GetBestRuns(runsQuery);

            Assert.AreEqual(4, bestRunsQuery.Runs.Count);
        }
Exemplo n.º 8
0
        public void ShouldReturn42EmptyDayActivities()
        {
            MemoryDataContext.Clear();
            InsertDefaultAthlete();
            Assert.AreEqual(0, MemoryDataContext.Queryable<Run>().Count());
            var e = new RunDataAccess();

            var monthQuery = new MonthQuery
                        {
                            Athlete = _athlete,
                            Month = 11,
                            WeekStartsOnMonday = true,
                            Year = 2009
                        };

            monthQuery = e.GetMonthQuery(monthQuery);

            foreach (var dayActivity in monthQuery.DayActivities)
            {
                Assert.AreEqual(0, dayActivity.ActivityCount);
            }
            Assert.AreEqual(42, monthQuery.DayActivities.Count);
        }
Exemplo n.º 9
0
        public TrainingPlan SaveTrainingPlan(TrainingPlan trainingPlan)
        {
            DataContext.RollbackAndAttach(trainingPlan.Athlete);
            trainingPlan.Goal.Athlete = trainingPlan.Athlete;
            if (trainingPlan.ID > 0)
            {
                DataContext.UpdateAndAttach(trainingPlan.Goal);
                DataContext.UpdateAndAttach(trainingPlan);
            }
            else
            {
                DataContext.InsertOnSubmit(trainingPlan);
            }
            DataContext.Commit();

            var runDataAccess = new RunDataAccess(DataContext);
            runDataAccess.CreateRuns(trainingPlan);

            return trainingPlan;
        }
Exemplo n.º 10
0
 private void InsertPersistentRun(DateTime dateTime)
 {
     var e = new RunDataAccess();
     var run = new Run { ID = 0, Athlete = _athlete, Start = dateTime};
     e.SaveRun(run);
 }