// GET: Habit public ActionResult Index(int habitId) { Habit dbHabit = db.Habits.First(h => h.HabitId == habitId); var habitModel = new HabitViewModel(dbHabit); return(View(habitModel)); }
public void TestInit() { _dateProvider = Mock.Create <IDateTimeProvider>(); _navigationService = Mock.Create <INavigationService>(); _habitService = Mock.Create <IHabitService>(); _habitViewModel = new HabitViewModel(_dateProvider, _habitService, _navigationService); }
public void HabitInitializesFillingWhenTheDateTodayIsStartDay() { // Arrange var firstMondayDate = new DateTime(2017, 3, 5); var startDate = firstMondayDate.AddDays(2); var repeatType = RepeatType.Mon | RepeatType.Wed; var daysToRepeat = 3; var expectedFilling = new ObservableDictionary <DateTime, int> { // First Week { startDate, 0 }, { startDate.AddDays(5), 0 }, { startDate.AddDays(7), 0 }, { startDate.AddDays(5 + 7), 0 }, { startDate.AddDays(7 + 7), 0 }, }; var model = Mock.Create <IHabitModel>(); Mock.Arrange(() => model.RepeatType).Returns(repeatType); Mock.Arrange(() => model.DaysToRepeat).Returns(daysToRepeat); Mock.Arrange(() => model.StartDate).Returns(startDate); Mock.Arrange(() => _dateProvider.Now).Returns(firstMondayDate); // Act var habit = new HabitViewModel(_dateProvider, _habitService, _navigationService, model); // Assert CustomAsserts.DictionariesAreEqual(expectedFilling, habit.Filling); }
private void AddHabit(HabitViewModel habit) { var habitView = new HabitView(habit); MainLayout.Children.Add(habitView); if (habit.IsCreateMode) { habitView.FocusEntry(); } }
private HabitView FindHabitItem(HabitViewModel id) { foreach (var child in MainLayout.Children) { var habit = child as HabitView; if (habit?.ViewModel == id) { return(habit); } } return(null); }
public ModifyHabitPage(HabitViewModel habit) { MyLogger.WriteStartMethod(); try { ViewModel = new ModifyHabitViewModel(((App)App.Current).HabitService, ((App)App.Current).Navigation, habit); InitializeComponent(); } catch (Exception e) { MyLogger.WriteException(e); throw; } MyLogger.WriteEndMethod(); }
public void HabitInitializesFillingToEmptyCollectionIfStartDateIsLaterThanToday() { // Arrange var firstMondayDate = new DateTime(2017, 3, 5); var today = new DateTime(2017, 3, 4); var startDate = firstMondayDate.AddDays(2); var repeatType = RepeatType.Mon | RepeatType.Wed; var daysToRepeat = 3; var model = Mock.Create <IHabitModel>(); Mock.Arrange(() => model.RepeatType).Returns(repeatType); Mock.Arrange(() => model.DaysToRepeat).Returns(daysToRepeat); Mock.Arrange(() => model.StartDate).Returns(startDate); Mock.Arrange(() => _dateProvider.Now).Returns(today); // Act var habit = new HabitViewModel(_dateProvider, _habitService, _navigationService, model); // Assert Assert.IsNotNull(habit.Filling); Assert.AreEqual(0, habit.Filling.Count()); }
public HabitProgressPage(HabitViewModel habit) { ViewModel = new HabitProgressViewModel(((App)Application.Current).HabitService, habit); InitializeComponent(); SetupProgressChart(); }
private void RemoveHabit(HabitViewModel habit) { var habitItem = FindHabitItem(habit); habitItem.IsVisible = false; }