public async Task UpdateHabitsAsync_WithCorrectData_ShouldReturnCorrectResult() { var color = new Color { Id = 1, Name = "Test", Hex = "TestHex", }; var calendar = new Calendar { Id = "CalendarId", Title = "Default", DefaultCalendarColor = color, DefaultCalendarColorId = color.Id, }; var goal = new Goal { Id = "TestId", Title = "Test", Calendar = calendar, CalendarId = calendar.Id, IsActive = true, Color = color, ColorId = color.Id, }; var habit = new Habit { Id = "TestId", Title = "Test", StartDateTime = new DateTime(2020, 02, 02, 12, 0, 0), EndDateTime = new DateTime(2020, 02, 02, 12, 30, 0), GoalId = goal.Id, Goal = goal, IsCompleted = false, }; var currentDate = DateTime.Parse("02/02/2020"); var startEndDatetime = new StartEndDateTime { Start = new DateTime(2020, 02, 02, 12, 0, 0), End = new DateTime(2020, 02, 02, 12, 30, 0), }; this.dateTimeService .Setup(x => x.GenerateDatesForMonthAhead(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <DateTime>())) .Returns(new List <StartEndDateTime> { startEndDatetime }); this.habitsRepository.Setup(x => x.All()).Returns(new List <Habit> { habit }.AsQueryable()); var result = await this.habitService.UpdateHabitsAsync(goal, habit.Id); this.habitsRepository.Verify(x => x.All(), Times.Exactly(2)); this.habitsRepository.Verify(x => x.SaveChangesAsync(), Times.Exactly(2)); }
public async Task GenerateMoreHabitsAsync_WithCorrectData_ShouldReturnCorrectResult() { var color = new Color { Id = 1, Name = "Test", Hex = "TestHex", }; var calendar = new Calendar { Id = "CalendarId", Title = "Default", DefaultCalendarColor = color, DefaultCalendarColorId = color.Id, }; var goal = new Goal { Id = "TestId", Title = "Test", Calendar = calendar, CalendarId = calendar.Id, IsActive = true, Color = color, ColorId = color.Id, }; var currentDate = DateTime.Parse("02/02/2020"); var lastGeneratedWeek = DateTime.Parse("02/02/2020"); var firstDate = DateTime.Parse("03/02/2020"); var startEndDatetime = new StartEndDateTime { Start = new DateTime(2020, 02, 02, 12, 0, 0), End = new DateTime(2020, 02, 02, 12, 30, 0), }; this.dateTimeService .Setup(x => x.FirstDayOfWeekAfhterMonth(It.IsAny <DateTime>())) .Returns(lastGeneratedWeek); this.dateTimeService .Setup(x => x.FirstDayOfWeek(It.IsAny <DateTime>())) .Returns(firstDate); this.dateTimeService .Setup(x => x.GenerateDatesForMonthAhead(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <DateTime>())) .Returns(new List <StartEndDateTime> { startEndDatetime }); var result = await this.habitService.GenerateMoreHabitsAsync(goal, currentDate); this.habitsRepository.Verify(x => x.AddAsync(It.IsAny <Habit>()), Times.Once); this.habitsRepository.Verify(x => x.SaveChangesAsync(), Times.Once); }
public void GetDetailsViewModelById_WithSameStartAndLastWeek_ShouldReturnCorrectResult() { var color = new Color { Id = 1, Name = "Test", Hex = "TestHex", }; var calendar = new Calendar { Id = "CalendarId", Title = "Default", DefaultCalendarColor = color, DefaultCalendarColorId = color.Id, }; var goal = new Goal { Id = "TestId", Title = "Test", StartDateTime = new DateTime(2020, 02, 04, 12, 0, 0), Calendar = calendar, CalendarId = calendar.Id, IsActive = true, Color = color, ColorId = color.Id, }; var habit = new Habit { Id = "Test1", Title = "Test", StartDateTime = new DateTime(2020, 02, 02, 12, 0, 0), EndDateTime = new DateTime(2020, 02, 02, 12, 30, 0), GoalId = goal.Id, Goal = goal, IsCompleted = false, }; var habitCompleted = new Habit { Id = "Test2", Title = "Test", StartDateTime = new DateTime(2020, 02, 02, 12, 0, 0), EndDateTime = new DateTime(2020, 02, 02, 12, 30, 0), GoalId = goal.Id, Goal = goal, IsCompleted = true, }; var mondayHabit = DateTime.Parse("03/02/2020"); var mondayGoal = DateTime.Parse("27/01/2020"); var firstDate = DateTime.Parse("02/02/2020"); var startEndDatetime = new StartEndDateTime { Start = new DateTime(2020, 02, 02, 12, 0, 0), End = new DateTime(2020, 02, 02, 12, 30, 0), }; this.habitsRepository .Setup(x => x.All()) .Returns(new List <Habit> { habit, habitCompleted }.AsQueryable()); this.dateTimeService .Setup(x => x.FirstDayOfWeek(habit.StartDateTime)) .Returns(mondayHabit); this.dateTimeService .Setup(x => x.FirstDayOfWeek(goal.StartDateTime)) .Returns(mondayGoal); this.dateTimeService .Setup(x => x.GenerateDatesForMonthAhead(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <DateTime>())) .Returns(new List <StartEndDateTime> { startEndDatetime }); var result = this.habitService.GetDetailsViewModelById(habit.Id); Assert.Equal(4, result.CompletedHabitsForWeeks.Count); }