示例#1
0
        public void Models_LeaderBoardModel_Default_Instantiate_Should_Pass()
        {
            // Act
            var result = new LeaderBoardModel();

            // Assert
            Assert.IsNotNull(result, TestContext.TestName);
        }
示例#2
0
        private async void UpdateLeaderBoard()
        {
            try
            {
                if (!string.IsNullOrEmpty(goal.ChallengeId))
                {
                    competitors.Clear();
                    leaderboardCollectionView.ItemsSource = null;
                    var goals = await App.client.GetTable <GoalModel>().Where(g => g.ChallengeId == goal.ChallengeId).Where(g => g.Deadline == goal.Deadline).ToListAsync();

                    if (goals != null)
                    {
                        foreach (GoalModel g in goals)
                        {
                            var user = (await App.client.GetTable <UserModel>().Where(u => u.Id == g.UserId).ToListAsync()).FirstOrDefault();

                            LeaderBoardModel competitor = new LeaderBoardModel()
                            {
                                Name      = user.FirstName + " " + user.LastName,
                                Progress  = g.Progress,
                                Completed = g.Completed,
                                Accepted  = !g.GoalAccepted
                            };
                            competitors.Add(competitor);
                        }
                        competitors.Sort((x, y) => y.Progress.CompareTo(x.Progress));

                        for (int i = 1; i <= competitors.Count; i++)
                        {
                            competitors[i - 1].Placing = i;
                        }
                        leaderboardCollectionView.ItemsSource   = competitors;
                        leaderboardCollectionView.HeightRequest = competitors.Count * 50 + 20;
                    }
                }
            }
            catch (Exception ex)
            {
                await DisplayAlert("Error", ex.ToString(), "Ok");

                var properties = new Dictionary <string, string> {
                    { "GoalDetailPage", "On appearing" }
                };
                Crashes.TrackError(ex, properties);
            }
        }
示例#3
0
        public void Models_LeaderBoardModel_Update_With_Invalid_Data_Null_Should_Fail()
        {
            // Arrange

            var expect = "test";

            var data = new LeaderBoardModel
            {
                Id = "test"
            };

            // Act
            data.Update(null);
            var result = data.Id;

            // Assert
            Assert.AreEqual(expect, result, TestContext.TestName);
        }
示例#4
0
        public void Models_LeaderBoardModel_Instantiate_Valid_Should_Pass()
        {
            // Arrange
            var expectProfit = 0;
            var expectName   = "name";
            var test         = new LeaderBoardModel
            {
                Name   = expectName,
                Profit = expectProfit
            };

            // Act
            var result = new LeaderBoardModel(test);

            // Assert
            Assert.AreEqual(expectProfit, result.Profit, TestContext.TestName);
            Assert.AreEqual(expectName, result.Name, TestContext.TestName);
        }
        protected override async void OnAppearing()
        {
            base.OnAppearing();

            try
            {
                if (!string.IsNullOrEmpty(goal.ChallengeId))
                {
                    var goals = await App.client.GetTable <GoalModel>().Where(g => g.ChallengeId == goal.ChallengeId).ToListAsync();

                    if (goals != null)
                    {
                        foreach (GoalModel g in goals)
                        {
                            var user = (await App.client.GetTable <UserModel>().Where(u => u.Id == g.UserId).ToListAsync()).FirstOrDefault();

                            LeaderBoardModel competitor = new LeaderBoardModel()
                            {
                                Name     = user.FirstName + " " + user.LastName,
                                Progress = g.Progress
                            };

                            competitors.Add(competitor);
                        }
                        competitors.Sort((x, y) => y.Progress.CompareTo(x.Progress));

                        for (int i = 1; i <= competitors.Count; i++)
                        {
                            competitors[i - 1].Placing = i;
                        }
                    }
                    leaderboardCollectionView.ItemsSource = competitors;
                }
            }
            catch (Exception ex)
            {
                var properties = new Dictionary <string, string> {
                    { "Leaderboard page", "On appearing" }
                };
                Crashes.TrackError(ex, properties);
            }
        }
示例#6
0
        public void Models_LeaderBoardModel_Update_With_Valid_Data_Should_Pass()
        {
            // Arrange
            var expectProfit = 0;
            var expectName   = "Name";

            var data = new LeaderBoardModel();

            var test = new LeaderBoardModel
            {
                Profit = expectProfit,
                Name   = expectName
            };

            // Act
            data.Update(test);
            var result = data;

            // Assert
            Assert.AreEqual(expectProfit, result.Profit, "Profit " + TestContext.TestName);
            Assert.AreEqual(expectName, result.Name, "Name " + TestContext.TestName);
        }
示例#7
0
        public List <LeaderBoardModel> GetLeaderBoard()
        {
            var board = new List <LeaderBoardModel>();
            var data  = DataSourceBackend.Instance.StudentBackend.Index();

            // Get Student
            foreach (var student in data)
            {
                var temp = new LeaderBoardModel
                {
                    Id     = student.Id,
                    Name   = student.Name,
                    Profit = student.Truck.Income
                };
                board.Add(temp);
            }

            // Sort leaderboard by profit
            board = board.OrderByDescending(x => x.Profit).ToList();

            return(board);
        }