Exemple #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);
            }
        }
Exemple #2
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);
        }
Exemple #3
0
        public BestRunsQuery GetBestRuns(BestRunsQuery query)
        {
            var runs = GetRuns(query.Athlete);

            if (query.Before.HasValue)
            {
                runs = runs.Where(x => x.Start < query.Before.Value);
            }
            if (query.After.HasValue)
            {
                runs = runs.Where(x => x.Start > query.After.Value);
            }
            runs = runs.Where(x => x.Time > 0);
            runs = query.IsExactDistance ?
                runs.Where(x => x.Distance == query.DistanceMinimum) :
                runs.Where(x => x.Distance >= query.DistanceMinimum && x.Distance <= query.DistanceMaximum);

            query.Runs = runs.
                OrderBy(x=>x.Time).
                Take(query.NumberOfRunsToFetch).
                ToList();
            return query;
        }