예제 #1
0
        public void GetOverallNumberOfRequestsForTodayTest()
        {
            var overallViewModel = new OverallViewModel("1");

            var tempUser1 = new User { UserId = "User1", Name = "User1", IsApproved = true };

            var tempUser2 = new User { UserId = "User2", Name = "User2", IsApproved = true };

            Assert.AreEqual(overallViewModel.GetOverallNumberOfRequestsForToday(),0);

            overallViewModel.AddUserStats(tempUser1, 120, 70, DateTime.Today);

            overallViewModel.AddUserStats(tempUser2, 60, 60, DateTime.Today);

            Assert.AreEqual(130,overallViewModel.GetOverallNumberOfRequestsForToday());
        }
예제 #2
0
        public ActionResult Overall()
        {
            var activitiesByUser = this.SecurityStorage
                .GetUserActivities()
                .AsParallel()
                .GroupBy(ua => ua.UserRef)
                .Select(g => new
                    {
                        UserRef = g.Key,
                        TotalNumberOfRequests = g.Count(),
                        TodayNumberOfRequests = g.Count(ua => ua.RequestStartTime.Date == DateTime.Today),
                        LastActivityTime = g.Max(ua => ua.RequestStartTime)
                    });

            var userService = SecurityPlugin.Container.Resolve<IUserService>();
            var users = userService.GetUsers().ToList();
            
            var model = new OverallViewModel();
            
            foreach (var stats in activitiesByUser.OrderBy(x => x.UserRef))
            {
                model.AddUserStats(
                    users.FirstOrDefault(u => u.Id == stats.UserRef),
                    stats.TotalNumberOfRequests,
                    stats.TodayNumberOfRequests,
                    stats.LastActivityTime);
            }

            return View(model);
        }
예제 #3
0
        public void GetOverallNumberOfRequestsTest()
        {
            var overallViewModel = new OverallViewModel("1");

            var tempUser1 = new User {UserId = "user1",Name = "User1", IsApproved = true};

            var tempUser2 = new User {UserId = "user2",Name = "User2", IsApproved = true };

            //Must be zero;
            Assert.AreEqual(overallViewModel.GetOverallNumberOfRequests(), 0);

            overallViewModel.AddUserStats(tempUser1, 120, 70, DateTime.Today);

            overallViewModel.AddUserStats(tempUser2, 60, 60, DateTime.Today);

            //Check if request of all users are summed;
            Assert.AreEqual(overallViewModel.GetOverallNumberOfRequests(), 180);
        }
예제 #4
0
        public void GetStatsTest()
        {
            var overallViewModel = new OverallViewModel("1");

            var tempUser = new User { UserId = "user1", Name = "User1", IsApproved = true };

            overallViewModel.AddUserStats(tempUser, 120, 70, DateTime.Today);

            Assert.True(overallViewModel.GetStats().Count(s => s.User.UserId == "user1")==1);

            Assert.True(overallViewModel.GetStats().Count(s => s.User.UserId == "user15") == 0);
        }
예제 #5
0
        public void AddUserStatsTest()
        {
            var overallViewModel = new OverallViewModel("1");

            var tempUser = new User {UserId = "User1", Name = "User1", IsApproved = true};

            Assert.AreEqual(overallViewModel.GetOverallNumberOfRequests(), 0);

            overallViewModel.AddUserStats(tempUser, 120, 70, DateTime.Today);

            Assert.True(overallViewModel.GetStats().Count(s => s.User.UserId == "User1") == 1);

            Assert.AreEqual(overallViewModel.GetOverallNumberOfRequests(),120);
        }
예제 #6
0
 public void AddUserStats(OverallViewModel model, User user, int totalRequests,
     int todayRequests, DateTime lastActivity)
 {
     model.AddUserStats(user, totalRequests, todayRequests, lastActivity);
 }
예제 #7
0
        public void GetUserActivityTest()
        {
            var overallViewModel = new OverallViewModel("1");

            var tempUser1 = new User { UserId = "user1", Name = "User1", IsApproved = true };

            var tempUser2 = new User { UserId = "user2", Name = "User2", IsApproved = true };

            overallViewModel.AddUserStats(tempUser1, 120, 70, DateTime.Today);

            overallViewModel.AddUserStats(tempUser2, 60, 60, DateTime.Today);

            Assert.True(overallViewModel.GetUserActivity("user1").Sum(s => s.TotalNumberOfRequests) == 120);
        }