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; }
public static List <OverviewData> GetLatestCyclingSessions(int count) { List <OverviewData> datas = new List <OverviewData>(); TrainingManager TM = new TrainingManager(new UnitOfWork(new TrainingContext())); foreach (var x in TM.GetPreviousCyclingSessions(count)) { datas.Add(new OverviewData(x)); } return(datas); }
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); } }
private void go_Click(object sender, RoutedEventArgs e) { int laatseTrainings = 0; if (int.TryParse(input.Text, out int inputInt)) { laatseTrainings = inputInt; List <CyclingSession> cTrainings = training.GetPreviousCyclingSessions(laatseTrainings); foreach (var ct in cTrainings) { output.Text += ct.ToString() + "\n"; } } }
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); }
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); }
public void previousCycling() { t = new TrainingManager(new UnitOfWork(new TrainingContext())); TrainingManager m = new TrainingManager(new UnitOfWork(new TrainingContext("Production"))); var date1 = new DateTime(2020, 4, 21, 16, 00, 00); var distance1 = 50; var time1 = new TimeSpan(1, 20, 00); var averageSpeed1 = 30; var averageWatt1 = 200; var type1 = TrainingType.Endurance; var comment1 = ""; var bikeType1 = BikeType.RacingBike; var date2 = new DateTime(2020, 4, 18, 18, 00, 00); var distance2 = 40; var time2 = new TimeSpan(1, 42, 00); // var averageSpeed2 = ; var averageWatt2 = 200; var type2 = TrainingType.Recuperation; var comment2 = ""; var bikeType2 = BikeType.RacingBike; List <CyclingSession> tranings = t.GetPreviousCyclingSessions(2); tranings[0].When.Should().Be(date2); tranings[0].Distance.Should().Be(distance2); tranings[0].Time.Should().Be(time2); tranings[0].AverageSpeed.Should().Be(20); tranings[0].AverageWatt.Should().Be(null); tranings[0].TrainingType.Should().Be(type2); tranings[0].Comments.Should().Be(null); tranings[0].BikeType.Should().Be(bikeType2); tranings[1].When.Should().Be(date1); tranings[1].Distance.Should().Be(distance1); tranings[1].Time.Should().Be(time1); tranings[1].AverageSpeed.Should().Be(30); tranings[1].AverageWatt.Should().Be(null); tranings[1].TrainingType.Should().Be(type1); tranings[1].Comments.Should().Be(null); tranings[1].BikeType.Should().Be(bikeType1); }
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"); }
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)); } } }
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"); }
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); } }
public List <CyclingSession> GetCountCyclingSessions(int count) { return(_gerry.GetPreviousCyclingSessions(count)); }
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); } }