コード例 #1
0
        public void HabitTrackTest()
        {
            User         popo = User.NewUser("Popo");
            List <Habit> list = new List <Habit>();

            Habit habit  = Habit.addNewHabit(popo.ID, "Belajar", new string[] { "Tue", "Wed" });
            Habit habit2 = Habit.addNewHabit(popo.ID, "Mandi", new string[] { "Mon" });

            list.Add(habit);
            list.Add(habit2);

            string name = null;

            foreach (var i in list)
            {
                if (i.Name == habit.Name)
                {
                    name = i.Name;
                    break;
                }
            }

            Assert.NotNull(list);
            Assert.Equal(name, habit.Name);
        }
コード例 #2
0
        public ActionResult <Habit> UpdateHabit(Guid userID, Guid id, [FromBody] RequestData data)
        {
            string name = data.UpdateName;

            string[] off = data.UpdateDaysOff;

            Habit toUpdateHabit = Habit.addNewHabit(userID, name, off);

            if (toUpdateHabit == null)
            {
                return(NotFound("Invalid Habit format to update"));
            }

            NpgsqlConnection _connection = new NpgsqlConnection(_connstringgg);

            _connection.Open();

            IHabitRepository repo = new PostgresHabitRepository(_connection, null);

            Habit toUpdate = repo.FindByIdAndUserId(id, userID);

            if (toUpdate == null)
            {
                return(NotFound("Habit is not founded"));
            }

            repo.UpdateHabit(toUpdate, toUpdateHabit.Name, toUpdateHabit.DayOff);
            if (data.UpdateName.Equals(toUpdate.Name))
            {
                return(NotFound("Habit is not updated"));
            }
            toUpdate = repo.FindByIdAndUserId(id, userID);

            return(toUpdate);
        }
コード例 #3
0
        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();
        }
コード例 #4
0
        public void testtesttest()
        {
            User popo = User.NewUser("Popo");

            List <Habit> habits  = new List <Habit>();
            Habit        belajar = Habit.addNewHabit(popo.ID, "Belajar", new string[] { "Sat", "Sun" });

            habits.Add(belajar);
            AbcApplication daily = new HabitTracker(habits);
        }
コード例 #5
0
        public ActionResult <Habit> AddNewHabit(Guid userID, [FromBody] RequestData data)
        {
            Habit habit = Habit.addNewHabit(userID, data.Name, data.DaysOff);

            if (habit.DayOff == null)
            {
                return(NotFound("Habit is Invalid"));
            }

            NpgsqlConnection _connection = new NpgsqlConnection(_connstringgg);

            _connection.Open();

            IHabitRepository repo = new PostgresHabitRepository(_connection, null);

            repo.Create(habit);

            return(habit);
        }
コード例 #6
0
        public void TrackerTest()
        {
            User popo = User.NewUser("Popo");

            List <Habit> habits    = new List <Habit>();
            Habit        belajar   = Habit.addNewHabit(popo.ID, "Belajar", new string[] { "Sat", "Sun" });
            Habit        olahraga  = Habit.addNewHabit(popo.ID, "Olahraga", new string[] { "Mon" });
            Habit        main_game = Habit.addNewHabit(popo.ID, "Main Game", new string[] { "Mon" });

            habits.Add(belajar);
            habits.Add(olahraga);
            habits.Add(main_game);

            AbcApplication daily = new HabitTracker(habits);

            daily.Do(new HabitTrack(belajar, popo.ID, new DateTime(2020, 3, 1)));
            daily.Do(new HabitTrack(belajar, popo.ID, new DateTime(2020, 3, 2)));
            daily.Do(new HabitTrack(belajar, popo.ID, new DateTime(2020, 3, 3)));
            daily.Do(new HabitTrack(belajar, popo.ID, new DateTime(2020, 3, 4)));
            daily.Do(new HabitTrack(belajar, popo.ID, new DateTime(2020, 3, 5)));
            daily.Do(new HabitTrack(belajar, popo.ID, new DateTime(2020, 3, 6)));
        }