示例#1
0
        public void previousRunning()
        {
            TrainingManager m = new TrainingManager(new UnitOfWork(new TrainingContext("Production")));
            // m.AddRunningTraining(new DateTime(2020, 4, 17, 12, 30, 00), 5000, new TimeSpan(0, 27, 17), 20, TrainingType.Endurance, null);
            //m.AddRunningTraining(new DateTime(2020, 4, 19, 12, 30, 00), 5000, new TimeSpan(0, 25, 48), 25, TrainingType.Endurance, null);

            var date1     = new DateTime(2020, 4, 17, 12, 30, 00);
            var distance1 = 5000;
            var time1     = new TimeSpan(0, 27, 17);
            var type1     = TrainingType.Endurance;
            var comment1  = "";

            var date2     = new DateTime(2020, 4, 19, 12, 30, 00);
            var distance2 = 5000;
            var time2     = new TimeSpan(0, 25, 48);
            var type2     = TrainingType.Endurance;
            var comment2  = "";

            List <RunningSession> tranings = m.GetPreviousRunningSessions(2);

            tranings[0].When.Should().Be(date1);
            tranings[0].Distance.Should().Be(distance1);
            tranings[0].Time.Should().Be(time1);
            tranings[0].AverageSpeed.Should().Be(20);
            tranings[0].TrainingType.Should().Be(type1);
            tranings[0].Comments.Should().Be(null);


            tranings[1].When.Should().Be(date2);
            tranings[1].Distance.Should().Be(distance2);
            tranings[1].Time.Should().Be(time2);
            tranings[1].AverageSpeed.Should().Be(25);
            tranings[1].TrainingType.Should().Be(type2);
            tranings[1].Comments.Should().Be(null);
        }
        public void GetPreviousSessions_ShouldReturnCorrectAmount(int count)
        {
            var expected = count;

            TM.GetPreviousCyclingSessions(count).Count.ShouldBe(expected);
            TM.GetPreviousRunningSessions(count).Count.ShouldBe(expected);
        }
        private void SetLatestSessions()
        {
            bool isNumber = int.TryParse(numberOfLatetsSessions.Text, out int amount);

            if (!isNumber)
            {
                MessageBox.Show("Give a number", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error); return;
            }
            if (cbBycicle.IsChecked == false && cbRunning.IsChecked == false)
            {
                MessageBox.Show("Select a type", "ERROR", MessageBoxButton.OK); return;
            }
            List <CyclingSession> biSes = new List <CyclingSession>();

            if (cbBycicle.IsChecked == true)
            {
                biSes.AddRange(tm.GetPreviousCyclingSessions(amount));
                lbTitle.Content = $"The last {amount} bike-sessions";
            }
            List <RunningSession> runSes = new List <RunningSession>();

            if (cbRunning.IsChecked == true)
            {
                runSes.AddRange(tm.GetPreviousRunningSessions(amount));
                lbTitle.Content = $"The last {amount} run-sessions";
            }
            if (cbRunning.IsChecked == true && cbBycicle.IsChecked == true)
            {
                lbTitle.Content = $"The last {amount} sessions";
            }

            List <Object> sessions = SortSessions(biSes, runSes).Take(amount).ToList();

            lvOverview.ItemsSource = sessions;
        }
示例#4
0
        public void GetPreviousRunningSessionsTest()
        {
            TrainingManager TM = new TrainingManager(new UnitOfWork(new TrainingContextTest(true)));
            RunningSession  runningSession1 = new RunningSession(new DateTime(2020, 3, 17, 11, 0, 00), 5000, new TimeSpan(0, 28, 10), null, TrainingType.Interval, "3x700m");
            RunningSession  runningSession2 = new RunningSession(new DateTime(2020, 3, 17, 11, 0, 00), 8000, new TimeSpan(0, 42, 10), null, TrainingType.Endurance, null);

            List <RunningSession> runningsessions = TM.GetPreviousRunningSessions(2);

            runningsessions[0].ShouldBe(runningSession1);
            runningsessions[1].ShouldBe(runningSession2);
        }
        public static List <OverviewData> GetLatestRunningSessions(int count)
        {
            List <OverviewData> datas = new List <OverviewData>();
            TrainingManager     TM    = new TrainingManager(new UnitOfWork(new TrainingContext()));

            foreach (var x in TM.GetPreviousRunningSessions(count))
            {
                datas.Add(new OverviewData(x));
            }
            return(datas);
        }
示例#6
0
        public void TestNullAcceptanceForRunningSessionTable()
        {
            //Arrange
            TrainingManager m = new TrainingManager(new UnitOfWork(new TrainingContextTest()));

            m.AddRunningTraining(DateTime.Now, 15000, new TimeSpan(2, 0, 0), null, TrainingType.Endurance, null);

            //Act
            RunningSession runningSession = m.GetPreviousRunningSessions(1)[0];

            //Assert
            Assert.IsNull(runningSession.Comments);
        }
示例#7
0
        public void ShowResults(int amount, SessionType sessionType)
        {
            TrainingManager _tM = new TrainingManager(new UnitOfWork(new TrainingContext(_databaseString)));

            if (sessionType == SessionType.Cycling)
            {
                dataGridShowResults.ItemsSource = _tM.GetPreviousCyclingSessions(amount);
            }
            else
            {
                dataGridShowResults.ItemsSource = _tM.GetPreviousRunningSessions(amount);
            }
        }
示例#8
0
        private void go_Click(object sender, RoutedEventArgs e)
        {
            int laatseTrainings = 0;

            if (int.TryParse(input.Text, out int inputInt))
            {
                laatseTrainings = inputInt;
                List <RunningSession> cTrainings = training.GetPreviousRunningSessions(laatseTrainings);

                foreach (var ct in cTrainings)
                {
                    output.Text += ct.ToString() + "\n";
                }
            }
        }
示例#9
0
        public void TestFindLatestRunningSessionsNotEnoughInDatabase()
        {
            //Arrange
            TrainingManager m      = new TrainingManager(new UnitOfWork(new TrainingContextTest()));
            DateTime        first  = new DateTime(2000, 5, 12);
            DateTime        second = new DateTime(2008, 5, 12);
            DateTime        third  = DateTime.Now;

            m.AddRunningTraining(second, 10000, new TimeSpan(2, 0, 0), null, TrainingType.Endurance, null);
            m.AddRunningTraining(first, 10000, new TimeSpan(2, 0, 0), null, TrainingType.Endurance, null);
            m.AddRunningTraining(third, 10000, new TimeSpan(2, 0, 0), null, TrainingType.Endurance, null);
            m.AddCyclingTraining(DateTime.Now, 20, new TimeSpan(1, 0, 0), null, null, TrainingType.Endurance, null, BikeType.MountainBike);

            //Act
            var collection = m.GetPreviousRunningSessions(5);

            //Assert
            Assert.IsTrue(collection.Count == 3, "Did not return the right amount amount");
            Assert.IsTrue(collection[0].When == first, "Did not get returned in the right order");
            Assert.IsTrue(collection[1].When == second, "Did not get returned in the right order");
        }
示例#10
0
        public void TestAddRunningSessionToDatabase()
        {
            //Arrange
            TrainingManager m = new TrainingManager(new UnitOfWork(new TrainingContextTest()));

            DateTime       now = DateTime.Now;
            RunningSession cS  = new RunningSession(now, 10000, new TimeSpan(2, 0, 0), null, TrainingType.Endurance, "");

            //Act
            m.AddRunningTraining(now, 10000, new TimeSpan(2, 0, 0), null, TrainingType.Endurance, "");
            RunningSession retrieved = m.GetPreviousRunningSessions(1)[0];

            //Assert
            Assert.IsTrue(m.GetAllRunningSessions().Count == 1);
            Assert.IsTrue(m.GetAllCyclingSessions().Count == 0, "Running Session got added as Cycling Session as well");
            Assert.AreEqual(retrieved.AverageSpeed, cS.AverageSpeed, "AverageSpeed did not match up");
            Assert.AreEqual(retrieved.Comments, cS.Comments, "Comments did not match up");
            Assert.AreEqual(retrieved.Distance, cS.Distance, "Distance did not match up");
            Assert.AreEqual(retrieved.Time, cS.Time, "Time did not match up");
            Assert.AreEqual(retrieved.TrainingType, cS.TrainingType, "TrainingType did not match up");
            Assert.AreEqual(retrieved.When, cS.When, "When did not match up");
        }
示例#11
0
        public void PreviousRunningSessionTests()
        {
            TrainingManager tm = new TrainingManager(new UnitOfWork(new TrainingContextTest(false)));

            tm.AddRunningTraining(new DateTime(2019, 10, 1), 350, new TimeSpan(2, 50, 0), 25, TrainingType.Interval, "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, 40, 0), 30, TrainingType.Interval, "number 3");
            tm.AddRunningTraining(new DateTime(2018, 10, 1), 200, new TimeSpan(2, 30, 0), 20, TrainingType.Endurance, "number 4");

            DateTime     session1Date      = new DateTime(2019, 10, 1);
            int          session1Distance  = 350;
            TimeSpan     session1Time      = new TimeSpan(2, 50, 0);
            float        session1AveSpeed  = 25;
            TrainingType session1TrainType = TrainingType.Interval;
            string       session1Comment   = "number 1";

            DateTime     session0Date      = new DateTime(2018, 10, 1);
            int          session0Distance  = 200;
            TimeSpan     session0Time      = new TimeSpan(2, 30, 0);
            float        session0AveSpeed  = 20;
            TrainingType session0TrainType = TrainingType.Endurance;
            string       session0Comment   = "number 4";

            List <RunningSession> runningSessions = tm.GetPreviousRunningSessions(2);

            runningSessions[0].When.Should().Be(session0Date);
            runningSessions[0].Distance.Should().Be(session0Distance);
            runningSessions[0].Time.Should().Be(session0Time);
            runningSessions[0].AverageSpeed.Should().Be(session0AveSpeed);
            runningSessions[0].TrainingType.Should().Be(session0TrainType);
            runningSessions[0].Comments.Should().BeEquivalentTo(session0Comment);

            runningSessions[1].When.Should().Be(session1Date);
            runningSessions[1].Distance.Should().Be(session1Distance);
            runningSessions[1].Time.Should().Be(session1Time);
            runningSessions[1].AverageSpeed.Should().Be(session1AveSpeed);
            runningSessions[1].TrainingType.Should().Be(session1TrainType);
            runningSessions[1].Comments.Should().BeEquivalentTo(session1Comment);
        }
示例#12
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));
                }
            }
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            bool?cycling = cyclingCheckBox.IsChecked;
            bool?running = runningCheckBox.IsChecked;
            int  amount;
            bool amountW = int.TryParse(amountSession.Text, out amount);

            try
            {
                if (!amountW)
                {
                    throw new ArgumentException("amount is not entered");
                }
                if (cycling == true && running == true)
                {
                    throw new ArgumentException("pls select only one checkbox");
                }
                if (cycling == true)
                {
                    LatestSessionPerMonthDataGrid.ItemsSource = m.GetPreviousCyclingSessions(amount);
                    LatestSessionPerMonthDataGrid.Items.Refresh();
                }
                else if (running == true)
                {
                    LatestSessionPerMonthDataGrid.ItemsSource = m.GetPreviousRunningSessions(amount);
                    LatestSessionPerMonthDataGrid.Items.Refresh();
                }
                else
                {
                    throw new ArgumentException("pls select at least one checkbox");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Latest Session", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
示例#14
0
 public List <RunningSession> GetCountRunningSessions(int count)
 {
     return(_gerry.GetPreviousRunningSessions(count));
 }
示例#15
0
        private void inputButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int nrOfSessions = 0;
                if (string.IsNullOrWhiteSpace(prevSessInput.Text))
                {
                    throw new ArgumentException("Nr of sessions can not be empty.");
                }
                if (!int.TryParse(prevSessInput.Text, out int nrofSessionsParsed))
                {
                    throw new ArgumentException("Nr of sessions is not a whole number.");
                }
                else
                {
                    if (nrofSessionsParsed > 0)
                    {
                        nrOfSessions = nrofSessionsParsed;
                    }
                    else
                    {
                        throw new ArgumentException("Nr of sessions must be bigger than 0.");
                    }
                }

                if (selectedSession == 0)
                {
                    List <RunningSession> sessions = tm.GetPreviousRunningSessions(nrOfSessions);
                    inputPanel.Visibility    = Visibility.Collapsed;
                    sessionsPanel.Visibility = Visibility.Visible;
                    MaxHeight = 370;
                    MaxWidth  = 400;
                    Height    = 370;
                    Width     = 400;
                    MinHeight = 370;
                    MinWidth  = 400;
                    SetSessions(sessions);
                }
                else if (selectedSession == 1)
                {
                    List <RunningSession> sessions = tm.GetPreviousRunningSessions(nrOfSessions);
                    inputPanel.Visibility    = Visibility.Collapsed;
                    sessionsPanel.Visibility = Visibility.Visible;
                    MaxHeight = 370;
                    MaxWidth  = 400;
                    Height    = 370;
                    Width     = 400;
                    MinHeight = 370;
                    MinWidth  = 400;
                    SetSessions(tm.GetPreviousCyclingSessions(nrOfSessions));
                }
            }
            catch (ArgumentException aex)
            {
                ShowErrorMessage(aex.Message);
            }
            catch (Exception ex)
            {
                ShowErrorMessage(ex.Message);
            }
        }