Пример #1
0
        public void ShowResults(int year, int month)
        {
            TrainingManager trainingManager = new TrainingManager(new UnitOfWork(new TrainingContext(_databaseString)));
            Report          report          = trainingManager.GenerateMonthlyTrainingsReport(year, month);

            dataGridShowResults.ItemsSource = report.TimeLine;
            dataGridShowFastest.ItemsSource = new List <object>()
            {
                report.MaxSpeedSessionCycling, report.MaxSpeedSessionRunning
            };
            dataGridShowLongest.ItemsSource = new List <object>()
            {
                report.MaxDistanceSessionCycling, report.MaxDistanceSessionRunning
            };
            dataGridShowWattest.ItemsSource = new List <CyclingSession>()
            {
                report.MaxWattSessionCycling
            };
            startDateReport.Text = $"{report.StartDate.Year}/{report.StartDate.Month:00}/{report.StartDate.Day:00}";
            endDateReport.Text   = $"{report.EndDate.Year}/{report.EndDate.Month:00}/{report.EndDate.Day:00}";

            AmountOfRunSessions.Text     = report.RunningSessions.ToString();
            AmountOfCyclingSessions.Text = report.CyclingSessions.ToString();
            AmountOfTotalSessions.Text   = report.TotalSessions.ToString();

            TotalRunTime.Text      = report.TotalRunningTrainingTime.ToString();
            TotalCyclingTime.Text  = report.TotalCyclingTrainingTime.ToString();
            TotalTrainingTime.Text = report.TotalTrainingTime.ToString();

            TotalRunDistance.Text      = report.TotalRunningDistance.ToString() + " m";
            TotalCyclingDistance.Text  = report.TotalCyclingDistance.ToString() + " km";
            TotalTrainingDistance.Text = (report.TotalRunningDistance / 1000 + report.TotalCyclingDistance).ToString() + " km";
        }
Пример #2
0
        private void DialogGenerateClickEevent(object sender, RoutedEventArgs e)
        {
            DateTime inputDate = new DateTime();

            try
            {
                inputDate = InputDate.SelectedDate.Value;
            }
            catch (Exception)
            {
                MessageBox.Show("You must fill in the date");
                return;
            }

            if (inputDate > DateTime.Now)
            {
                MessageBox.Show("You can't select a date in the future");
                return;
            }

            TrainingManager manager = new TrainingManager(new UnitOfWork(new TrainingContext("Production")));
            Report          rapport = manager.GenerateMonthlyTrainingsReport(inputDate.Year, inputDate.Month);


            if (rapport.TotalTrainingTime.ToString(@"h\h") != "0h")
            {
                CountTime.Text = rapport.TotalTrainingTime.ToString(@"h\h") + " " + rapport.TotalTrainingTime.ToString(@"m\m");
            }
            else
            {
                CountTime.Text = rapport.TotalCyclingTrainingTime.ToString(@"m\m");
            }

            CountRunning.Text  = (rapport.CyclingSessions + rapport.RunningSessions).ToString();
            CountDistance.Text = (rapport.TotalCyclingDistance + (rapport.TotalRunningDistance / 1000)) + "km";

            dataTable.Clear();

            RunningSession maxRunDistance = rapport.MaxDistanceSessionRunning;

            addDataLine("Distance", "Running", maxRunDistance.TrainingType.ToString(), maxRunDistance.Distance + " m", maxRunDistance.Time, Math.Round(maxRunDistance.AverageSpeed, 2) + " km/h", "", "", maxRunDistance.When, maxRunDistance.Comments);

            RunningSession maxRunSpeed = rapport.MaxSpeedSessionRunning;

            addDataLine("Speed", "Running", maxRunSpeed.TrainingType.ToString(), maxRunSpeed.Distance + " m", maxRunSpeed.Time, Math.Round(maxRunSpeed.AverageSpeed, 2) + " km/h", "", "", maxRunSpeed.When, maxRunSpeed.Comments);

            CyclingSession maxDistance = rapport.MaxDistanceSessionCycling;

            addDataLine("Distance", "Cycling", maxDistance.TrainingType.ToString(), maxDistance.Distance + " km", maxDistance.Time, Math.Round(Convert.ToDecimal(maxDistance.AverageSpeed), 2) + " km/h", maxDistance.AverageWatt.ToString(), maxDistance.BikeType.ToString(), maxDistance.When, maxDistance.Comments);

            CyclingSession maxSpeed = rapport.MaxSpeedSessionCycling;

            addDataLine("Speed", "Cycling", maxSpeed.TrainingType.ToString(), maxSpeed.Distance + " km", maxSpeed.Time, Math.Round(Convert.ToDecimal(maxSpeed.AverageSpeed), 2) + " km/h", maxSpeed.AverageWatt.ToString(), maxSpeed.BikeType.ToString(), maxSpeed.When, maxSpeed.Comments);

            CyclingSession maxWatt = rapport.MaxWattSessionCycling;

            addDataLine("Watt", "Cycling", maxWatt.TrainingType.ToString(), maxWatt.Distance + " km", maxWatt.Time, Math.Round(Convert.ToDecimal(maxWatt.AverageSpeed), 2) + " km/h", maxWatt.AverageWatt.ToString(), maxWatt.BikeType.ToString(), maxWatt.When, maxWatt.Comments);

            Dialog.IsOpen = false;
        }
Пример #3
0
        public void AllReportTests()
        {
            TrainingManager tm = new TrainingManager(new UnitOfWork(new TrainingContextTest(false)));

            tm.AddRunningTraining(new DateTime(2019, 10, 1), 200, new TimeSpan(2, 30, 0), 20, TrainingType.Endurance, "number 1");
            tm.AddRunningTraining(new DateTime(2019, 10, 2), 300, new TimeSpan(2, 30, 0), 20, TrainingType.Endurance, "number 2");
            tm.AddRunningTraining(new DateTime(2019, 10, 3), 150, new TimeSpan(2, 30, 0), 20, TrainingType.Endurance, "number 3");
            tm.AddRunningTraining(new DateTime(2018, 10, 1), 200, new TimeSpan(2, 30, 0), 20, TrainingType.Endurance, "number 4");

            tm.AddCyclingTraining(new DateTime(2019, 10, 4), 200, new TimeSpan(2, 30, 0), 20, 2, TrainingType.Endurance, "number 1", BikeType.IndoorBike);
            tm.AddCyclingTraining(new DateTime(2019, 10, 5), 300, new TimeSpan(2, 30, 0), 20, 2, TrainingType.Endurance, "number 2", BikeType.IndoorBike);
            tm.AddCyclingTraining(new DateTime(2019, 10, 6), 150, new TimeSpan(2, 0, 0), 20, 2, TrainingType.Endurance, "number 3", BikeType.IndoorBike);
            tm.AddCyclingTraining(new DateTime(2018, 10, 2), 200, new TimeSpan(2, 30, 0), 20, 2, TrainingType.Endurance, "number 4", BikeType.IndoorBike);

            int expectedNumberOfTrainingsPerType = 3;
            int expectedNumberOfTrainingsTotal   = 6;
            int expectedDistance = 200;

            Report report = tm.GenerateMonthlyTrainingsReport(2019, 10);

            report.RunningSessions.Should().Be(expectedNumberOfTrainingsPerType);

            report.Runs[0].Distance.Should().Be(expectedDistance);

            report.CyclingSessions.Should().Be(expectedNumberOfTrainingsPerType);

            report.Rides[0].Distance.Should().Be(expectedDistance);

            report.TotalSessions.Should().Be(expectedNumberOfTrainingsTotal);
        }
Пример #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            TrainingManager m = new TrainingManager(new UnitOfWork(new TrainingContext("Production")));

            m.AddCyclingTraining(new DateTime(2020, 4, 21, 16, 00, 00), 40, new TimeSpan(1, 20, 00), 30, null, TrainingType.Endurance, null, BikeType.RacingBike);
            m.AddCyclingTraining(new DateTime(2020, 4, 18, 18, 00, 00), 40, new TimeSpan(1, 42, 00), null, null, TrainingType.Recuperation, null, BikeType.RacingBike);
            m.AddCyclingTraining(new DateTime(2020, 4, 19, 16, 45, 00), null, new TimeSpan(1, 0, 00), null, 219, TrainingType.Interval, "5x5 min 270", BikeType.IndoorBike);
            m.AddRunningTraining(new DateTime(2020, 4, 17, 12, 30, 00), 5000, new TimeSpan(0, 27, 17), null, TrainingType.Endurance, null);
            m.AddRunningTraining(new DateTime(2020, 4, 19, 12, 30, 00), 5000, new TimeSpan(0, 25, 48), null, TrainingType.Endurance, null);
            m.AddRunningTraining(new DateTime(2020, 3, 17, 12, 0, 00), 5000, new TimeSpan(0, 28, 10), null, TrainingType.Interval, "3x700m");
            m.AddRunningTraining(new DateTime(2020, 3, 17, 11, 0, 00), 8000, new TimeSpan(0, 42, 10), null, TrainingType.Endurance, null);


            Report r1 = m.GenerateMonthlyCyclingReport(2020, 4);
            Report r2 = m.GenerateMonthlyRunningReport(2020, 4);

            Console.WriteLine("---------------------------");
            Report r3 = m.GenerateMonthlyTrainingsReport(2020, 4);

            foreach (var s in  r3.TimeLine)
            {
                Console.WriteLine($"{s.Item1.ToString()},{s.Item2}");
            }
        }
Пример #5
0
        public void GenerateMonthlyTrainingsReportTest()
        {
            SetupForReportTests();

            var r = tm.GenerateMonthlyTrainingsReport(2020, 03);

            r.TotalSessions.Should().Be(3);
            r.Rides.Count.Should().Be(1);
            r.Runs.Count.Should().Be(2);
            r.TotalTrainingTime.Should().Be(TimeSpan.FromTicks(new TimeSpan(1, 0, 00).Ticks + new TimeSpan(0, 28, 10).Ticks + new TimeSpan(0, 42, 10).Ticks));
        }
        private void setBestSessions()
        {
            var report = tm.GenerateMonthlyTrainingsReport(1994, 9);

            var longestCycling      = report.MaxDistanceSessionCycling;
            var highestSpeedCycling = report.MaxSpeedSessionCycling;
            var highestWattCycling  = report.MaxWattSessionCycling;
            var longestRun          = report.MaxDistanceSessionRunning;
            var highestSpeedRun     = report.MaxSpeedSessionRunning;

            var list = new []
            {
                new  { Title = "Longest Ride", session = (object)longestCycling },
                new { Title = "Highest Speed Ride", session = (object)highestSpeedCycling },
                new { Title = "Highest Watt Ride", session = (object)highestWattCycling },
                new { Title = "Longest Run", session = (object)longestRun },
                new { Title = "Highest Speed Run", session = (object)highestSpeedRun }
            };

            lvBestSessions.ItemsSource = list;
        }
        public void Report_ShouldHaveCorrectValues()
        {
            var expectedSessies     = 5;
            var expectedRunDistance = 10000;
            var expectedMaxWatt     = 219;

            Report r = TM.GenerateMonthlyTrainingsReport(2020, 4);

            r.TotalSessions.ShouldBe(expectedSessies);
            r.TotalRunningDistance.ShouldBe(expectedRunDistance);
            r.MaxWattSessionCycling.AverageWatt.ShouldBe(expectedMaxWatt);
        }
        public void GenerateMonthlyTrainingReportTest()
        {
            //Arrange = initialisatie objecten en kent waarden van gegevens toe aan methoden
            int year  = 1996;
            int month = 1;
            //DB testCyclingSessions
            TrainingManager t = new TrainingManager(new UnitOfWork(new TrainingContextTest(false)));

            //Cyclingreport
            #region AddCyclingTraining maxDistanceSession
            DateTime now = new DateTime(1996, 1, 23); float distance = 257.20f; TimeSpan time = new TimeSpan(12, 05, 10);
            float    averageSpeed = 30.00f; int averageWatt = 200; TrainingType tt = TrainingType.Endurance; string comment = "Good job"; BikeType bt = BikeType.RacingBike;
            t.AddCyclingTraining(now, distance, time, averageSpeed, averageWatt, tt, comment, bt);
            #endregion
            #region AddCyclingTraining2 maxSpeedSession
            DateTime tommorow = new DateTime(1996, 1, 24); float distance2 = 120.40f; TimeSpan time2 = new TimeSpan(6, 03, 08);
            float    averageSpeed2 = 50.00f; int averageWatt2 = 200; TrainingType tt2 = TrainingType.Endurance; BikeType bt2 = BikeType.MountainBike;
            t.AddCyclingTraining(tommorow, distance2, time2, averageSpeed2, averageWatt2, tt2, comment, bt2);
            #endregion
            #region AddCyclingTraining3 maxWattSession
            DateTime afterTommorow = new DateTime(1996, 1, 25); float distance3 = 110.40f; TimeSpan time3 = new TimeSpan(6, 03, 08);
            float    averageSpeed3 = 30.00f; int averageWatt3 = 400; TrainingType tt3 = TrainingType.Endurance; BikeType bt3 = BikeType.MountainBike;
            t.AddCyclingTraining(afterTommorow, distance3, time3, averageSpeed3, averageWatt3, tt3, comment, bt3);
            #endregion
            //RunningReport
            #region runningTraining maxDistanceSessionRunning
            DateTime now4 = new DateTime(1996, 1, 26);
            int      distance4 = 500;
            TimeSpan time4 = new TimeSpan(0, 15, 20); float averageSpeed4 = 15.00f;
            t.AddRunningTraining(now4, distance4, time4, averageSpeed4, TrainingType.Interval, "good job!");
            #endregion
            #region runningTraining maxSpeedSessionRunning
            DateTime now5 = new DateTime(1996, 1, 26, 12, 20, 30);
            int      distance5 = 200;
            TimeSpan time5 = new TimeSpan(0, 20, 20); float averageSpeed5 = 25.00f;
            t.AddRunningTraining(now5, distance5, time5, averageSpeed5, TrainingType.Recuperation, "awesome new SpeedRecord");
            #endregion
            //Act = roept testen method op met ingestgelde parameters
            Report rapport = t.GenerateMonthlyTrainingsReport(year, month);
            //Assert = verifieert actie van geteste methoden
            rapport.TimeLine.Count.Should().Be(5);
            rapport.Rides.Count.Should().Be(3);
            rapport.Runs.Count.Should().Be(2);
        }
Пример #9
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            TrainingManager m = new TrainingManager(new UnitOfWork(new TrainingContext("Production")));

            if (MonthRadioButton.IsChecked == true)
            {
                if (RunningRadioButton.IsChecked == true)
                {
                    Report report = m.GenerateMonthlyRunningReport(2020, (cmbMonth.SelectedIndex) + 1);
                    dgTraining.ItemsSource      = report.Runs;
                    txtBestDistance.Text        = report.MaxDistanceSessionRunning.ToString();
                    txtHighestAverageSpeed.Text = report.MaxSpeedSessionRunning.ToString();
                }
                else if (CyclingRadioButton.IsChecked == true)
                {
                    Report report = m.GenerateMonthlyCyclingReport(2020, (cmbMonth.SelectedIndex) + 1);
                    dgTraining.ItemsSource      = report.Rides;
                    txtBestDistance.Text        = report.MaxDistanceSessionCycling.ToString();
                    txtHighestAverageSpeed.Text = report.MaxSpeedSessionCycling.ToString();
                    txtHighestWattage.Text      = report.MaxWattSessionCycling.ToString();
                }

                else
                {
                    dgTraining.ItemsSource = m.GenerateMonthlyTrainingsReport(2020, (cmbMonth.SelectedIndex) + 1).TimeLine;
                }
            }
            else
            {
                if (RunningRadioButton.IsChecked == true)
                {
                    dgTraining.ItemsSource = m.GetPreviousRunningSessions(int.Parse(txtSessionAmount.Text));
                }
                else if (CyclingRadioButton.IsChecked == true)
                {
                    dgTraining.ItemsSource = m.GetPreviousCyclingSessions(int.Parse(txtSessionAmount.Text));
                }
            }
        }
Пример #10
0
        private void inputButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int year = 0;
                if (string.IsNullOrWhiteSpace(yearInput.Text))
                {
                    throw new ArgumentException("Year is not a whole number.");
                }
                if (!int.TryParse(yearInput.Text, out int yearParsed))
                {
                    throw new ArgumentException("Year is not a whole number.");
                }
                else
                {
                    year = yearParsed;
                }
                int month = 0;
                if (string.IsNullOrWhiteSpace(monthInput.Text))
                {
                    throw new ArgumentException("Month is not a whole number.");
                }
                if (!int.TryParse(monthInput.Text, out int monthParsed))
                {
                    throw new ArgumentException("Month is not a whole number.");
                }
                else
                {
                    if (!(monthParsed <= 12))
                    {
                        throw new ArgumentException("Month is bigger than 12.");
                    }
                    month = monthParsed;
                }
                Report r = null;
                if (selectedBoxes == -1)
                {
                    r = tm.GenerateMonthlyTrainingsReport(year, month);
                    if (r.Runs.Count == 0)
                    {
                        throw new Exception("There are no run session for the given month and year.");
                    }
                    if (r.Rides.Count == 0)
                    {
                        throw new Exception("There are no cycle session for the given month and year.");
                    }
                }
                else if (selectedBoxes == 0)
                {
                    r = tm.GenerateMonthlyRunningReport(year, month);
                    if (r.Runs.Count == 0)
                    {
                        throw new Exception("There are no run session for the given month and year.");
                    }
                }
                else if (selectedBoxes == 1)
                {
                    r = tm.GenerateMonthlyCyclingReport(year, month);
                    if (r.Rides.Count == 0)
                    {
                        throw new Exception("There are no cycle session for the given month and year.");
                    }
                }

                sessionsHeader.Text  += $@" {month}/{year}";
                inputPanel.Visibility = Visibility.Collapsed;
                MaxHeight             = 450;
                MaxWidth    = 550;
                this.Height = 450;
                this.Width  = 600;
                if (selectedBoxes == -1 || selectedBoxes == 0)
                {
                    bestRunningSessions.Visibility = Visibility.Visible;
                }
                if (selectedBoxes == -1 || selectedBoxes == 1)
                {
                    bestCyclingSessions.Visibility = Visibility.Visible;
                }
                sessionsPanel.Visibility = Visibility.Visible;
                MinHeight = 450;
                MinWidth  = 600;

                SetSessions(r);
            }
            catch (ArgumentException aex)
            {
                ShowErrorMessage(aex.Message);
            }
            catch (Exception ex)
            {
                ShowErrorMessage(ex.Message);
            }
        }
Пример #11
0
        internal static Report GenerateMonthReport(int month, int year)
        {
            TrainingManager TM = new TrainingManager(new UnitOfWork(new TrainingContext()));

            return(TM.GenerateMonthlyTrainingsReport(year, month));
        }
Пример #12
0
 public Report GetMonlyReport(int jaar, int maant)
 {
     return(_gerry.GenerateMonthlyTrainingsReport(jaar, maant));
 }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            bool?  cycling = cyclingCheckBox.IsChecked;
            bool?  running = runningCheckBox.IsChecked;
            int    year;
            int    month;
            bool   yearW  = int.TryParse(yearTextBox.Text, out year);
            bool   monthW = int.TryParse(monthTextBox.Text, out month);
            Report rapport;

            try
            {
                if (!yearW)
                {
                    throw new ArgumentException("year is not correct or not inserted");
                }
                else if (!monthW)
                {
                    throw new ArgumentException("Month is not correct or not inserted");
                }
                if (cycling == true && running == true)
                {
                    rapport = m.GenerateMonthlyTrainingsReport(year, month);
                    trainingPerMonthDataGrid.ItemsSource = rapport.TimeLine;
                    trainingPerMonthDataGrid.Items.Refresh();
                    //beste toevoegen
                    besteTrainingen.Text = "CyclingSSession \n" +
                                           "----------------\n" +
                                           $"MaxDistance: {rapport.MaxDistanceSessionCycling} \n" +
                                           $"MaxSpeed: {rapport.MaxSpeedSessionCycling}\n" +
                                           $"MaxWatt: {rapport.MaxWattSessionCycling}\n\n" +
                                           "RunningSession \n" +
                                           "----------------\n" +
                                           $"MaxDistance: {rapport.MaxDistanceSessionRunning}\n" +
                                           $"MaxSpeed: {rapport.MaxSpeedSessionRunning}\n";
                }
                else if (cycling == true)
                {
                    rapport = m.GenerateMonthlyCyclingReport(year, month);
                    trainingPerMonthDataGrid.ItemsSource = rapport.Rides;
                    trainingPerMonthDataGrid.Items.Refresh();
                    //beste toevoegen
                    besteTrainingen.Text = "CyclingSSession \n" +
                                           "----------------\n" +
                                           $"MaxDistance: {rapport.MaxDistanceSessionCycling}\n" +
                                           $"MaxSpeed: {rapport.MaxSpeedSessionCycling}\n" +
                                           $"MaxWatt: {rapport.MaxWattSessionCycling} \n";
                }
                else if (running == true)
                {
                    rapport = m.GenerateMonthlyRunningReport(year, month);
                    trainingPerMonthDataGrid.ItemsSource = rapport.Runs;
                    trainingPerMonthDataGrid.Items.Refresh();
                    //beste toevoegen
                    besteTrainingen.Text = "RunningSession \n" +
                                           "----------------\n" +
                                           $"MaxDistance: {rapport.MaxDistanceSessionRunning} m \n" +
                                           $"MaxSpeed: {rapport.MaxSpeedSessionRunning} m/s \n";
                }
                else
                {
                    throw new ArgumentException("Please check at least one checkbox");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Home", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Пример #14
0
        public void TestMonthlyTotalReport()
        {
            //Arrange
            TrainingManager addingManager   = new TrainingManager(new UnitOfWork(new TrainingContextTest()));
            DateTime        fastestRideTime = new DateTime(2010, 4, 12);
            DateTime        ignoredRideTime = new DateTime(2000, 2, 5);
            DateTime        longestRideTime = new DateTime(2010, 4, 10);
            DateTime        wattestRideTime = new DateTime(2005, 8, 6);

            DateTime fastestRunTime     = new DateTime(2010, 4, 11);
            DateTime ignoredSessionTime = new DateTime(2000, 2, 4);
            DateTime longestRunTime     = new DateTime(2010, 4, 15);

            CyclingSession fastestRide = new CyclingSession(fastestRideTime, 20, new TimeSpan(1, 0, 0), null, 30, TrainingType.Endurance, null, BikeType.CityBike);
            CyclingSession secFastRide = new CyclingSession(ignoredRideTime, 20, new TimeSpan(5, 0, 0), null, 35, TrainingType.Endurance, null, BikeType.CityBike);
            CyclingSession longestRide = new CyclingSession(longestRideTime, 25, new TimeSpan(10, 0, 0), null, 25, TrainingType.Endurance, null, BikeType.CityBike);
            CyclingSession wattestRide = new CyclingSession(wattestRideTime, 10, new TimeSpan(1, 0, 0), null, 200, TrainingType.Endurance, null, BikeType.CityBike);

            RunningSession fastestRun = new RunningSession(fastestRunTime, 20000, new TimeSpan(1, 0, 0), null, TrainingType.Endurance, null);
            RunningSession secFastRun = new RunningSession(ignoredSessionTime, 20000, new TimeSpan(5, 0, 0), null, TrainingType.Endurance, null);
            RunningSession longestRun = new RunningSession(longestRunTime, 25000, new TimeSpan(10, 0, 0), null, TrainingType.Endurance, null);

            addingManager.AddCyclingTraining(fastestRide.When, fastestRide.Distance, fastestRide.Time, fastestRide.AverageSpeed, fastestRide.AverageWatt, fastestRide.TrainingType, fastestRide.Comments, fastestRide.BikeType);
            addingManager.AddCyclingTraining(secFastRide.When, secFastRide.Distance, secFastRide.Time, secFastRide.AverageSpeed, secFastRide.AverageWatt, secFastRide.TrainingType, secFastRide.Comments, secFastRide.BikeType);
            addingManager.AddCyclingTraining(longestRide.When, longestRide.Distance, longestRide.Time, longestRide.AverageSpeed, longestRide.AverageWatt, longestRide.TrainingType, longestRide.Comments, longestRide.BikeType);
            addingManager.AddCyclingTraining(wattestRide.When, wattestRide.Distance, wattestRide.Time, wattestRide.AverageSpeed, wattestRide.AverageWatt, wattestRide.TrainingType, wattestRide.Comments, wattestRide.BikeType);

            addingManager.AddRunningTraining(fastestRun.When, fastestRun.Distance, fastestRun.Time, fastestRun.AverageSpeed, fastestRun.TrainingType, fastestRun.Comments);
            addingManager.AddRunningTraining(secFastRun.When, secFastRun.Distance, secFastRun.Time, secFastRun.AverageSpeed, secFastRun.TrainingType, secFastRun.Comments);
            addingManager.AddRunningTraining(longestRun.When, longestRun.Distance, longestRun.Time, longestRun.AverageSpeed, longestRun.TrainingType, longestRun.Comments);

            DateTime secondRideTime = new DateTime(2010, 5, 10);
            DateTime firstRideTime  = new DateTime(2010, 5, 1);
            DateTime thirdRideTime  = new DateTime(2010, 5, 31);
            DateTime laterRideTime  = new DateTime(2010, 6, 1);
            DateTime earlyRideTime  = new DateTime(2010, 4, 30);

            DateTime secondRunTime = new DateTime(2010, 5, 11);
            DateTime firstRunTime  = new DateTime(2010, 5, 2);
            DateTime thirdRunTime  = new DateTime(2010, 5, 30);
            DateTime laterRunTime  = new DateTime(2010, 6, 2);
            DateTime earlyRunTime  = new DateTime(2010, 4, 29);


            CyclingSession secondRide = new CyclingSession(secondRideTime, 5, new TimeSpan(1, 0, 0), null, 10, TrainingType.Endurance, null, BikeType.CityBike);
            CyclingSession firstRide  = new CyclingSession(firstRideTime, 5, new TimeSpan(1, 0, 0), null, 50, TrainingType.Endurance, null, BikeType.CityBike);
            CyclingSession thirdRide  = new CyclingSession(thirdRideTime, 5, new TimeSpan(1, 0, 0), null, 30, TrainingType.Endurance, null, BikeType.CityBike);
            CyclingSession laterRide  = new CyclingSession(laterRideTime, 5, new TimeSpan(1, 0, 0), null, 20, TrainingType.Endurance, null, BikeType.CityBike);
            CyclingSession earlyRide  = new CyclingSession(earlyRideTime, 5, new TimeSpan(1, 0, 0), null, 15, TrainingType.Endurance, null, BikeType.CityBike);

            RunningSession secondRun = new RunningSession(secondRunTime, 5000, new TimeSpan(1, 0, 0), null, TrainingType.Endurance, null);
            RunningSession firstRun  = new RunningSession(firstRunTime, 5000, new TimeSpan(1, 0, 0), null, TrainingType.Endurance, null);
            RunningSession thirdRun  = new RunningSession(thirdRunTime, 5000, new TimeSpan(1, 0, 0), null, TrainingType.Endurance, null);
            RunningSession laterRun  = new RunningSession(laterRunTime, 5000, new TimeSpan(1, 0, 0), null, TrainingType.Endurance, null);
            RunningSession earlyRun  = new RunningSession(earlyRunTime, 5000, new TimeSpan(1, 0, 0), null, TrainingType.Endurance, null);


            addingManager.AddCyclingTraining(secondRide.When, secondRide.Distance, secondRide.Time, secondRide.AverageSpeed, secondRide.AverageWatt, secondRide.TrainingType, secondRide.Comments, secondRide.BikeType);
            addingManager.AddCyclingTraining(firstRide.When, firstRide.Distance, firstRide.Time, firstRide.AverageSpeed, firstRide.AverageWatt, firstRide.TrainingType, firstRide.Comments, firstRide.BikeType);
            addingManager.AddCyclingTraining(thirdRide.When, thirdRide.Distance, thirdRide.Time, thirdRide.AverageSpeed, thirdRide.AverageWatt, thirdRide.TrainingType, thirdRide.Comments, thirdRide.BikeType);
            addingManager.AddCyclingTraining(laterRide.When, laterRide.Distance, laterRide.Time, laterRide.AverageSpeed, laterRide.AverageWatt, laterRide.TrainingType, laterRide.Comments, laterRide.BikeType);
            addingManager.AddCyclingTraining(earlyRide.When, earlyRide.Distance, earlyRide.Time, earlyRide.AverageSpeed, earlyRide.AverageWatt, earlyRide.TrainingType, earlyRide.Comments, earlyRide.BikeType);

            addingManager.AddRunningTraining(secondRun.When, secondRun.Distance, secondRun.Time, secondRun.AverageSpeed, secondRun.TrainingType, secondRun.Comments);
            addingManager.AddRunningTraining(firstRun.When, firstRun.Distance, firstRun.Time, firstRun.AverageSpeed, firstRun.TrainingType, firstRun.Comments);
            addingManager.AddRunningTraining(thirdRun.When, thirdRun.Distance, thirdRun.Time, thirdRun.AverageSpeed, thirdRun.TrainingType, thirdRun.Comments);
            addingManager.AddRunningTraining(laterRun.When, laterRun.Distance, laterRun.Time, laterRun.AverageSpeed, laterRun.TrainingType, laterRun.Comments);
            addingManager.AddRunningTraining(earlyRun.When, earlyRun.Distance, earlyRun.Time, earlyRun.AverageSpeed, earlyRun.TrainingType, earlyRun.Comments);


            //Act
            TrainingManager reportManager = new TrainingManager(new UnitOfWork(new TrainingContextTest(true)));
            int             reportYear    = 2010;
            int             reportMonth   = 5;
            Report          report        = reportManager.GenerateMonthlyTrainingsReport(reportYear, reportMonth);

            //Assert
            Assert.AreEqual(report.StartDate, new DateTime(reportYear, reportMonth, 1), "StartDate dit not match up");
            Assert.AreEqual(report.EndDate, new DateTime(reportYear, reportMonth, DateTime.DaysInMonth(reportYear, reportMonth)), "EndDate did not match up");

            Assert.AreEqual(report.RunningSessions, 3, "Number of RunningSessions was incorrect");
            Assert.AreEqual(report.CyclingSessions, 3, "Number of CyclingSessions was incorrect");
            Assert.AreEqual(report.TotalSessions, 6, "Number of TotalSessions was incorrect");
            Assert.AreEqual(report.Rides[0].When, firstRideTime, "The first element in Rides did not match, probably not sorted by date properly");
            Assert.AreEqual(report.Rides[1].When, secondRideTime, "The second element in Rides did not match");
            Assert.AreEqual(report.Rides[2].When, thirdRideTime, "The third element in Rides did not match");
            Assert.AreEqual(report.Runs[0].When, firstRunTime, "The first element in Runs did not match,probably not sorted by date properly");
            Assert.AreEqual(report.Runs[1].When, secondRunTime, "The second element in Runs did not match");
            Assert.AreEqual(report.Runs[2].When, thirdRunTime, "The third element in Runs did not match");

            Assert.AreEqual(report.MaxDistanceSessionCycling.When, longestRideTime, "Max Distance Ride did not match up");
            Assert.AreEqual(report.MaxSpeedSessionCycling.When, fastestRideTime, "Max Speed Ride did not match up");
            Assert.AreEqual(report.MaxWattSessionCycling.When, wattestRideTime, "Max Watt Ride did not match up");
            Assert.AreEqual(report.TotalCyclingDistance, secondRide.Distance + firstRide.Distance + thirdRide.Distance);
            Assert.AreEqual(report.TotalCyclingTrainingTime, secondRide.Time + firstRide.Time + thirdRide.Time);

            Assert.AreEqual(report.MaxDistanceSessionRunning.When, longestRunTime, "Max Distance Run did not match up");
            Assert.AreEqual(report.MaxSpeedSessionRunning.When, fastestRunTime, "Max Speed Run did not match up");
            Assert.AreEqual(report.TotalRunningDistance, secondRun.Distance + firstRun.Distance + thirdRun.Distance);
            Assert.AreEqual(report.TotalRunningTrainingTime, secondRun.Time + firstRun.Time + thirdRun.Time);

            Assert.AreEqual(report.TotalTrainingTime, report.TotalRunningTrainingTime + report.TotalCyclingTrainingTime, "TotalTrainingTime did not add up");

            Assert.AreEqual(report.TimeLine[0].Item2, report.Rides[0], "Timeline did not match up");
            Assert.AreEqual(report.TimeLine[0].Item1, SessionType.Cycling, "Type of first Item did not match up");
            Assert.AreEqual(report.TimeLine[1].Item2, report.Runs[0], "Timeline did not match up");
            Assert.AreEqual(report.TimeLine[1].Item1, SessionType.Running, "Type of second Item did not match up");
            Assert.AreEqual(report.TimeLine[2].Item2, report.Rides[1], "Timeline did not match up");
            Assert.AreEqual(report.TimeLine[2].Item1, SessionType.Cycling, "Type of third Item did not match up");
            Assert.AreEqual(report.TimeLine[3].Item2, report.Runs[1], "Timeline did not match up");
            Assert.AreEqual(report.TimeLine[3].Item1, SessionType.Running, "Type of fourth Item did not match up");
            Assert.AreEqual(report.TimeLine[4].Item2, report.Runs[2], "Timeline did not match up");
            Assert.AreEqual(report.TimeLine[4].Item1, SessionType.Running, "Type of fifth Item did not match up");
            Assert.AreEqual(report.TimeLine[5].Item2, report.Rides[2], "Timeline did not match up");
            Assert.AreEqual(report.TimeLine[5].Item1, SessionType.Cycling, "Type of sixth Item did not match up");
        }
        private void ShowButton_Click(object sender, RoutedEventArgs e)
        {
            int             month   = Int32.Parse(monthinput.Text);
            int             year    = Int32.Parse(yearinput.Text);
            TrainingManager manager = new TrainingManager(new UnitOfWork(new TrainingContext("Production")));

            if (AllRadio.IsChecked.Equals(true))
            {
                Report v = manager.GenerateMonthlyTrainingsReport(year, month);
                testlabel.Content = "TotalSessions: " + v.TotalSessions.ToString();
                CycleSess.Content = "CycleSessions: " + v.CyclingSessions.ToString();
                RunSess.Content   = "RunSessions: " + v.RunningSessions.ToString();
                TotalTime.Content = "TotalTime: " + v.TotalTrainingTime.ToString();
                RunDis.Content    = "TotalRunningDistance: " + v.TotalRunningDistance.ToString();
                RuntIme.Content   = "TotalRunTime: " + v.TotalRunningTrainingTime.ToString();
                CycleDis.Content  = "TotalCycleDistance: " + v.TotalCyclingDistance.ToString();
                CycleTime.Content = "TotalCycleTime: " + v.TotalCyclingTrainingTime.ToString();
                Dt.Rows.Clear();

                DataRow x = Dt.NewRow();
                x[0] = "MaxDistanceCycling";
                x[1] = v.MaxDistanceSessionCycling.Id;
                x[2] = v.MaxDistanceSessionCycling.When;
                x[3] = v.MaxDistanceSessionCycling.Distance.ToString() + " KM";
                x[4] = v.MaxDistanceSessionCycling.Time;
                x[5] = v.MaxDistanceSessionCycling.AverageSpeed;
                x[6] = v.MaxDistanceSessionCycling.Comments;
                x[7] = v.MaxDistanceSessionCycling.TrainingType;
                x[8] = v.MaxDistanceSessionCycling.AverageWatt;
                x[9] = v.MaxDistanceSessionCycling.BikeType;
                Dt.Rows.Add(x);

                DataRow xt = Dt.NewRow();
                xt[0] = "MaxDistanceRunner";
                xt[1] = v.MaxDistanceSessionRunning.Id;
                xt[2] = v.MaxDistanceSessionRunning.When;
                xt[3] = v.MaxDistanceSessionRunning.Distance.ToString() + " M";
                xt[4] = v.MaxDistanceSessionRunning.Time;
                xt[5] = v.MaxDistanceSessionRunning.AverageSpeed;
                xt[6] = v.MaxDistanceSessionRunning.Comments;
                xt[7] = v.MaxDistanceSessionRunning.TrainingType;
                Dt.Rows.Add(xt);

                DataRow xv = Dt.NewRow();
                xv[0] = "MaxSpeedRunner";
                xv[1] = v.MaxSpeedSessionRunning.Id;
                xv[2] = v.MaxSpeedSessionRunning.When;
                xv[3] = v.MaxSpeedSessionRunning.Distance.ToString() + " M";
                xv[4] = v.MaxSpeedSessionRunning.Time;
                xv[5] = v.MaxSpeedSessionRunning.AverageSpeed;
                xv[6] = v.MaxSpeedSessionRunning.Comments;
                xv[7] = v.MaxSpeedSessionRunning.TrainingType;
                Dt.Rows.Add(xv);

                DataRow xf = Dt.NewRow();
                xf[0] = "MaxSpeedCycling";
                xf[1] = v.MaxSpeedSessionCycling.Id;
                xf[2] = v.MaxSpeedSessionCycling.When;
                xf[3] = v.MaxSpeedSessionCycling.Distance.ToString() + " KM";
                xf[4] = v.MaxSpeedSessionCycling.Time;
                xf[5] = v.MaxSpeedSessionCycling.AverageSpeed;
                xf[6] = v.MaxSpeedSessionCycling.Comments;
                xf[7] = v.MaxSpeedSessionCycling.TrainingType;
                xf[8] = v.MaxSpeedSessionCycling.AverageWatt;
                xf[9] = v.MaxSpeedSessionCycling.BikeType;
                Dt.Rows.Add(xf);

                DataRow xq = Dt.NewRow();
                xq[0] = "MaxWattCycling";
                xq[1] = v.MaxWattSessionCycling.Id;
                xq[2] = v.MaxWattSessionCycling.When;
                xq[3] = v.MaxWattSessionCycling.Distance.ToString() + " KM";
                xq[4] = v.MaxWattSessionCycling.Time;
                if (v.MaxWattSessionCycling.AverageSpeed.Equals(null))
                {
                    v.MaxWattSessionCycling.AverageSpeed = 0;
                }
                xq[5] = v.MaxWattSessionCycling.AverageSpeed;
                xq[6] = v.MaxWattSessionCycling.Comments;
                xq[7] = v.MaxWattSessionCycling.TrainingType;
                xq[8] = v.MaxWattSessionCycling.AverageWatt;
                xq[9] = v.MaxWattSessionCycling.BikeType;
                Dt.Rows.Add(xq);
            }
            else if (CyclerRadio.IsChecked.Equals(true))
            {
                Report v = manager.GenerateMonthlyTrainingsReport(year, month);
                testlabel.Content = "TotalSessions: " + v.TotalSessions.ToString();
                CycleSess.Content = "CycleSessions: " + v.CyclingSessions.ToString();
                RunSess.Content   = "N/A";
                TotalTime.Content = "TotalTime: " + v.TotalTrainingTime.ToString();
                RunDis.Content    = "N/A";
                RuntIme.Content   = "N/A";
                CycleDis.Content  = "TotalCycleDistance: " + v.TotalCyclingDistance.ToString();
                CycleTime.Content = "TotalCycleTime: " + v.TotalCyclingTrainingTime.ToString();
                Dt.Rows.Clear();

                DataRow xf = Dt.NewRow();
                xf[0] = "MaxSpeedCycling";
                xf[1] = v.MaxSpeedSessionCycling.Id;
                xf[2] = v.MaxSpeedSessionCycling.When;
                xf[3] = v.MaxSpeedSessionCycling.Distance.ToString() + " KM";
                xf[4] = v.MaxSpeedSessionCycling.Time;
                xf[5] = v.MaxSpeedSessionCycling.AverageSpeed;
                xf[6] = v.MaxSpeedSessionCycling.Comments;
                xf[7] = v.MaxSpeedSessionCycling.TrainingType;
                xf[8] = v.MaxSpeedSessionCycling.AverageWatt;
                xf[9] = v.MaxSpeedSessionCycling.BikeType;
                Dt.Rows.Add(xf);

                DataRow xq = Dt.NewRow();
                xq[0] = "MaxWattCycling";
                xq[1] = v.MaxWattSessionCycling.Id;
                xq[2] = v.MaxWattSessionCycling.When;
                xq[3] = v.MaxWattSessionCycling.Distance.ToString() + " KM";
                xq[4] = v.MaxWattSessionCycling.Time;
                if (v.MaxWattSessionCycling.AverageSpeed.Equals(null))
                {
                    v.MaxWattSessionCycling.AverageSpeed = 0;
                }
                xq[5] = v.MaxWattSessionCycling.AverageSpeed;
                xq[6] = v.MaxWattSessionCycling.Comments;
                xq[7] = v.MaxWattSessionCycling.TrainingType;
                xq[8] = v.MaxWattSessionCycling.AverageWatt;
                xq[9] = v.MaxWattSessionCycling.BikeType;
                Dt.Rows.Add(xq);

                DataRow x = Dt.NewRow();
                x[0] = "MaxDistanceCycling";
                x[1] = v.MaxDistanceSessionCycling.Id;
                x[2] = v.MaxDistanceSessionCycling.When;
                x[3] = v.MaxDistanceSessionCycling.Distance.ToString() + " KM";
                x[4] = v.MaxDistanceSessionCycling.Time;
                x[5] = v.MaxDistanceSessionCycling.AverageSpeed;
                x[6] = v.MaxDistanceSessionCycling.Comments;
                x[7] = v.MaxDistanceSessionCycling.TrainingType;
                x[8] = v.MaxDistanceSessionCycling.AverageWatt;
                x[9] = v.MaxDistanceSessionCycling.BikeType;
                Dt.Rows.Add(x);
            }
            else if (RunRadio.IsChecked.Equals(true))
            {
                Report v = manager.GenerateMonthlyTrainingsReport(year, month);
                testlabel.Content = "TotalSessions: " + v.TotalSessions.ToString();
                CycleSess.Content = "N/A ";
                RunSess.Content   = "RunSessions: " + v.RunningSessions.ToString();
                TotalTime.Content = "TotalTime: " + v.TotalTrainingTime.ToString();
                RunDis.Content    = "TotalRunningDistance: " + v.TotalRunningDistance.ToString();
                RuntIme.Content   = "TotalRuntIme: " + v.TotalRunningTrainingTime.ToString();
                CycleDis.Content  = "N/A ";
                CycleTime.Content = "N/A ";
                Dt.Rows.Clear();

                DataRow xt = Dt.NewRow();
                xt[0] = "MaxDistanceRunner";
                xt[1] = v.MaxDistanceSessionRunning.Id;
                xt[2] = v.MaxDistanceSessionRunning.When;
                xt[3] = v.MaxDistanceSessionRunning.Distance.ToString() + " M";
                xt[4] = v.MaxDistanceSessionRunning.Time;
                xt[5] = v.MaxDistanceSessionRunning.AverageSpeed;
                xt[6] = v.MaxDistanceSessionRunning.Comments;
                xt[7] = v.MaxDistanceSessionRunning.TrainingType;
                Dt.Rows.Add(xt);

                DataRow xv = Dt.NewRow();
                xv[0] = "MaxSpeedRunner";
                xv[1] = v.MaxSpeedSessionRunning.Id;
                xv[2] = v.MaxSpeedSessionRunning.When;
                xv[3] = v.MaxSpeedSessionRunning.Distance.ToString() + " M";
                xv[4] = v.MaxSpeedSessionRunning.Time;
                xv[5] = v.MaxSpeedSessionRunning.AverageSpeed;
                xv[6] = v.MaxSpeedSessionRunning.Comments;
                xv[7] = v.MaxSpeedSessionRunning.TrainingType;
                Dt.Rows.Add(xv);
            }
        }