Esempio n. 1
0
        public void WorkUnit_GetFrame_ReturnsNullIfRequestedIdDoesNotExist_Test()
        {
            // Arrange
            var workUnit = new WorkUnit();

            // Act & Assert
            Assert.IsNull(workUnit.GetFrame(0));
        }
Esempio n. 2
0
        public void WorkUnit_GetFrame_ReturnsObjectIfRequestedIdExists_Test()
        {
            // Arrange
            var workUnit = new WorkUnit();
            var frames   = new Dictionary <int, LogLineFrameData>().With(new LogLineFrameData {
                ID = 0
            });

            workUnit.Frames = frames;
            // Act & Assert
            Assert.IsNotNull(workUnit.GetFrame(0));
        }
Esempio n. 3
0
        /// <summary>
        /// Get the average duration over the specified number of most recent frames
        /// </summary>
        /// <param name="numberOfFrames">Number of most recent frames</param>
        private int GetDurationInSeconds(int numberOfFrames)
        {
            // the numberOfFrames must be 1 or greater
            // if CurrentFrame is null then no frames have been captured yet
            if (numberOfFrames < 1 || WorkUnit.CurrentFrame == null)
            {
                return(0);
            }

            // init return value
            int averageSeconds = 0;

            // Make sure we only add frame durations greater than a Zero TimeSpan
            // The first frame will always have a Zero TimeSpan for frame duration
            // we don't want to take this frame into account when calculating 'AllFrames'
            TimeSpan totalTime   = TimeSpan.Zero;
            int      countFrames = 0;

            int frameId = WorkUnit.CurrentFrame.ID;

            for (int i = 0; i < numberOfFrames; i++)
            {
                var frame = WorkUnit.GetFrame(frameId);
                if (frame != null && frame.Duration > TimeSpan.Zero)
                {
                    totalTime = totalTime.Add(frame.Duration);
                    countFrames++;
                }
                frameId--;
            }

            if (countFrames > 0)
            {
                averageSeconds = Convert.ToInt32(totalTime.TotalSeconds) / countFrames;
            }

            return(averageSeconds);
        }