public void CheckHabit2() { Guid habit_id = Guid.NewGuid(); Guid user_id = Guid.NewGuid(); DateTime now = DateTime.Now; Days[] dayoff = new Days[] { new Days("Mon"), new Days("Sun") }; Habit h = new Habit(habit_id, "Nyanyi", dayoff, user_id, now); h.DoHabit(DateTime.Now.AddDays(0)); //Sun // h.DoHabit(DateTime.Now.AddDays(1)); //Mon h.DoHabit(DateTime.Now.AddDays(3)); //Wed h.DoHabit(DateTime.Now.AddDays(4)); //Thu h.DoHabit(DateTime.Now.AddDays(6)); //Sun h.DoHabit(DateTime.Now.AddDays(7)); //Sun HabitLogMemento hm = (HabitLogMemento)h.HabitLog.GetMemento(); Assert.Equal(2, hm.longest_streak); Assert.Equal(2, hm.current_streak); Assert.Equal(5, hm.log_count); }
// [Fact] public void GiveEpicComeback() { NpgsqlConnection _connection = new NpgsqlConnection(connString); _connection.Open(); IHabitRepository repo = new PostgresHabitRepository(_connection, null); Guid id = new Guid("41684bad-554b-4194-8fc2-d192273b9aa8"); Guid userID = new Guid("e28c8034-f90d-48aa-8e55-2aad1282f3bd"); Habit habit = repo.FindHabitByID(id, userID); DateTime now = DateTime.Now; habit.DoHabit(now); repo.DoHabit(habit, now); for (int i = 10; i < 20; i++) { now = DateTime.Now.AddDays(i); habit.DoHabit(now); repo.DoHabit(habit, now); } Habit habit2 = repo.FindHabitByID(id, userID); _connection.Close(); HabitLogMemento hm = (HabitLogMemento)habit2.HabitLog.GetMemento(); // Habit habit2 = repo.FindHabitByID(id, userID); // Badge badge = bRepo.FindByUserID(userID); // Assert.Equal("Dominating", badge.Name); _connection.Close(); }
public ActionResult <HabitAPI> Log(Guid userID, Guid id) { NpgsqlConnection _connection = new NpgsqlConnection(connString); _connection.Open(); IHabitRepository repo = new PostgresHabitRepository(_connection, null); Habit habit = repo.FindHabitByID(id, userID); DateTime now = DateTime.Now; habit.DoHabit(now); repo.DoHabit(habit, now); Habit habit2 = repo.FindHabitByID(id, userID); _connection.Close(); HabitLogMemento hm = (HabitLogMemento)habit2.HabitLog.GetMemento(); return(new HabitAPI { ID = hm.id, Name = habit2.Name, DaysOff = changeToString(habit2.DaysOff), LogCount = hm.log_count, CurrentStreak = hm.current_streak, LongestStreak = hm.longest_streak, Logs = hm.logs, UserID = hm.user_id, CreatedAt = habit2.CreatedAt }); }
public void CheckHabit() { Guid habit_id = Guid.NewGuid(); Guid user_id = Guid.NewGuid(); DateTime now = DateTime.Now; Days[] dayoff = new Days[] { new Days("Mon"), new Days("Tue") }; Habit h = new Habit(habit_id, "Nyanyi", dayoff, user_id, now); for (int i = 0; i < 2; i++) { h.DoHabit(DateTime.Now.AddDays(i)); } for (int i = 4; i < 5; i++) { h.DoHabit(DateTime.Now.AddDays(i)); } HabitLogMemento hm = (HabitLogMemento)h.HabitLog.GetMemento(); Assert.Equal(2, hm.longest_streak); Assert.Equal(1, hm.current_streak); Assert.Equal(3, hm.log_count); }