Exemple #1
0
        public void ResetStackData(string errorStackId)
        {
            if (String.IsNullOrEmpty(errorStackId))
            {
                return;
            }

            ErrorStack stack = _errorStackRepository.GetById(errorStackId);

            if (stack == null)
            {
                return;
            }

            try {
                stack.TotalOccurrences = 0;
                stack.LastOccurrence   = DateTime.MinValue.ToUniversalTime();
                stack.FirstOccurrence  = DateTime.MinValue.ToUniversalTime();
                _errorStackRepository.Update(stack);

                _statsHelper.DecrementDayProjectStatsByStackId(stack.ProjectId, errorStackId);
                _statsHelper.DecrementMonthProjectStatsByStackId(stack.ProjectId, errorStackId);

                _errorRepository.RemoveAllByErrorStackId(errorStackId);
                _dayStackStats.RemoveAllByErrorStackId(errorStackId);
                _monthStackStats.RemoveAllByErrorStackId(errorStackId);
            } catch (Exception e) {
                Log.Error().Project(stack.ProjectId).Exception(e).Message("Error resetting stack data.").Report().Write();
                throw;
            }
        }
        public void CanResetStackStats()
        {
            _dataHelper.ResetProjectData(TestConstants.ProjectId);
            TimeSpan  timeOffset = _projectRepository.GetDefaultTimeOffset(TestConstants.ProjectId);
            DateTime  startDate  = DateTime.UtcNow.Add(timeOffset).Date.AddDays(-45);
            DateTime  endDate    = DateTime.UtcNow.Add(timeOffset).Date;
            const int count      = 100;

            List <Error> errors1 = ErrorData.GenerateErrors(count, organizationId: TestConstants.OrganizationId, startDate: startDate, endDate: endDate, projectId: TestConstants.ProjectId, timeZoneOffset: timeOffset).ToList();

            _errorPipeline.Run(errors1);

            long stackCount = _errorStackRepository.Where(es => es.ProjectId == TestConstants.ProjectId).Count();
            var  firstStack = _errorStackRepository.Where(es => es.ProjectId == TestConstants.ProjectId).OrderBy(es => es.FirstOccurrence).First();

            Console.WriteLine("Count: " + firstStack.TotalOccurrences);

            var info = _errorStatsHelper.GetProjectErrorStats(TestConstants.ProjectId, timeOffset, startDate, endDate);

            Assert.Equal(count, info.Total);
            Assert.InRange(info.UniqueTotal, 1, count);
            Assert.Equal(stackCount, info.NewTotal);
            Assert.Equal(info.EndDate.Subtract(info.StartDate).TotalDays + 1, info.Stats.Count);
            Assert.Equal(count, info.Stats.Sum(ds => ds.Total));
            Assert.Equal(stackCount, info.Stats.Sum(ds => ds.NewTotal));

            _errorStatsHelper.DecrementDayProjectStatsByStackId(TestConstants.ProjectId, firstStack.Id);
            _errorStatsHelper.DecrementMonthProjectStatsByStackId(TestConstants.ProjectId, firstStack.Id);

            info = _errorStatsHelper.GetProjectErrorStats(TestConstants.ProjectId, timeOffset, startDate, endDate);
            Assert.Equal(count - firstStack.TotalOccurrences, info.Total);
            Assert.InRange(info.UniqueTotal - 1, 1, count);
            Assert.Equal(stackCount - 1, info.NewTotal);
            Assert.Equal(info.EndDate.Subtract(info.StartDate).TotalDays + 1, info.Stats.Count);
            Assert.Equal(count - firstStack.TotalOccurrences, info.Stats.Sum(ds => ds.Total));
            Assert.Equal(stackCount - 1, info.Stats.Sum(ds => ds.NewTotal));
        }