Example #1
0
        public void CompletedGoalsCount_IsCorrect_AfterAddingCompleteGoal()
        {
            Day       day  = new Day(sampleDate);
            DailyGoal goal = new DailyGoal("", true);

            day.Goals.Add(goal);

            Assert.That(day.CompletedGoalsCount, Is.EqualTo(1));
        }
Example #2
0
        public void CompletedGoalsCount_IsZero_AfterAddingIncompleteGoals()
        {
            Day       day  = new Day(sampleDate);
            DailyGoal goal = new DailyGoal("");

            day.Goals.Add(goal);

            Assert.That(day.CompletedGoalsCount, Is.Zero);
        }
Example #3
0
        public void CompletedGoalsCount_IsZero_AfterRemovingGoal()
        {
            Day       day  = new Day(sampleDate);
            DailyGoal goal = new DailyGoal("", true);

            day.Goals.Add(goal);
            day.Goals.Remove(goal);

            Assert.That(day.CompletedGoalsCount, Is.Zero);
        }
Example #4
0
        public void CompletedGoalsCount_IsZero_AfterUpdatingGoal()
        {
            Day       day  = new Day(sampleDate);
            DailyGoal goal = new DailyGoal("", true);

            day.Goals.Add(goal);
            goal.SetCompleted(false);

            Assert.That(day.CompletedGoalsCount, Is.Zero);
        }
Example #5
0
        public void DeleteGoalData_DailyGoal_DoDeleteOnStartDate()
        {
            GoalTrackerService gts  = GetEmptyGTS();
            DailyGoal          goal = gts.CreateDailyGoal("goal");
            Day day = gts.CreateDay(date);

            gts.DeleteGoalData(goal, date);

            Assert.That(day.GoalsCount, Is.Zero);
        }
Example #6
0
        public void DeleteGoal_DoNotAddToRemovedGoals_IfNoDataRemains()
        {
            GoalTrackerService gts = GetEmptyGTS();

            gts.CreateDay(date);
            DailyGoal goal = gts.CreateDailyGoal("goal");

            gts.DeleteGoal(goal);

            Assert.That(!gts.HasRemovedGoal(goal.Name, Goal.GoalType.Daily));
        }
Example #7
0
        public void DeleteGoalData_DailyGoal_DoNotDeleteBeforeStartDate()
        {
            GoalTrackerService gts  = GetEmptyGTS();
            DailyGoal          goal = gts.CreateDailyGoal("goal");
            Day day = gts.CreateDay(date);

            gts.CreateDay(date.AddDays(1));

            gts.DeleteGoalData(goal, date.AddDays(1));

            Assert.That(day.GoalsCount, Is.GreaterThan(0));
        }
Example #8
0
        public void DeleteGoalData_DailyGoal_RemoveGoalFromRemovedGoals_WhenDeletedFromAllDays()
        {
            GoalTrackerService gts  = GetEmptyGTS();
            DailyGoal          goal = gts.CreateDailyGoal("goal");

            gts.CreateDailyGoal("goal2");
            gts.CreateDay(date);
            gts.DeleteGoal(goal);

            gts.DeleteGoalData(goal, date);

            Assert.That(gts.HasRemovedGoal(goal.Name, Goal.GoalType.Daily), Is.False);
        }
Example #9
0
        public void DeleteGoalData_DailyGoal_RemoveDaysWithNoRemainingGoalData()
        {
            GoalTrackerService gts  = GetEmptyGTS();
            DailyGoal          goal = gts.CreateDailyGoal("goal");

            gts.CreateDay(date);
            EventRaisedTester daysChangedRaised = new EventRaisedTester(handler => gts.DaysChanged += handler);

            gts.DeleteGoalData(goal, date);

            Assert.That(gts.GetDayForDate(date), Is.Null);
            Assert.That(daysChangedRaised.TimesRaised, Is.EqualTo(1));
        }
Example #10
0
        // Converts an array of ints into a Day object; each 0 in the input array represents an incomplete goal,
        // and each 1 (or other nonzero int) represents a completed goal.
        private static Day GetDayWithGoalsFromInts(int[] goalsListAsInts)
        {
            Day day = new Day(new DateTime(2020, 9, 17));

            for (int i = 0; i < goalsListAsInts.Length; i++)
            {
                bool      isComplete = goalsListAsInts[i] != 0;
                DailyGoal g          = new DailyGoal("goal", isComplete);
                day.Goals.Add(g);
            }

            return(day);
        }
Example #11
0
        public void CreateDay_DayHasAllCurrentDailyGoals()
        {
            GoalTrackerService gts         = GetEmptyGTS();
            DailyGoal          goal1       = gts.CreateDailyGoal("goal");
            DailyGoal          goal2       = gts.CreateDailyGoal("goal2");
            DailyGoal          removedGoal = gts.CreateDailyGoal("goal3");

            gts.DeleteGoal(removedGoal);

            Day day = gts.CreateDay(date);

            Assert.That(day.Goals.Contains(goal1));
            Assert.That(day.Goals.Contains(goal2));
            Assert.That(!day.Goals.Contains(removedGoal));
        }
        bool DailyGoalPercentProcess(int intake)
        {
            if (IsAchieveGoal())
            {
                uiState.PushNewState(UIStateEnum.eDailyGoal100CompleteNotify, dataManager.missionId);
            }
            else
            {
                dataManager.currIntake += intake;

                uiState.PushNewState(UIStateEnum.eDailyProcessIncrease, dataManager.percentOfDailyGoal);
                for (int i = 0; i < CrownPersent.Length; ++i)
                {
                    if (!dataManager.DidCrownGet(i))
                    {
                        if (dataManager.percentOfDailyGoal >= CrownPersent[i])
                        {
                            ++dataManager.todayCrownGotCount;
                            ++dataManager.CrownCount;
                            dataManager.TrySendPlayerData2Server();
                            int        expDelta   = dataManager.GetDailyGoalExp(this.CrownPersent[i]);                                      //计算获取的经验
                            DailyGoal  dailyGoal  = this.LevelConfig.GetLevelDailyGoal(this.dataManager.playerLevel, this.CrownPersent[i]); //获取当前等级与当日饮水进度对应的配饰数据
                            AwardDatas awardDatas = this.AwardDataHelper.GetAwards(dailyGoal.Coin, dailyGoal.Award);                        //根据获得的奖励的总价值及奖品产出规则,计算获得的金币及道具
                            if (awardDatas != null && awardDatas.Datas != null)
                            {
                                awardDatas.Datas.ForEach(t => this.AwardDataHelper.AddItem(t));//记录获得的金币和道具(食物,材料等)
                            }
                            uiState.PushNewState(UIStateEnum.eDailyGoalCrownComplete, i, expDelta, true, awardDatas);
                            AddCrownItem(i);
                            dataManager.exp += expDelta;
                            uiState.PushNewState(UIStateEnum.eExpIncrease, GetExpPercent());
                            RefreshLevelAfterExpChange();
                            if (i == CrownPersent.Length - 1)
                            {
                                uiState.PushNewState(UIStateEnum.eDailyGoal100CompleteNotify, dataManager.missionId);
                            }
                            else
                            {
                                uiState.PushNewState(UIStateEnum.eDailyProcessIncrease, dataManager.percentOfDailyGoal);
                            }
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
        private void AddGoal()
        {
            Console.WriteLine("AddGoal");
            if (gtService.HasRemovedGoal(Name, IsWeekly ? GoalType.Weekly : GoalType.Daily))
            {
                MessageBoxResult result = ConfirmMerge();
                if (result == MessageBoxResult.Cancel)
                {
                    return;
                }
            }

            if (IsWeekly)
            {
                WeeklyGoal goal = gtService.CreateWeeklyGoal(Name, WeeklyTarget);
                if (goal == null)
                {
                    AlertDuplicateGoalName();
                    return;
                }

                if (AddData)
                {
                    gtService.AddGoalToWeeks(goal, AddDataStartDate);
                }
            }
            else
            {
                DailyGoal goal = gtService.CreateDailyGoal(Name);
                Console.WriteLine("goal = " + goal + ", AddData = " + AddData);
                if (goal == null)
                {
                    AlertDuplicateGoalName();
                    return;
                }

                if (AddData)
                {
                    Console.WriteLine("Adding data");
                    gtService.AddGoalToDays(goal, AddDataStartDate);
                }
            }

            RequestClose?.Invoke();
        }
Example #14
0
        public void RemoveGoals_DoesNotDeleteData_WhenDeleteDataEntriesIsFalse()
        {
            Mock <IGoalTrackerService> mockGts = new Mock <IGoalTrackerService>();
            RemoveGoalWindowViewModel  vm      = new RemoveGoalWindowViewModel(mockGts.Object, new Mock <IWindowService>().Object)
            {
                DeleteAfterDate   = DateTime.MinValue,
                DeleteDataEntries = false
            };
            DailyGoal goal = new DailyGoal("goal");

            vm.RemoveGoalsCommand.Execute(new List <Goal>()
            {
                goal
            });

            mockGts.Verify(mock => mock.DeleteGoal(goal), Times.Once);
            mockGts.Verify(mock => mock.DeleteGoalData(goal, It.IsAny <DateTime>()), Times.Never);
        }
Example #15
0
        public void RemoveGoals_DeletesOnlyAfterDate_WhenDeleteAllIsFalse()
        {
            Mock <IGoalTrackerService> mockGts = new Mock <IGoalTrackerService>();
            RemoveGoalWindowViewModel  vm      = new RemoveGoalWindowViewModel(mockGts.Object, new Mock <IWindowService>().Object)
            {
                DeleteAfterDate   = testDate,
                DeleteDataEntries = true,
                DeleteAll         = false
            };
            DailyGoal goal = new DailyGoal("goal");

            vm.RemoveGoalsCommand.Execute(new List <Goal>()
            {
                goal
            });

            mockGts.Verify(mock => mock.DeleteGoalData(goal, testDate), Times.Once);
        }
Example #16
0
        public void Day_Deserialized_Equals_Serialized()
        {
            DataContractSerializer serializer = new DataContractSerializer(typeof(Day));
            Day       day  = new Day(sampleDate);
            DailyGoal goal = new DailyGoal("", true);

            day.Goals.Add(goal);

            using (FileStream file = File.Create(testPath))
            {
                serializer.WriteObject(file, day);
            }

            Day deserialized;

            using (FileStream file = File.OpenRead(testPath))
            {
                deserialized = (Day)serializer.ReadObject(file);
            }

            Assert.That(day.Date, Is.EqualTo(deserialized.Date));
            Assert.That(day.Goals, Is.EqualTo(deserialized.Goals));
        }
Example #17
0
 public DailyGoalViewModel(DailyGoal goal)
 {
     this.goal = goal;
 }