コード例 #1
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);
        }
コード例 #2
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}");
            }
        }
コード例 #3
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            DateTime     when; TimeSpan whenAdditional;
            int          distance; TimeSpan time; float averageSpeed;
            TrainingType trainingtype; string comment = commentaarCyclingSession.Text;
            BikeType     bikeType; int averageWatt;

            #region parsers
            bool distanceW       = int.TryParse(afstandCyclingSession.Text, out distance);
            bool timeW           = TimeSpan.TryParse(tijdsduurCyclingSession.Text, out time);
            bool averageSpeedW   = float.TryParse(gemiddeldeSnelheidCyclingSession.Text, out averageSpeed);
            bool whenAdditionalW = TimeSpan.TryParse(tijdStipCyclingSession.Text, out whenAdditional);
            bool averageWattW    = int.TryParse(avgWattage.Text, out averageWatt);
            Enum.TryParse((string?)trainingTypeCyclingSession.SelectedItem, out trainingtype);
            Enum.TryParse((string?)typeFietsListBox.SelectedItem, out bikeType);
            #endregion
            try
            {
                if (!DatePickerCycling.SelectedDate.HasValue)
                {
                    throw new ArgumentException("Date not entered!");
                }
                if (!whenAdditionalW)
                {
                    throw new ArgumentException("Time not entered or incorrectly!");
                }
                if (!distanceW)
                {
                    throw new ArgumentException("Distance not entered or incorrectly!");
                }
                if (!timeW)
                {
                    throw new ArgumentException("Duration not entered or incorrectly!");
                }
                if (!averageWattW)
                {
                    throw new ArgumentException("Average Watt not entered or incorrectly!");
                }
                if (!averageSpeedW)
                {
                    when = (DateTime)DatePickerCycling.SelectedDate;
                    when = when.Add(whenAdditional);
                    m.AddCyclingTraining(when, distance, time, null, averageWatt, trainingtype, comment, bikeType);
                    MessageBox.Show("Cyclingsession added", "CyclingSession", MessageBoxButton.OK, MessageBoxImage.Information);
                    parent.refreshListBox();
                }
                else
                {
                    when = (DateTime)DatePickerCycling.SelectedDate;
                    when = when.Add(whenAdditional);
                    m.AddCyclingTraining(when, distance, time, averageSpeed, averageWatt, trainingtype, comment, bikeType);
                    MessageBox.Show("Cyclingsession added", "CyclingSession", MessageBoxButton.OK, MessageBoxImage.Information);
                    parent.refreshListBox();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "CyclingSession", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
コード例 #4
0
        public void TestRemovingCyclingSessionFromDatabase()
        {
            //Arrange
            TrainingManager m   = new TrainingManager(new UnitOfWork(new TrainingContextTest()));
            DateTime        now = DateTime.Now;
            CyclingSession  cS  = new CyclingSession(now, null, new TimeSpan(2, 0, 0), null, null, TrainingType.Endurance, null, BikeType.CityBike);
            CyclingSession  ToDeleteSessions = new CyclingSession(new DateTime(2010, 5, 12), null, new TimeSpan(2, 0, 0), null, null, TrainingType.Endurance, null, BikeType.IndoorBike);

            m.AddCyclingTraining(ToDeleteSessions.When, ToDeleteSessions.Distance, ToDeleteSessions.Time, ToDeleteSessions.AverageSpeed, ToDeleteSessions.AverageWatt, ToDeleteSessions.TrainingType, ToDeleteSessions.Comments, ToDeleteSessions.BikeType);
            m.AddCyclingTraining(cS.When, cS.Distance, cS.Time, cS.AverageSpeed, cS.AverageWatt, cS.TrainingType, cS.Comments, cS.BikeType);

            //Act
            TrainingManager m2 = new TrainingManager(new UnitOfWork(new TrainingContextTest(true)));

            m2.RemoveTrainings(new List <int>()
            {
                1
            }, new List <int>());
            var            cyclingSessions = m2.GetAllCyclingSessions();
            CyclingSession retrievedCycle  = cyclingSessions[0];

            //Assert
            Assert.IsTrue(cyclingSessions.Count == 1, "The Running Session was not deleted");
            Assert.AreEqual(retrievedCycle.AverageSpeed, cS.AverageSpeed, "AverageSpeed did not match up");
            Assert.AreEqual(retrievedCycle.Comments, cS.Comments, "Comments did not match up");
            Assert.AreEqual(retrievedCycle.Distance, cS.Distance, "Distance did not match up");
            Assert.AreEqual(retrievedCycle.Time, cS.Time, "Time did not match up");
            Assert.AreEqual(retrievedCycle.TrainingType, cS.TrainingType, "TrainingType did not match up");
            Assert.AreEqual(retrievedCycle.When, cS.When, "When did not match up");
            Assert.AreEqual(retrievedCycle.BikeType, cS.BikeType, "BikeType did not match up");
        }
コード例 #5
0
        public void AddCyclingTraining_ShouldThrowDomainException_WhenTimeInvalid()
        {
            TrainingManager TM = new TrainingManager(new UnitOfWork(new TrainingContextTest(true)));

            try
            {
                TM.AddCyclingTraining(new DateTime(2020, 4, 19, 16, 45, 00), null, new TimeSpan(-1), null, 219, TrainingType.Interval, "5x5 min 270", BikeType.IndoorBike);
            }
            catch (DomainException ex)
            {
                StringAssert.Contains(ex.Message, "Time invalid value");
                return;
            }

            try
            {
                TM.AddCyclingTraining(new DateTime(2020, 4, 19, 16, 45, 00), null, new TimeSpan(21, 0, 0), null, 219, TrainingType.Interval, "5x5 min 270", BikeType.IndoorBike);
            }
            catch (DomainException ex)
            {
                StringAssert.Contains(ex.Message, "Time invalid value");
                return;
            }

            Assert.Fail("The expected exception was not thrown");
        }
コード例 #6
0
        public void AddTraining_ShouldThrowException_IfWhenIsBeforeNow()
        {
            ExpectedException = Should.Throw <DomainException>(() => TM.AddCyclingTraining(DateTime.Now.AddHours(5), null, TimeSpan.FromHours(6), null, null, TrainingType.Endurance, null, BikeType.CityBike));
            ExpectedException.Message.ShouldBe("Training is in the future");

            ExpectedException = Should.Throw <DomainException>(() => TM.AddRunningTraining(DateTime.Now.AddHours(5), 10000, TimeSpan.FromHours(6), null, TrainingType.Endurance, null));
            ExpectedException.Message.ShouldBe("Training is in the future");
        }
コード例 #7
0
        public void AddCyclingTrainingTest_InTheFuture_ThrowDomainException()
        {
            SetUpForAddCyclingSessionExceptions();

            tm.Invoking(tm => tm.AddCyclingTraining(DateTime.Now.AddDays(1), null, TimeSpan.Zero,
                                                    null, null, TrainingType.Endurance, null, BikeType.CityBike))
            .Should().Throw <DomainException>().WithMessage("Training is in the future");
        }
コード例 #8
0
 public void SetupForReportTests()
 {
     tm = new TrainingManager(new UnitOfWork(new TrainingContextTest()));
     tm.AddCyclingTraining(new DateTime(2020, 4, 21, 16, 00, 00), 40, new TimeSpan(1, 20, 00), 30, null, TrainingType.Endurance, null, BikeType.RacingBike);
     tm.AddCyclingTraining(new DateTime(2020, 4, 18, 18, 00, 00), 40, new TimeSpan(1, 42, 00), null, null, TrainingType.Recuperation, null, BikeType.RacingBike);
     tm.AddCyclingTraining(new DateTime(2020, 3, 19, 16, 45, 00), null, new TimeSpan(1, 0, 00), null, 219, TrainingType.Interval, "5x5 min 270", BikeType.IndoorBike);
     tm.AddRunningTraining(new DateTime(2020, 4, 17, 12, 30, 00), 5000, new TimeSpan(0, 27, 17), null, TrainingType.Endurance, null);
     tm.AddRunningTraining(new DateTime(2020, 4, 19, 12, 30, 00), 5000, new TimeSpan(0, 25, 48), null, TrainingType.Endurance, null);
     tm.AddRunningTraining(new DateTime(2020, 3, 17, 12, 0, 00), 5000, new TimeSpan(0, 28, 10), null, TrainingType.Interval, "3x700m");
     tm.AddRunningTraining(new DateTime(2020, 3, 17, 11, 0, 00), 8000, new TimeSpan(0, 42, 10), null, TrainingType.Endurance, null);
 }
コード例 #9
0
        public void AllCyclingSessionTests()
        {
            TrainingManager tm = new TrainingManager(new UnitOfWork(new TrainingContextTest(false)));

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

            DateTime     session3Date      = new DateTime(2019, 10, 3);
            int          session3Distance  = 150;
            TimeSpan     session3Time      = new TimeSpan(2, 40, 0);
            float        session3AveSpeed  = 30;
            TrainingType session3TrainType = TrainingType.Interval;
            string       session3Comment   = "number 3";
            int          session3Watt      = 10;
            BikeType     session3BikeType  = BikeType.IndoorBike;

            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";
            int          session0Watt      = 2;
            BikeType     session0BikeType  = BikeType.IndoorBike;

            int nrOfSessions = 4;

            List <CyclingSession> cyclingSessions = tm.GetAllCyclingSessions();

            cyclingSessions.Count.Should().Be(nrOfSessions);

            cyclingSessions[0].When.Should().Be(session0Date);
            cyclingSessions[0].Distance.Should().Be(session0Distance);
            cyclingSessions[0].Time.Should().Be(session0Time);
            cyclingSessions[0].AverageSpeed.Should().Be(session0AveSpeed);
            cyclingSessions[0].TrainingType.Should().Be(session0TrainType);
            cyclingSessions[0].Comments.Should().BeEquivalentTo(session0Comment);
            cyclingSessions[0].AverageWatt.Should().Be(session0Watt);
            cyclingSessions[0].BikeType.Should().Be(session0BikeType);

            cyclingSessions[3].When.Should().Be(session3Date);
            cyclingSessions[3].Distance.Should().Be(session3Distance);
            cyclingSessions[3].Time.Should().Be(session3Time);
            cyclingSessions[3].AverageSpeed.Should().Be(session3AveSpeed);
            cyclingSessions[3].TrainingType.Should().Be(session3TrainType);
            cyclingSessions[3].Comments.Should().BeEquivalentTo(session3Comment);
            cyclingSessions[3].AverageWatt.Should().Be(session3Watt);
            cyclingSessions[3].BikeType.Should().Be(session3BikeType);
        }
コード例 #10
0
        public void MonthlyCyclingTrainingTest()
        {
            // t.AddCyclingTraining(new DateTime(2020, 5, 24, 08, 00, 00), 60, new TimeSpan(1, 00, 02), 20, null, TrainingType.Endurance, "comment", BikeType.RacingBike);
            TrainingManager m = new TrainingManager(new UnitOfWork(new TrainingContext("Production")));

            m.AddCyclingTraining(new DateTime(2020, 4, 21, 16, 00, 00), 50, 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), 20, null, TrainingType.Recuperation, null, BikeType.RacingBike);
            var mt = m.GenerateMonthlyCyclingReport(2020, 4);

            mt.TotalCyclingDistance.Should().Be(90);
            mt.TotalCyclingTrainingTime.Should().Be(new TimeSpan(3, 02, 00));
            mt.Rides.Select(x => x.When.Month).All(m => m == 4);
            mt.Rides.Count.Should().Be(2);
        }
コード例 #11
0
        public void AddCyclingAverageWatt()
        {
            TrainingManager m = new TrainingManager(new UnitOfWork(new TrainingContext("Production")));
            Action          a = () => m.AddCyclingTraining(new DateTime(2020, 01, 01), null, new TimeSpan(1), 30, 100000, TrainingType.Endurance, "comment", BikeType.CityBike);

            a.Should().Throw <DomainException>().WithMessage("Average watt invalid value");
        }
コード例 #12
0
        public void PreviousCyclingSessionTests()
        {
            TrainingManager tm = new TrainingManager(new UnitOfWork(new TrainingContextTest(false)));

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

            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";
            int          session1Watt      = 5;
            BikeType     session1BikeType  = BikeType.CityBike;

            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";
            int          session0Watt      = 2;
            BikeType     session0BikeType  = BikeType.IndoorBike;

            List <CyclingSession> cyclingSessions = tm.GetPreviousCyclingSessions(2);

            cyclingSessions[0].When.Should().Be(session0Date);
            cyclingSessions[0].Distance.Should().Be(session0Distance);
            cyclingSessions[0].Time.Should().Be(session0Time);
            cyclingSessions[0].AverageSpeed.Should().Be(session0AveSpeed);
            cyclingSessions[0].TrainingType.Should().Be(session0TrainType);
            cyclingSessions[0].Comments.Should().BeEquivalentTo(session0Comment);
            cyclingSessions[0].AverageWatt.Should().Be(session0Watt);
            cyclingSessions[0].BikeType.Should().Be(session0BikeType);

            cyclingSessions[1].When.Should().Be(session1Date);
            cyclingSessions[1].Distance.Should().Be(session1Distance);
            cyclingSessions[1].Time.Should().Be(session1Time);
            cyclingSessions[1].AverageSpeed.Should().Be(session1AveSpeed);
            cyclingSessions[1].TrainingType.Should().Be(session1TrainType);
            cyclingSessions[1].Comments.Should().BeEquivalentTo(session1Comment);
            cyclingSessions[1].AverageWatt.Should().Be(session1Watt);
            cyclingSessions[1].BikeType.Should().Be(session1BikeType);
        }
コード例 #13
0
        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);
        }
コード例 #14
0
        public void AddCyclingTrainingTest()
        {
            TrainingManager TM           = new TrainingManager(new UnitOfWork(new TrainingContextTest(true)));
            var             cyclingCount = TM.GetAllCyclingSessions().Count();

            cyclingCount.ShouldBe(3);
            TM.AddCyclingTraining(new DateTime(2020, 4, 19, 16, 45, 00), null, new TimeSpan(1, 0, 00), null, 219, TrainingType.Interval, "5x5 min 270", BikeType.IndoorBike);
            cyclingCount = TM.GetAllCyclingSessions().Count();
            cyclingCount.ShouldBe(4);
        }
コード例 #15
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                DateTime startTime = (DateTime)trainingDatePicker.SelectedDate;

                //startTime
                int startHours   = (int)startHoursSelection.SelectedItem;
                int startMinutes = (int)startMinutesSelection.SelectedItem;
                startTime = startTime.AddHours(startHours);
                startTime = startTime.AddMinutes(startMinutes);

                //duration

                int durationHours   = int.Parse(durationHoursTextBox.Text);
                int durationMinutes = int.Parse(durationMinutesTextBox.Text);


                TimeSpan duration = new TimeSpan(durationHours, durationMinutes, 0);

                //trainingType
                TrainingType trainingType = (TrainingType)trainingsTypeList.SelectedItem;

                string comment = null;
                if (commentTextBox.Text != "")
                {
                    comment = commentTextBox.Text;
                }

                int distance = int.Parse(distanceTextBox.Text);

                float?averageSpeed = null;
                if (kmPerHoursTextBox.Text != "")
                {
                    averageSpeed = float.Parse(kmPerHoursTextBox.Text);
                }

                int?watt = null;
                if (wattTextBox.Text != "")
                {
                    watt = int.Parse(wattTextBox.Text);
                }

                BikeType bikeType = (BikeType)bikeTypeList.SelectedItem;

                TrainingManager m = new TrainingManager(new UnitOfWork(new TrainingContext(_databaseString)));
                m.AddCyclingTraining(startTime, distance, duration, averageSpeed, watt, trainingType, comment, bikeType);
                setInitialValues();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().Name, MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
コード例 #16
0
        public void TestFindLatestCyclingSessionNotEnoughInDatabase()
        {
            //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.AddCyclingTraining(second, null, new TimeSpan(2, 0, 0), null, null, TrainingType.Endurance, null, BikeType.CityBike);
            m.AddCyclingTraining(first, null, new TimeSpan(2, 0, 0), null, null, TrainingType.Endurance, null, BikeType.IndoorBike);
            m.AddCyclingTraining(third, null, new TimeSpan(2, 0, 0), null, null, TrainingType.Endurance, null, BikeType.MountainBike);
            m.AddRunningTraining(DateTime.Now, 2000, new TimeSpan(1, 0, 0), null, TrainingType.Endurance, null);

            //Act
            var collection = m.GetPreviousCyclingSessions(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");
        }
コード例 #17
0
        public void AddCycle_ExceptionsCheck()
        {
            TrainingManager tm = new TrainingManager(new UnitOfWork(new TrainingContextTest(false)));

            Action act = () => tm.AddCyclingTraining(new DateTime(2021, 05, 23), 500, new TimeSpan(2, 3, 5), null, 10, TrainingType.Endurance, "comment", BikeType.CityBike);

            act.Should().Throw <DomainException>().WithMessage("Training is in the future");

            act = () => tm.AddCyclingTraining(new DateTime(2020, 05, 20), -1, new TimeSpan(2, 3, 5), 10, 50, TrainingType.Endurance, "comment", BikeType.CityBike);

            act.Should().Throw <DomainException>().WithMessage("Distance invalid value");

            act = () => tm.AddCyclingTraining(new DateTime(2020, 05, 20), null, new TimeSpan(-1), 10, 50, TrainingType.Endurance, "comment", BikeType.CityBike);

            act.Should().Throw <DomainException>().WithMessage("Time invalid value");

            act = () => tm.AddCyclingTraining(new DateTime(2020, 05, 20), null, new TimeSpan(2), 6000, 50, TrainingType.Endurance, "comment", BikeType.CityBike);

            act.Should().Throw <DomainException>().WithMessage("Average speed invalid value");

            act = () => tm.AddCyclingTraining(new DateTime(2020, 05, 20), null, new TimeSpan(2), 10, 80000, TrainingType.Endurance, "comment", BikeType.CityBike);

            act.Should().Throw <DomainException>().WithMessage("Average watt invalid value");

            act = () => tm.AddCyclingTraining(new DateTime(2020, 05, 20), null, new TimeSpan(2), 10, 1, TrainingType.Endurance, "comment", BikeType.CityBike);

            act.Should().NotThrow <Exception>();
        }
コード例 #18
0
        public void GenerateMonthlyCyclingReportTest()
        {
            //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
            //Act = roept testen method op met ingestgelde parameters
            Report rapport = t.GenerateMonthlyCyclingReport(year, month);
            //Assert = verifieert actie van geteste methoden
            //Test findMAxSessions
            rapport.MaxDistanceSessionCycling.Distance.Should().Be(257.20f);
            rapport.MaxSpeedSessionCycling.AverageSpeed.Should().Be(50.00f);
            rapport.MaxWattSessionCycling.AverageWatt.Should().Be(400);
            //Test TotalSessions
            rapport.CyclingSessions.Should().Be(3);
            rapport.TotalCyclingDistance.Should().Be(488.00f);
            rapport.TotalCyclingTrainingTime.Should().Be(new TimeSpan(24, 11, 26));
            //Test Timeline
            rapport.TimeLine.Should().NotBeEmpty();
        }
コード例 #19
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            TrainingType trainingType = TrainingType.Endurance;

            switch (cmbTypeTraining.SelectedItem.ToString())
            {
            case "Interval":
                trainingType = TrainingType.Interval;
                break;

            case "Endurance":
                trainingType = TrainingType.Endurance;
                break;

            case "Recuperation":
                trainingType = TrainingType.Recuperation;
                break;
            }

            BikeType bikeType = BikeType.CityBike;

            switch (cmbTypeTraining.SelectedItem.ToString())
            {
            case "CityBike":
                bikeType = BikeType.CityBike;
                break;

            case "IndoorBike":
                bikeType = BikeType.IndoorBike;
                break;

            case "MountainBike":
                bikeType = BikeType.MountainBike;
                break;

            case "RacingBike":
                bikeType = BikeType.RacingBike;
                break;
            }


            if (RunningRadioButton.IsChecked == true)
            {
                m.AddRunningTraining(new DateTime(2020, 4, 23, 17, 48, 00), int.Parse(txtDistance.Text), new TimeSpan(0, 31, 17), float.Parse(txtAverageSpeed.Text), trainingType, txtComments.Text);
            }
            else
            {
                m.AddCyclingTraining(new DateTime(2020, 4, 23, 17, 48, 00), int.Parse(txtDistance.Text), new TimeSpan(0, 31, 17), float.Parse(txtAverageSpeed.Text), int.Parse(txtWattage.Text), trainingType, txtComments.Text, bikeType);
            }
        }
コード例 #20
0
        public void DateTimeInFutureDomainException()
        {
            //Arrange
            DateTime     now      = DateTime.Now.AddMinutes(10);
            TimeSpan     time     = new TimeSpan(2, 3, 4);
            TrainingType training = TrainingType.Endurance;
            BikeType     bike     = BikeType.CityBike;

            //Act
            TrainingManager m = new TrainingManager(new UnitOfWork(new TrainingContextTest(true)));

            //Assert
            Assert.ThrowsException <DomainException>(() => m.AddCyclingTraining(now, null, time, null, null, training, null, bike));
        }
コード例 #21
0
        public void DistanceShouldNotBeNegative_ShouldThrowDomainException()
        {
            //Arrange
            DateTime     now      = DateTime.Now;
            TimeSpan     time     = new TimeSpan(2, 3, 4);
            TrainingType training = TrainingType.Endurance;
            BikeType     bike     = BikeType.CityBike;
            float        distance = -1;

            //Act
            TrainingManager m = new TrainingManager(new UnitOfWork(new TrainingContextTest(true)));

            //Assert
            Assert.ThrowsException <DomainException>(() => m.AddCyclingTraining(now, distance, time, null, null, training, null, bike));
        }
コード例 #22
0
        public void TestNullAcceptanceForCyclingSessionTable()
        {
            //Arrange
            TrainingManager m = new TrainingManager(new UnitOfWork(new TrainingContextTest()));

            m.AddCyclingTraining(DateTime.Now, null, new TimeSpan(2, 0, 0), null, null, TrainingType.Endurance, null, BikeType.CityBike);

            //Act
            CyclingSession cyclingSession = m.GetPreviousCyclingSessions(1)[0];

            //Assert
            Assert.IsNull(cyclingSession.AverageSpeed);
            Assert.IsNull(cyclingSession.Distance);
            Assert.IsNull(cyclingSession.AverageWatt);
            Assert.IsNull(cyclingSession.Comments);
        }
コード例 #23
0
        public void AverageSpeedShouldNotBeMoreThan60_ShouldThrowDomainException()
        {
            //Arrange
            DateTime     now          = DateTime.Now;
            TimeSpan     time         = new TimeSpan(2, 0, 0);
            TrainingType training     = TrainingType.Endurance;
            BikeType     bike         = BikeType.CityBike;
            float?       distance     = null;
            float?       averageSpeed = 61;

            //Act
            TrainingManager m = new TrainingManager(new UnitOfWork(new TrainingContextTest(true)));

            //Assert
            Assert.ThrowsException <DomainException>(() => m.AddCyclingTraining(now, distance, time, averageSpeed, null, training, null, bike));
        }
コード例 #24
0
        private void addToDb_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                DateTime date        = GetDate();
                float?   distance    = GetDistance();
                TimeSpan time        = GetTime();
                int?     averageWatt = null;
                if (sessionType == 1)
                {
                    averageWatt = GetWatt();
                }
                TrainingType trainType    = GetTrainingType();
                float?       averageSpeed = GetAverageSpeed();
                string       comments     = GetComments();
                BikeType     bikeType     = GetBikeType();

                if (sessionType == 0)
                {
                    Task.Run(() => tm.AddRunningTraining(date, (int)distance, time, averageSpeed, trainType, comments));
                    MessageBox.Show("Added a running session to the database");
                }
                else if (sessionType == 1)
                {
                    Task.Run(() => tm.AddCyclingTraining(date, distance, time, averageSpeed, averageWatt, trainType, comments, bikeType));
                    MessageBox.Show("Added a cycling session to the database");
                }

                if (finishedInput.IsChecked == true)
                {
                    this.Close();
                }
            }
            catch (DomainException dex)
            {
                ShowErrorMessage(dex.Message);
            }
            catch (ArgumentException aex)
            {
                ShowErrorMessage(aex.Message);
            }
            catch (Exception ex)
            {
                ShowErrorMessage(ex.Message);
            }
        }
コード例 #25
0
        public void TestMultipleAdditionsAndGetAllCyclingSessions()
        {
            //Arrange
            TrainingManager m          = new TrainingManager(new UnitOfWork(new TrainingContextTest()));
            int             totalAdded = 0;

            //Act
            for (int i = 0; i < 1000; i++)
            {
                m.AddCyclingTraining(DateTime.Now, 10, new TimeSpan(1, 0, 0), null, null, TrainingType.Recuperation, null, BikeType.CityBike);
                totalAdded++;
            }
            var collection = m.GetAllCyclingSessions();

            //Assert
            Assert.IsTrue(collection.Count == totalAdded);
            Assert.IsTrue(m.GetAllRunningSessions().Count == 0, "There were Running Sessions added");
        }
コード例 #26
0
        public void AddCyclingTrainingWithInvalidDistanceNul()
        {
            //Arrange
            DateTime now          = DateTime.Now;
            float    distanceNul  = 0;
            TimeSpan time         = new TimeSpan(0, 10, 20);
            float    averageSpeed = 40;
            int      averageWatt  = 400;
            //Act
            TrainingManager t   = new TrainingManager(new UnitOfWork(new TrainingContextTest(false)));
            Action          act = () => t.AddCyclingTraining(now, distanceNul, time, averageSpeed, averageWatt, TrainingType.Interval, "comment", BikeType.MountainBike);

            //Assert
            //--------------------------------------------------------------MS-------------------------------------------------------------------------------------------------------------------------
            //Assert.ThrowsException<DomainException>(() => t.AddCyclingTraining(now, distanceNul, time, averageSpeed, averageWatt, TrainingType.Interval, "comment", BikeType.MountainBike));
            //-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
            act.Should().Throw <DomainException>()
            .WithMessage("Distance invalid value");
        }
コード例 #27
0
        public void AddCyclingTrainingWithInvalidDate()
        {
            //Arrange = initialisatie objecten en kent waarden van gegevens toe aan methoden
            DateTime future       = new DateTime(2050, 2, 12);
            float    distance     = 400;
            TimeSpan time         = new TimeSpan(0, 10, 20);
            float    averageSpeed = 40;
            int      averageWatt  = 400;
            //Act = roept testen method op met ingestgelde parameters
            TrainingManager t   = new TrainingManager(new UnitOfWork(new TrainingContextTest(false)));
            Action          act = () => t.AddCyclingTraining(future, distance, time, averageSpeed, averageWatt, TrainingType.Interval, "comment", BikeType.MountainBike);

            //Assert = verifieert actie van geteste methoden
            //--------------------------------------------------------------MS-------------------------------------------------------------------------------------------------------------------------
            //Assert.ThrowsException<DomainException>(() => t.AddCyclingTraining(future, distance, time, averageSpeed, averageWatt, TrainingType.Interval, "comment", BikeType.MountainBike));
            //-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
            act.Should().Throw <DomainException>()
            .WithMessage("Training is in the future");
        }
コード例 #28
0
        private void bSave_Click(object sender, RoutedEventArgs e)
        {
            DateTime     date         = GetDate();
            float?       distance     = GetDistance();
            TimeSpan     time         = GetTime();
            int?         averageWatt  = GetWatt();
            TrainingType trainType    = GetTrainingType();
            float?       averageSpeed = GetAverageSpeed();
            string       comments     = GetComment();
            BikeType     bikeType     = GetBikeType();

            try
            {
                training.AddCyclingTraining(date, distance, time, averageSpeed, averageWatt, trainType, comments, bikeType);
                MessageBox.Show("Training werd toegevoegd");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Niet gelukt om training toe te voegen");
            }
        }
コード例 #29
0
        public void TestAddCyclingSessionToDatabase()
        {
            //Arrange
            TrainingManager m   = new TrainingManager(new UnitOfWork(new TrainingContextTest()));
            DateTime        now = DateTime.Now;
            CyclingSession  cS  = new CyclingSession(now, 10, new TimeSpan(2, 0, 0), null, null, TrainingType.Endurance, "", BikeType.CityBike);

            //Act
            m.AddCyclingTraining(now, 10, new TimeSpan(2, 0, 0), null, null, TrainingType.Endurance, "", BikeType.CityBike);
            CyclingSession retrieved = m.GetPreviousCyclingSessions(1)[0];

            //Assert
            Assert.IsTrue(m.GetAllCyclingSessions().Count == 1);
            Assert.IsTrue(m.GetAllRunningSessions().Count == 0, "Cycling Session got added as Running Session as well");
            Assert.AreEqual(retrieved.AverageSpeed, cS.AverageSpeed, "AverageSpeed did not match up");
            Assert.AreEqual(retrieved.AverageWatt, cS.AverageWatt, "AverageWatt did not match up");
            Assert.AreEqual(retrieved.BikeType, cS.BikeType, "BikeType 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");
        }
コード例 #30
0
        private void FormSaveClickEevent(object sender, RoutedEventArgs e)
        {
            SaveButton.Content = "Saving...";

            DateTime inputDate = new DateTime();
            DateTime inputTime = new DateTime();

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

            DateTime date = new DateTime(inputDate.Year, inputDate.Month, inputDate.Day, inputTime.Hour, inputTime.Minute, inputTime.Second);

            int trainingType = InputTrainingType.SelectedIndex;

            if (trainingType < 0)
            {
                MessageBox.Show("You must select a training type");
                return;
            }

            int sportType = InputSportType.SelectedIndex;

            if (sportType < 0)
            {
                MessageBox.Show("You must select a sport type");
                return;
            }

            int bikeType = InputBikeType.SelectedIndex;

            if (sportType == 1)
            {
                if (bikeType < 0)
                {
                    MessageBox.Show("You must select a bike type");
                    return;
                }
            }

            if (InputLength.Text == "")
            {
                MessageBox.Show("You must fill in the distance");
                return;
            }

            if (!Int32.TryParse(InputLength.Text, out int inputLength))
            {
                MessageBox.Show("You must fill in a valid number as distance");
                return;
            }

            if (inputLength <= 0)
            {
                MessageBox.Show("Distance must be greater than 0");
                return;
            }

            if (InputDuration.Text == "")
            {
                MessageBox.Show("You must fill in a duration");
                return;
            }

            if (!TimeSpan.TryParse(InputDuration.Text, out TimeSpan duration))
            {
                MessageBox.Show("Duration must be a valid time format");
                return;
            }

            String inputComment = InputComment.Text;



            TrainingType TrainingType = TrainingType.Interval;

            switch (trainingType)
            {
            case 0:
                TrainingType = TrainingType.Recuperation;
                break;

            case 1:
                TrainingType = TrainingType.Endurance;
                break;

            case 2:
                TrainingType = TrainingType.Interval;
                break;
            }

            try
            {
                switch (sportType)
                {
                case 0:
                    int runSpeed = Convert.ToInt32((inputLength * 1000) / duration.TotalHours);
                    manager.AddRunningTraining(date, inputLength, duration, runSpeed, TrainingType, inputComment);
                    break;

                case 1:
                    BikeType BikeType = BikeType.CityBike;
                    switch (bikeType)
                    {
                    case 0:
                        BikeType = BikeType.MountainBike;
                        break;

                    case 1:
                        BikeType = BikeType.IndoorBike;
                        break;

                    case 2:
                        BikeType = BikeType.RacingBike;
                        break;

                    case 3:
                        BikeType = BikeType.CityBike;
                        break;
                    }

                    int bikeSpeed = Convert.ToInt32(inputLength / duration.TotalHours);
                    manager.AddCyclingTraining(date, (float)inputLength, duration, bikeSpeed, 100, TrainingType, inputComment, BikeType);
                    break;

                default:
                    break;
                }

                MessageBox.Show("New training has been added");
            }
            catch (Exception)
            {
                MessageBox.Show("Something went wrong while adding new a training");
            }

            SaveButton.Content = "Save Training";
        }