Esempio n. 1
0
        public void GetEntryLogswithURL_Pass()
        {
            // Arrange
            string        entryLog = "https://www.endpoint.com";
            bool          expected = true;
            bool          actual   = false;
            string        path     = "C:\\Users\\Midnightdrop\\Documents\\GitHub\\GreetNGroup\\Backend\\UnitTest\\UADTest\\TestLogs\\ServiceLogs\\PassLogs";
            List <GNGLog> logList  = new List <GNGLog>();

            // Act
            logList = _loggerService.ReadLogsPath(path);
            var newLog = _uadService.GetEntryLogswithURL(logList, entryLog);

            if (newLog.Count == 3)
            {
                actual = true;
            }
            // Assert
            Assert.AreEqual(actual, expected);
        }
Esempio n. 2
0
        /// <summary>
        /// Function that returns the top 5 page used for a month
        /// </summary>
        /// <param name="month">referenced month</param>
        /// <param name="year">referenced year</param>
        /// <returns>A list of objects that holds the top 5 page used for a month</returns>
        public List <UADObject> GetTop5AveragePageSession(string month, int year)
        {
            var sessions = new List <GNGLog>();
            var urlPages = new List <string> {
                "https://www.greetngroup.com/search", "https://www.greetngroup.com/createevent", "https://www.greetngroup.com", "https://www.greetngroup.com/help", "https://www.greetngroup.com/faq"
            };
            var averageTimeSpent = new List <double>();
            var monthIndex       = months.IndexOf(month);

            var loglist = _gngLoggerService.ReadLogsGivenMonthYear(months[monthIndex], year);

            // For every URL in the list get the average time spent on it
            for (int j = 0; j < urlPages.Count; j++)
            {
                // Get logs where user enters a url
                var entryToPage = _uadService.GetEntryLogswithURL(loglist, urlPages[j]);
                // Get Logs when user leaves a url
                var exitFromPage = _uadService.GetExitLogswithURL(loglist, urlPages[j]);
                // Pair the exit from pages with the entrance to a page
                sessions = _uadService.PairStartAndEndLogs(entryToPage, exitFromPage);
                if (sessions.Count == 0)
                {
                    averageTimeSpent.Add(0);
                }
                else
                {
                    // Get average time spent on the page
                    var average = _uadService.CalculateSessionInformation(sessions);
                    averageTimeSpent.Add(Convert.ToDouble(average[0]));
                }
                sessions.Clear();
            }
            //Sort Pages view time by shortest to longest
            _sortService.QuickSortDouble(averageTimeSpent, urlPages);
            // Transform list into UADObjects
            if (urlPages.Count >= 5)
            {
                for (int k = urlPages.Count - 1; k >= urlPages.Count - 5; k--)
                {
                    var sessionUADObject = new UADObject
                    {
                        Date     = months[monthIndex] + ' ' + year,
                        InfoType = urlPages[k],
                        Value    = averageTimeSpent[k].ToString()
                    };
                    uadObjects.Add(sessionUADObject);
                }
            }
            else
            {
                for (int k = urlPages.Count - 1; k >= 0; k--)
                {
                    var sessionUADObject = new UADObject
                    {
                        Date     = month + ' ' + year,
                        InfoType = urlPages[k],
                        Value    = averageTimeSpent[k].ToString()
                    };
                    uadObjects.Add(sessionUADObject);
                }
            }
            monthsUsed.Clear();

            return(uadObjects);
        }