// [Fact] public void GiveDominating() { NpgsqlConnection _connection = new NpgsqlConnection(connString); _connection.Open(); IHabitRepository repo = new PostgresHabitRepository(_connection, null); IBadgeRepository bRepo = new PostgresBadgeRepository(_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); for (int i = 0; i < 4; i++) { DateTime now = DateTime.Now.AddDays(i); habit.DoHabit(now); repo.DoHabit(habit, now); } // Habit habit2 = repo.FindHabitByID(id, userID); // Badge badge = bRepo.FindByUserID(userID); // Assert.Equal("Dominating", badge.Name); _connection.Close(); }
public void CreateBadge() { NpgsqlConnection _connection = new NpgsqlConnection(_connstring); _connection.Open(); IBadgeRepository repo = new PostgresBadgeRepository(_connection, null); }
public void CheckAchievementDominating() { IAchievementGainer _dominate = new DominatingGain(); NpgsqlConnection connection = new NpgsqlConnection(_connstring); connection.Open(); User popo = User.NewUser("Popo"); IHabitRepository habitRepo = new PostgresHabitRepository(connection, null); IBadgeRepository badgeRepo = new PostgresBadgeRepository(connection, null); Habit belajar = Habit.addNewHabit(popo.ID, "Belajar", new string[] { "Sat", "Mon" }); habitRepo.Create(belajar); Habit olahraga = Habit.addNewHabit(popo.ID, "Olahraga", new string[] { "Mon" }); habitRepo.Create(olahraga); List <Habit> habitList = new List <Habit>(); habitList.Add(belajar); habitList.Add(olahraga); AbcApplication daily = new HabitTracker(habitList); ILogsRepository repoLogs = new PostgresLogsRepository(connection, null); Track track; track = new HabitTrack(belajar, popo.ID, new DateTime(2020, 3, 1)); daily.Do(track); repoLogs.AddLogs(track); track = new HabitTrack(belajar, popo.ID, new DateTime(2020, 3, 2)); daily.Do(track); repoLogs.AddLogs(track); track = new HabitTrack(belajar, popo.ID, new DateTime(2020, 3, 3)); daily.Do(track); repoLogs.AddLogs(track); track = new HabitTrack(belajar, popo.ID, new DateTime(2020, 3, 4)); daily.Do(track); repoLogs.AddLogs(track); Habit founded_habit = habitRepo.FindByIdAndUserId(belajar.ID, popo.ID); int listSize = founded_habit.Log.GetLogDate.Count; Assert.True(founded_habit.isDominating() == true); if (founded_habit.isDominating()) { badgeRepo.CreateBadge(_dominate.GainAchievement(popo.ID), founded_habit.Log.GetLogDate[listSize - 1]); } connection.Close(); }
public ActionResult <IEnumerable <Badge> > All(Guid userID) { NpgsqlConnection connection = new NpgsqlConnection(_constringg); connection.Open(); IBadgeRepository badgeRepo = new PostgresBadgeRepository(connection, null); List <Badge> founded_badge = badgeRepo.FindByUserId(userID); if (founded_badge == null) { return(NotFound("No Badge in this user")); } return(founded_badge); }
public ActionResult <IEnumerable <BadgeAPI> > All(Guid userID) { NpgsqlConnection _connection = new NpgsqlConnection(connString); _connection.Open(); IBadgeRepository repo = new PostgresBadgeRepository(_connection, null); List <Badge> badge = repo.FindByUserID(userID); List <BadgeAPI> badgeApi = new List <BadgeAPI>(); for (int i = 0; i < badge.Count; i++) { BadgeAPI ba = new BadgeAPI { ID = badge[i].ID, Name = badge[i].Name, Description = badge[i].Description, CreatedAt = badge[i].DateTimeBadge, UserID = badge[i].User_id }; badgeApi.Add(ba); } return(badgeApi); }