Exemplo n.º 1
0
 public static string GetClassNamesForStatisticsChangeType(StatisticsChangeType changeType)
 {
     return(changeType == StatisticsChangeType.Increasing ? "color-green glyphicon glyphicon-arrow-up" : changeType == StatisticsChangeType.Decreasing ? "color-red glyphicon glyphicon-arrow-down" : string.Empty);
 }
        public void GetWeeklyUserLoginStatistics(int weekBefore, int thisWeek, decimal expectedPercentageDiff, StatisticsChangeType expectedChangeType)
        {
            List <UserLoginLogEntry> usersLogIn = new List <UserLoginLogEntry>();

            for (int i = 1; i <= weekBefore; i++)
            {
                usersLogIn.Add(new UserLoginLogEntry {
                    LoggedInAt = dateIn_14_DaysRange, UserId = i
                });
            }
            for (int i = weekBefore + 1; i <= (weekBefore + thisWeek); i++)
            {
                usersLogIn.Add(new UserLoginLogEntry {
                    LoggedInAt = dateIn_7_DaysRange, UserId = i
                });
            }
            _tolkDbContext.UserLoginLogEntries.AddRange(usersLogIn);

            _tolkDbContext.SaveChanges();
            WeeklyStatisticsModel ws = _statService.GetWeeklyUserLogins(breakDate);

            Assert.Equal(expectedPercentageDiff, ws.DiffPercentage);
            Assert.Equal(expectedChangeType, ws.ChangeType);
            _tolkDbContext.UserLoginLogEntries.RemoveRange(usersLogIn);
            _tolkDbContext.SaveChanges();
        }
        public void GetWeeklyComplaintStatistics(int weekBefore, int thisWeek, decimal expectedPercentageDiff, StatisticsChangeType expectedChangeType)
        {
            var complaints = _tolkDbContext.Complaints.ToList();

            //reset the date for all complaints
            foreach (Complaint c in complaints)
            {
                c.CreatedAt = resetDate;
            }
            for (int i = 1; i <= weekBefore; i++)
            {
                complaints[i].CreatedAt = dateIn_14_DaysRange;
            }
            for (int i = weekBefore + 1; i <= (weekBefore + thisWeek); i++)
            {
                complaints[i].CreatedAt = dateIn_7_DaysRange;
            }
            _tolkDbContext.SaveChanges();
            WeeklyStatisticsModel ws = _statService.GetWeeklyComplaintStatistics(breakDate);

            Assert.Equal(expectedPercentageDiff, ws.DiffPercentage);
            Assert.Equal(expectedChangeType, ws.ChangeType);
        }
        public void GetWeeklyStatistics(int weekBefore, int thisWeek, decimal expectedPercentageDiff, StatisticsChangeType expectedChangeType)
        {
            WeeklyStatisticsModel ws = StatisticsService.GetWeeklyStatistics(weekBefore, thisWeek, string.Empty);

            Assert.Equal(expectedPercentageDiff, ws.DiffPercentage);
            Assert.Equal(expectedChangeType, ws.ChangeType);
        }
        public void GetWeeklyDeliveredOrderStatistics(int weekBefore, int thisWeek, decimal expectedPercentageDiff, StatisticsChangeType expectedChangeType)
        {
            var orders = _tolkDbContext.Orders.ToList();

            //reset the date and set correct status for all orders
            foreach (Order o in orders)
            {
                o.StartAt = resetDate;
                o.EndAt   = resetDate.AddHours(2);
                o.Status  = OrderStatus.Delivered;
            }
            for (int i = 1; i <= weekBefore; i++)
            {
                orders[i].StartAt = dateIn_14_DaysRange;
                orders[i].EndAt   = dateIn_14_DaysRange.AddHours(2);
            }
            for (int i = weekBefore + 1; i <= (weekBefore + thisWeek); i++)
            {
                orders[i].StartAt = dateIn_7_DaysRange;
                orders[i].EndAt   = dateIn_7_DaysRange.AddHours(2);
            }
            _tolkDbContext.SaveChanges();
            WeeklyStatisticsModel ws = _statService.GetWeeklyDeliveredOrderStatistics(breakDate);

            Assert.Equal(expectedPercentageDiff, ws.DiffPercentage);
            Assert.Equal(expectedChangeType, ws.ChangeType);
        }