private void mnuUserExercise_Click(object sender, RoutedEventArgs e) { var item = (StrengthTrainingItemViewModel)(sender as FrameworkElement).DataContext; List <StrengthTrainingItemDTO> itemsToCopy = new List <StrengthTrainingItemDTO>(); if (Settings.TreatSuperSetsAsOne && !string.IsNullOrEmpty(item.Item.SuperSetGroup)) {//if we should treat superset as one then when we copy one exercise which is a part of superset then we should copy all of them itemsToCopy.AddRange(item.Item.StrengthTrainingEntry.Entries.Where(x => x.SuperSetGroup == item.Item.SuperSetGroup).OrderBy(x => x.Position)); } else { itemsToCopy.Add(item.Item); } foreach (var itemDto in itemsToCopy) { var newItem = itemDto.Copy(true); TrainingBuilder builder = new TrainingBuilder(); builder.PrepareCopiedStrengthTraining(newItem, Settings.CopyStrengthTrainingMode); builder.SetPreviewSets(itemDto, newItem); Entry.AddEntry(newItem); } //_viewModel.AddExercise(item.Item.Exercise); lblNoExercises.Visibility = Entry.Entries.Count == 0? System.Windows.Visibility.Visible: System.Windows.Visibility.Collapsed; StrengthWorkoutViewModel.ResetPositions(Entry); show(true); pivot.SelectedIndex = 0; }
private void usrWorkoutPlansChooser1_SelectedPlanDayChanged(object sender, EventArgs e) { TrainingBuilder builder = new TrainingBuilder(); builder.FillRepetitionNumber = Options.StrengthTraining.Default.FillRepetitionNumberFromPlan; builder.FillTrainingFromPlan(usrWorkoutPlansChooser1.SelectedPlanDay, strengthEntry); usrTrainingDaySourceGrid1.Fill(strengthEntry, usrWorkoutPlansChooser1.SelectedPlanDay, ReadOnly); }
public async Task delete_a_training_by_id() { var ATraining = new TrainingBuilder() .withId(1) .withName("ATraining") .withDescription("ADescription") .withDateTime(new DateTime(2020, 1, 1)).withCreatedBy("AnId").Build(); await DeleteTraining.Execute(1).Received(); }
protected override void PrepareCopiedEntry(EntryObjectDTO origEntry, EntryObjectDTO entry) { StrengthTrainingEntryDTO strength = entry as StrengthTrainingEntryDTO; if (strength != null) { var oldStrength = (StrengthTrainingEntryDTO)origEntry; copyStrengthTrainingProperties(strength, oldStrength); TrainingBuilder builder = new TrainingBuilder(); builder.PrepareCopiedStrengthTraining(strength, Settings.CopyStrengthTrainingMode); builder.SetPreviewSets(oldStrength, strength); } }
public void PostTraining_ValidModelReturnOkResult() { var item = TrainingBuilder.GetTestTraining(); var mock = new Mock <ITrainingRepository>(); //Act mock.Setup(p => p.Add(item)).ReturnsAsync(true); var controller = new TrainingController(mock.Object); var result = controller.PostTraining(item); Assert.NotNull(result); var response = Assert.IsType <OkObjectResult>(result.Result); Assert.Equal(200, response.StatusCode); }
public void GetById_UnknownIdPassed_ReturnsNotFoundResult() { // Act var testTraining = TrainingBuilder.GetTestTraining(); var mock = new Mock <ITrainingRepository>(); //Act mock.Setup(p => p.GetTraining(1)).ReturnsAsync(testTraining); var controller = new TrainingController(mock.Object); // Assert // act var notFoundResult = controller.GetTraining(999); // Assert Assert.IsType <NotFoundResult>(notFoundResult.Result); }
public void PostTraining_InValidModelBadRequestError() { var item = TrainingBuilder.GetTestTraining(); var mock = new Mock <ITrainingRepository>(); //Act mock.Setup(p => p.Add(item)).ReturnsAsync(true); var controller = new TrainingController(mock.Object); controller.ModelState.AddModelError("name", "name is required"); var result = controller.PostTraining(item); Assert.NotNull(result); var response = Assert.IsType <BadRequestObjectResult>(result.Result); Assert.Equal(400, response.StatusCode); }
private void fillStrengthTrainingEntryWithPlan(TrainingPlanDay planDay) { if (ApplicationState.Current.CurrentBrowsingTrainingDays.IsMine) { if (!EntryObjectPageBase.EnsureRemoveEntryTypeFromToday(typeof(StrengthTrainingEntryDTO))) {//cancel overwrite return; } var strengthTraining = new StrengthTrainingEntryDTO(); strengthTraining.StartTime = DateTime.Now; ApplicationState.Current.TrainingDay.TrainingDay.Objects.Add(strengthTraining); strengthTraining.TrainingDay = ApplicationState.Current.TrainingDay.TrainingDay; ApplicationState.Current.CurrentEntryId = new LocalObjectKey(strengthTraining); TrainingBuilder builder = new TrainingBuilder(); builder.FillTrainingFromPlan(planDay, strengthTraining); //apply setting related with copy sets data builder.PrepareCopiedStrengthTraining(strengthTraining, Settings.CopyStrengthTrainingMode); this.GetParent <PhoneApplicationPage>().Navigate("/Pages/StrengthWorkoutPage.xaml"); } }
public void GetById_ExistingIdPassed_ReturnsOkResult() { var testTraining = TrainingBuilder.GetTestTraining(); var mock = new Mock <ITrainingRepository>(); //Act mock.Setup(p => p.GetTraining(1)).ReturnsAsync(testTraining); var controller = new TrainingController(mock.Object); // Assert // act var result = controller.GetTraining(1); var response = Assert.IsType <OkObjectResult>(result.Result); Assert.Equal(200, response.StatusCode); Training trainingResult = (Training)response.Value; // assert Assert.Equal(1, trainingResult.Id); }
public void TestFillEmptyEntryObjectWithoutRepetitions() { TrainingPlan plan = getTrainingPlanWithSets(); var entry = new StrengthTrainingEntryDTO(); TrainingBuilder builder = new TrainingBuilder(); Assert.AreEqual(0, entry.Entries.Count); Assert.AreEqual(null, entry.TrainingPlanItemId); builder.FillTrainingFromPlan(plan.Days[0], entry); Assert.AreEqual(plan.Days[0].Entries.Count, entry.Entries.Count); Assert.AreEqual(plan.Days[0].GlobalId, entry.TrainingPlanItemId); for (int i = 0; i < plan.Days[0].Entries.Count; i++) { Assert.AreEqual(plan.Days[0].Entries[i].Exercise, entry.Entries[i].Exercise); Assert.AreEqual(plan.Days[0].Entries[i].Sets.Count, entry.Entries[i].Series.Count); for (int j = 0; j < plan.Days[0].Entries[i].Sets.Count; j++) { Assert.AreEqual(null, entry.Entries[i].Series[j].RepetitionNumber); } } }
private void usrWorkoutPlansChooser1_SelectedPlanDayChanged(object sender, EventArgs e) { //TODO:This event is raised twice every change - this could be improved later:) if (StrengthDetails.usrWorkoutPlansChooser1.SelectedPlanDay != null) { viewModel.TrainingPlanDay = StrengthDetails.usrWorkoutPlansChooser1.SelectedPlanDay; } if (StrengthDetails.usrWorkoutPlansChooser1.SelectedPlanDay == null || StrengthTrainingEntry.TrainingPlanItemId == StrengthDetails.usrWorkoutPlansChooser1.SelectedPlanDay.GlobalId) { updateToolbar(); return; } TrainingBuilder builder = new TrainingBuilder(); builder.FillRepetitionNumber = StrengthTraining.Default.FillRepetitionNumberFromPlan; builder.FillTrainingFromPlan(StrengthDetails.usrWorkoutPlansChooser1.SelectedPlanDay, StrengthTrainingEntry); viewModel.UpdateTrainingPlan(true); SetModifiedFlag(); updateToolbar(); }
public async Task get_training_by_id() { var ATraining = new TrainingBuilder() .withId(1) .withName("ATraining") .withDescription("ADescription") .withDateTime(new DateTime(2020, 1, 1)).withCreatedBy("AnId").Build(); TrainingRepositoryPort.GetTrainingByUser(ATraining.CreatedBy).Returns(new List <Training> { ATraining }); var result = await GetTrainingById.Execute(1); result.Should().BeEquivalentTo(new List <TrainingResponse> { new TrainingResponse { Name = ATraining.Name, Description = ATraining.Description, Date = ATraining.DateTime, CreatedBy = ATraining.CreatedBy } }); }
protected override void copyAllImplementation(EntryObjectDTO oldEntry) { if (oldEntry != null) { //var copyDay = oldDay.TrainingDay.StrengthWorkout.Copy(true); //PrepareCopiedEntry(oldDay.TrainingDay.StrengthWorkout,copyDay); var itemsToCopy = lstOldItems.SelectedItems.Cast <StrengthTrainingItemViewModel>().Select(x => x.Item).ToList(); var strength = Entry; var oldStrength = (StrengthTrainingEntryDTO)oldEntry; copyStrengthTrainingProperties(strength, oldStrength); TrainingBuilder builder = new TrainingBuilder(); foreach (var itemDto in itemsToCopy) { var newItem = itemDto.Copy(true); builder.PrepareCopiedStrengthTraining(newItem, Settings.CopyStrengthTrainingMode); if (Settings.CopyStrengthTrainingMode != CopyStrengthTrainingMode.OnlyExercises) { builder.SetPreviewSets(itemDto, newItem); } strength.AddEntry(newItem); } builder.CleanSingleSupersets(Entry); StrengthWorkoutViewModel.ResetPositions(Entry); show(true); lblNoExercises.Visibility = Entry.Entries.Count == 0? System.Windows.Visibility.Visible: System.Windows.Visibility.Collapsed; } }